From: Kevin Day Date: Tue, 28 Jun 2022 03:43:37 +0000 (-0500) Subject: Bugfix: Problems exposed by f_thread unit tests. X-Git-Tag: 0.5.10~12 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ff1377fc4cf187eb0d28046f155098c7c28311d1;p=fll Bugfix: Problems exposed by f_thread unit tests. --- diff --git a/level_0/f_thread/c/private-thread.c b/level_0/f_thread/c/private-thread.c index 410075a..362166e 100644 --- a/level_0/f_thread/c/private-thread.c +++ b/level_0/f_thread/c/private-thread.c @@ -69,9 +69,11 @@ extern "C" { #if !defined(_di_f_thread_barriers_adjust_) || !defined(_di_f_thread_barriers_decimate_by_) || !defined(_di_f_thread_barriers_decrease_) || !defined(_di_f_thread_barriers_decrease_by_) || !defined(_di_f_thread_barriers_increase_) || !defined(_di_f_thread_barriers_increase_by_) || !defined(_di_f_thread_barriers_resize_) f_status_t private_f_thread_barrier_delete(f_thread_barrier_t *barrier) { - if (pthread_barrier_destroy(barrier)) { - if (errno == EBUSY) return F_status_set_error(F_busy); - if (errno == EINVAL) return F_status_set_error(F_parameter); + const int error = pthread_barrier_destroy(barrier); + + if (error) { + if (error == EBUSY) return F_status_set_error(F_busy); + if (error == EINVAL) return F_status_set_error(F_parameter); return F_status_set_error(F_failure); } diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index 03bade9..69ee94c 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -437,6 +437,7 @@ extern "C" { #ifndef _di_f_thread_attribute_stack_get_ f_status_t f_thread_attribute_stack_get(const f_thread_attribute_t attribute, size_t * const stack_size, void **stack) { #ifndef _di_level_0_parameter_checking_ + if (!stack_size) return F_status_set_error(F_parameter); if (!stack) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -456,6 +457,7 @@ extern "C" { #ifndef _di_f_thread_attribute_stack_set_ f_status_t f_thread_attribute_stack_set(const size_t stack_size, void * const stack, f_thread_attribute_t * const attribute) { #ifndef _di_level_0_parameter_checking_ + if (!stack) return F_status_set_error(F_parameter); if (!attribute) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -481,6 +483,8 @@ extern "C" { const int error = pthread_attr_getstacksize(&attribute, stack_size); if (error) { + if (error == EINVAL) return F_status_set_error(F_parameter); + return F_status_set_error(F_failure); } @@ -508,6 +512,9 @@ extern "C" { #ifndef _di_f_thread_barrier_attribute_create_ f_status_t f_thread_barrier_attribute_create(f_thread_barrier_attribute_t * const attribute) { + #ifndef _di_level_0_parameter_checking_ + if (!attribute) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ const int error = pthread_barrierattr_init(attribute); @@ -569,7 +576,10 @@ extern "C" { #endif // _di_f_thread_barrier_attribute_shared_set_ #ifndef _di_f_thread_barrier_create_ - f_status_t f_thread_barrier_create(const unsigned int count, f_thread_barrier_attribute_t * const attribute, f_thread_barrier_t * const barrier) { + f_status_t f_thread_barrier_create(const unsigned int count, f_thread_barrier_attribute_t * const attribute, f_thread_barrier_t *barrier) { + #ifndef _di_level_0_parameter_checking_ + if (!barrier) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ const int error = pthread_barrier_init(barrier, attribute, count); diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 260c011..526e493 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -721,9 +721,13 @@ extern "C" { /** * Create (initialize) a thread barrier structure. * + * @param count + * The number of threads that must call the barrier wait function before any can successfully return. + * @param attribute + * (optional) The default attributes to initialize the barrier to. + * Set to NULL to not use (in which case the default barrier attributes are used). * @param barrier - * (optional) The barrier to set. - * Set to NULL to not use (in which case the default barrier is used). + * The barrier to set. * * @return * F_none on success. @@ -738,7 +742,7 @@ extern "C" { * @see pthread_barrier_init() */ #ifndef _di_f_thread_barrier_create_ - extern f_status_t f_thread_barrier_create(const unsigned int count, f_thread_barrier_attribute_t * const attribute, f_thread_barrier_t * const barrier); + extern f_status_t f_thread_barrier_create(const unsigned int count, f_thread_barrier_attribute_t * const attribute, f_thread_barrier_t *barrier); #endif // _di_f_thread_barrier_create_ /**