From 96540858a5dd0fa974ea67ead14ac0263b5a2c89 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 10 Apr 2021 23:57:05 -0500 Subject: [PATCH] Update: Finish implementing the thread condition functions. It looks like the f_thread_condition_wait() f_thread_condition_wait_timed() functions were not fully written. Add missing handlers. The f_thread_condition_wait_timed() was even missing the return case of F_time! Update the comments as the "time" value is relative to the absolute system clock time. Add F_dead, F_live, and related. --- level_0/f_status/c/status.h | 4 ++++ level_0/f_thread/c/thread.c | 9 +++++++-- level_0/f_thread/c/thread.h | 13 +++++++++---- level_1/fl_status/c/status.c | 12 ++++++++++++ level_1/fl_status/c/status.h | 8 ++++++++ level_2/fll_status/c/status.c | 20 ++++++++++++++++++++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/level_0/f_status/c/status.h b/level_0/f_status/c/status.h index f1e47a8..a3e2745 100644 --- a/level_0/f_status/c/status.h +++ b/level_0/f_status/c/status.h @@ -169,6 +169,8 @@ extern "C" { F_control_group_not, F_critical, F_critical_not, + F_dead, + F_dead_not, F_deadlock, F_deadlock_not, F_descriptor, @@ -218,6 +220,8 @@ extern "C" { F_limit_not, F_link, F_link_not, + F_live, + F_live_not, F_lock, F_lock_not, F_loop, diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index 3b553cc..be58bd8 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -1183,6 +1183,8 @@ extern "C" { if (error) { if (error == EINVAL) return F_status_set_error(F_parameter); + if (error == ENOTRECOVERABLE) return F_status_set_error(F_recover_not); + if (error == EOWNERDEAD) return F_status_set_error(F_dead); if (error == EPERM) return F_status_set_error(F_prohibited); return F_status_set_error(F_failure); @@ -1203,7 +1205,10 @@ extern "C" { if (error) { if (error == EINVAL) return F_status_set_error(F_parameter); + if (error == ENOTRECOVERABLE) return F_status_set_error(F_recover_not); + if (error == EOWNERDEAD) return F_status_set_error(F_dead); if (error == EPERM) return F_status_set_error(F_prohibited); + if (error == ETIMEDOUT) return F_time; return F_status_set_error(F_failure); } @@ -2304,7 +2309,7 @@ extern "C" { if (error == EDEADLK) return F_status_set_error(F_deadlock); if (error == EINVAL) return F_status_set_error(F_parameter); if (error == ENOTRECOVERABLE) return F_status_set_error(F_recover_not); - if (error == EOWNERDEAD) return F_status_set_error(F_thread_not); + if (error == EOWNERDEAD) return F_status_set_error(F_dead); if (error == ETIMEDOUT) return F_time; return F_status_set_error(F_failure); @@ -2544,7 +2549,7 @@ extern "C" { if (error == EDEADLK) return F_status_set_error(F_deadlock); if (error == EINVAL) return F_status_set_error(F_parameter); if (error == ENOTRECOVERABLE) return F_status_set_error(F_recover_not); - if (error == EOWNERDEAD) return F_status_set_error(F_thread_not); + if (error == EOWNERDEAD) return F_status_set_error(F_dead); if (error == EPERM) return F_status_set_error(F_prohibited); return F_status_set_error(F_failure); diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 65ba7ba..65003e6 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -1583,7 +1583,10 @@ extern "C" { * @return * F_none on success. * + * F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). * F_parameter (with error bit) if a parameter is invalid. + * F_prohibited (with error bit) if not allowed to perform the operation (possibly because mutex is not owned by current thread). + * F_recover_not (with error bit) if the state protected by the mutex is not recoverable. * * F_failure (with error bit) on any other error. * @@ -1601,7 +1604,7 @@ extern "C" { * * @param wait * The amount of time to wait for. - * The wait time is relative to the clock, so consider calling clock_gettime() and then adding the amount of wait time. + * The wait time is relative to the clock, so consider calling clock_gettime() or gettimeofday() and then adding the amount of wait time. * @param condition * The condition to wait on. * @param mutex @@ -1611,8 +1614,10 @@ extern "C" { * F_none on success. * F_time on success, and wait timeout was reached before condition was triggered. * + * F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). * F_parameter (with error bit) if a parameter is invalid. * F_prohibited (with error bit) if not allowed to perform the operation (possibly because mutex is not owned by current thread). + * F_recover_not (with error bit) if the state protected by the mutex is not recoverable. * * F_failure (with error bit) on any other error. * @@ -1887,7 +1892,7 @@ extern "C" { * The ID of the thread to wait for. * @param wait * The amount of time to wait for. - * The wait time is relative to the clock, so consider calling clock_gettime() and then adding the amount of wait time. + * The wait time is relative to the clock, so consider calling clock_gettime() or gettimeofday() and then adding the amount of wait time. * @param result * (optional) The data returned by the terminated thread (usually the exist status). * If the terminated thread is cancelled, then this holds PTHREAD_CANCELED. @@ -3085,7 +3090,7 @@ extern "C" { * F_prohibited (with error bit) if not allowed to perform the operation. * F_recover_not (with error bit) if the state protected by the mutex is not recoverable. * F_resource_not (with error bit) if max mutex locks is reached. - * F_thread_not (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). + * F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). * * F_failure (with error bit) on any other error. * @@ -3161,7 +3166,7 @@ extern "C" { * F_prohibited (with error bit) if not allowed to perform the operation. * F_recover_not (with error bit) if the state protected by the mutex is not recoverable (for a "robust" mutex). * F_resource_not (with error bit) if max mutex locks is reached. - * F_thread_not (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). + * F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead). * * F_failure (with error bit) on any other error. * diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index 6810fea..6dfeb6f 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -290,6 +290,12 @@ extern "C" { case F_critical_not: *string = FL_status_string_critical_not; break; + case F_dead: + *string = FL_status_string_dead; + break; + case F_dead_not: + *string = FL_status_string_dead_not; + break; case F_deadlock: *string = FL_status_string_deadlock; break; @@ -431,6 +437,12 @@ extern "C" { case F_link_not: *string = FL_status_string_link_not; break; + case F_live: + *string = FL_status_string_live; + break; + case F_live_not: + *string = FL_status_string_live_not; + break; case F_lock: *string = FL_status_string_lock; break; diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index a4ace12..4f2de20 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -189,6 +189,8 @@ extern "C" { #define FL_status_string_control_group_not "F_control_group_not" #define FL_status_string_critical "F_critical" #define FL_status_string_critical_not "F_critical_not" + #define FL_status_string_dead "F_dead" + #define FL_status_string_dead_not "F_dead_not" #define FL_status_string_deadlock "F_deadlock" #define FL_status_string_deadlock_not "F_deadlock_not" #define FL_status_string_descriptor "F_descriptor" @@ -238,6 +240,8 @@ extern "C" { #define FL_status_string_limit_not "F_limit_not" #define FL_status_string_link "F_link" #define FL_status_string_link_not "F_link_not" + #define FL_status_string_live "F_live" + #define FL_status_string_live_not "F_live_not" #define FL_status_string_lock "F_lock" #define FL_status_string_lock_not "F_lock_not" #define FL_status_string_loop "F_loop" @@ -354,6 +358,8 @@ extern "C" { #define FL_status_string_control_group_not_length 19 #define FL_status_string_critical_length 10 #define FL_status_string_critical_not_length 14 + #define FL_status_string_dead_length 6 + #define FL_status_string_dead_not_length 10 #define FL_status_string_deadlock_length 10 #define FL_status_string_deadlock_not_length 14 #define FL_status_string_descriptor_length 12 @@ -403,6 +409,8 @@ extern "C" { #define FL_status_string_limit_not_length 11 #define FL_status_string_link_length 6 #define FL_status_string_link_not_length 10 + #define FL_status_string_live_length 6 + #define FL_status_string_live_not_length 10 #define FL_status_string_lock_length 6 #define FL_status_string_lock_not_length 10 #define FL_status_string_loop_length 6 diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index 2b9c0c2..6d9fd8d 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -486,6 +486,16 @@ extern "C" { return F_none; } + if (fl_string_compare(string, FL_status_string_dead, length, FL_status_string_dead_length) == F_equal_to) { + *code = F_dead; + return F_none; + } + + if (fl_string_compare(string, FL_status_string_dead_not, length, FL_status_string_dead_not_length) == F_equal_to) { + *code = F_dead_not; + return F_none; + } + if (fl_string_compare(string, FL_status_string_deadlock, length, FL_status_string_deadlock_length) == F_equal_to) { *code = F_deadlock; return F_none; @@ -731,6 +741,16 @@ extern "C" { return F_none; } + if (fl_string_compare(string, FL_status_string_live, length, FL_status_string_live_length) == F_equal_to) { + *code = F_live; + return F_none; + } + + if (fl_string_compare(string, FL_status_string_live_not, length, FL_status_string_live_not_length) == F_equal_to) { + *code = F_live_not; + return F_none; + } + if (fl_string_compare(string, FL_status_string_lock, length, FL_status_string_lock_length) == F_equal_to) { *code = F_lock; return F_none; -- 1.8.3.1