Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A locking problem #2022

Closed
ryancaicse opened this issue Mar 24, 2022 · 2 comments
Closed

A locking problem #2022

ryancaicse opened this issue Mar 24, 2022 · 2 comments

Comments

@ryancaicse
Copy link

Hi, it seems the lock srv->lock is not released before Line 246. Although the condition may not very possible to reach, would it be better to release the lock before returning?

rtl_433/src/output_rtltcp.c

Lines 231 to 246 in 517b972

pthread_mutex_lock(&srv->lock);
if (srv->client_count <= 0) {
pthread_mutex_unlock(&srv->lock);
return; // no clients, do nothing
}
// find a free slot
int slot = 0;
for (; slot < DATA_SLOTS; ++slot) {
if (srv->data_inuse[slot] == 0) {
break;
}
}
if (slot >= DATA_SLOTS) {
fprintf(stderr, "%s: all data slots in use!\n", __func__);
return; // this should never happen

@zuckschwerdt
Copy link
Collaborator

Thanks for looking through this! Valid point. The code around the slots mechanism was changed quite a lot in the end and I missed that.
On the other hand it's really an invariant and we are doomed should 2 users (writer + reader) lock more than 2 slots ;)

That code has been replaced already with a different strategy (the global ring buffer on shared memory, mentioned in line 91), we'll hopefully have that in a few months.

@zuckschwerdt
Copy link
Collaborator

Closed by 7d7b7bf now.
Persistent valid buffers are guaranteed by the SDR backend, no need for own backing anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants