-
Notifications
You must be signed in to change notification settings - Fork 185
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
CFE-4401: Adjusted isreadable() to work without pthread_cancel when not available #5590
base: master
Are you sure you want to change the base?
Changes from 1 commit
cb70ddb
bb794bf
c3504d3
dd7fe67
0078633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8513,10 +8513,27 @@ struct IsReadableThreadData | |
FnCallResult result; | ||
}; | ||
|
||
#ifndef HAVE_PTHREAD_CANCEL | ||
#define PTHREAD_CANCELED ((void *)-1) | ||
static void ThreadSignalHandler(int signum) | ||
{ | ||
pthread_exit(PTHREAD_CANCELED); | ||
} | ||
#endif | ||
|
||
static void *IsReadableThreadRoutine(void *data) | ||
{ | ||
assert(data != NULL); | ||
|
||
#ifndef HAVE_PTHREAD_CANCEL | ||
struct sigaction actions; | ||
memset(&actions, 0, sizeof(actions)); | ||
sigemptyset(&actions.sa_mask); | ||
actions.sa_flags = 0; | ||
actions.sa_handler = ThreadSignalHandler; | ||
sigaction(SIGUSR2, &actions, NULL); | ||
#endif | ||
|
||
struct IsReadableThreadData *const thread_data = data; | ||
|
||
// Give main thread time to call pthread_cond_timedwait(3) | ||
|
@@ -8671,7 +8688,7 @@ static FnCallResult FnCallIsReadable(ARG_UNUSED EvalContext *const ctx, | |
#ifdef HAVE_PTHREAD_CANCEL | ||
ret = pthread_cancel(thread_data.thread); | ||
#else | ||
ret = pthread_kill(thread_data.thread, 0); | ||
ret = pthread_kill(thread_data.thread, SIGUSR2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @larsewi you had mentioned in my previous PR comment
And so here I am using the downstream patch which sends a kill signal and adds a signal handler to which then calls
from https://www.man7.org/linux/man-pages/man3/pthread_cancel.3.html |
||
#endif | ||
if (ret != 0) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer
SIGHUP
or some other signal that semantically matches the case? In fact, I think we should block many common signals in the new thread, we don't want handlers forSIGINT
etc. to be handled in it. So I'd extend this to something like what we do in cf-reactor and used one of the other signals here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I agree with SIGHUP/etc.
The reason for splitting commits was to acknowledge and make clear the use of another persons contribution.
I do agree that it makes more sense to have commits which are sufficient and complete on their own but also recognize that sometimes we make "mistakes" in a commit and then have to come back and fix them, sort of like in this case here.