From 3fa1aa7896bd2ad27745291063254050ef61ca03 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 10 Apr 2021 10:32:15 -0500 Subject: [PATCH] Update: handle POSIX compatibility automatically in f_thread_cancel_state_set(). The POSIX standard does not explicitly define that this parameter can be NULL. To prevent any possible problems, allow NULL but when NULL is received, use a temporary variable in its place. --- level_0/f_thread/c/thread.c | 12 +++++++++++- level_0/f_thread/c/thread.h | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index d0c410c..3b553cc 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -882,7 +882,17 @@ extern "C" { #ifndef _di_f_thread_cancel_state_set_ f_status_t f_thread_cancel_state_set(const int state, int *previous) { - const int error = pthread_setcancelstate(state, previous); + int error = 0; + + // POSIX doesn't allow this to be NULL, so make POSIX happy. + if (previous == 0) { + int ignore = 0; + + error = pthread_setcancelstate(state, &ignore); + } + else { + error = pthread_setcancelstate(state, previous); + } if (error) { if (error == EINVAL) return F_status_set_error(F_parameter); diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 22ba1f6..65ba7ba 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -1183,7 +1183,6 @@ extern "C" { * @param previous * (optional) The previously assigned cancellation state. * Set to NULL to not use. - * (Note: Linux allows this to be optional/NULL but POSIX does not explicitly defined this and there may be portability issues.) * * @return * F_none on success. -- 1.8.3.1