]> Kevux Git Server - fll/commitdiff
Update: Add thread mutex attribute defines, update tests, and add missing error handling.
authorKevin Day <Kevin@kevux.org>
Wed, 13 Aug 2025 00:20:31 +0000 (19:20 -0500)
committerKevin Day <Kevin@kevux.org>
Wed, 13 Aug 2025 00:20:31 +0000 (19:20 -0500)
Define `_di_f_thread_mutex_attribute_d_` such that the mutex attributes like `PTHREAD_MUTEX_NORMAL` have a mapped define.

The mutex lock and try lock are no longer missing the handling of `ENOTRECOVERABLE` and `EOWNERDEAD` errors.

build/disable/level_0/f_thread.h
build/stand_alone/byte_dump.config.h
build/stand_alone/example.config.h
build/stand_alone/fake.config.h
build/stand_alone/firewall.config.h
build/stand_alone/utf8.config.h
level_0/f_thread/c/thread.c
level_0/f_thread/c/thread.h
level_0/f_thread/c/thread/mutex_attribute.h
level_0/f_thread/tests/unit/c/test-thread-mutex_lock.c
level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.c

index 1e977fd1199c713467c2c92b67a1207b7e528ec7..2d23460ebd4b4719ff4a38e3043fe73c2e2429c9 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index b89882ca00c2ec53a721990f411512b0aa1dff7a..53265c60844e50ff334b5faca06089d1080d1a33 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index 4170ed5f97d427d5931bdbf2f951a03b567e61a5..e96aa9732f62772cb109fa199f8338c1a595e037 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index 3490d0ebd3605f75b62127c25531b2b723bee18b..548463387a1ac098072e0eea9bf2aaafa06ff5be 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index d3ff5154a40c2e868e2783d9a2da62c257ef7de3..2e3c78b76a73435b64162fd1e772bac569025039 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index f360591b15231759948a8118e0f58852d27c3aa9..421882f5e33211d4b529e3f86c3b9b69df02b78b 100644 (file)
 #define _di_f_thread_mutex_attribute_protocol_set_
 #define _di_f_thread_mutex_attribute_shared_get_
 #define _di_f_thread_mutex_attribute_shared_set_
+#define _di_f_thread_mutex_attribute_d_
 #define _di_f_thread_mutex_attribute_t_
 #define _di_f_thread_mutex_attribute_type_get_
 #define _di_f_thread_mutex_attribute_type_set_
index 4f6bde190b7151dbbdadbe77ac3684aa495fe4f8..aeed44bab48b2a87361ac8f695b6f42f7fdc59ac 100644 (file)
@@ -1590,6 +1590,8 @@ extern "C" {
       if (error == EAGAIN) return F_status_set_error(F_resource_not);
       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_dead);
 
       return F_status_set_error(F_failure);
     }
@@ -1634,6 +1636,8 @@ extern "C" {
       if (error == EAGAIN) return F_status_set_error(F_resource_not);
       if (error == EBUSY) return F_busy;
       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);
 
       return F_status_set_error(F_failure);
     }
index a3b4a01e7d806161b0cb6979d638f49ca7caa121..334c7cfe490d36b461f2cbc574c23db7d842420f 100644 (file)
@@ -2215,8 +2215,10 @@ extern "C" {
  * @return
  *   F_okay on success.
  *
+ *   F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead).
  *   F_deadlock (with error bit) if operation would cause a deadlock.
  *   F_parameter (with error bit) if a parameter is invalid.
+ *   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_failure (with error bit) on any other error.
@@ -2247,12 +2249,12 @@ extern "C" {
  *   F_okay on success.
  *   F_time if the timeout was reached before obtaining the lock.
  *
+ *   F_dead (with error bit) if the owning thread terminated while holding the mutex lock (thread is dead).
  *   F_deadlock (with error bit) if operation would cause a deadlock.
  *   F_parameter (with error bit) if a parameter is invalid.
  *   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_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.
  *
@@ -2278,7 +2280,9 @@ extern "C" {
  *   F_okay on success.
  *   F_busy on success, but the mutex is already locked.
  *
+ *   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_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_failure (with error bit) on any other error.
index 7beec5731e36d0d70ca00a0787b374979745f62a..dc6176dc9242d344a3c4891daf43744e35ccf11b 100644 (file)
@@ -17,6 +17,20 @@ extern "C" {
 #endif
 
 /**
+ * Mutex attribute defines.
+ *
+ * f_thread_mutex_attribute_*_d:
+ *   - error_check: Handle deadlock and ownership detection and return on error.
+ *   - normal:      The normal mutex type (also the default type and is the POSIX standard compliant version of PTHREAD_MUTEX_DEFAULT).
+ *   - recursive:   Recursive lock (uses a count on locks, mutexs become unlocked when count is 0).
+ */
+#ifndef _di_f_thread_mutex_attribute_d_
+  #define f_thread_mutex_attribute_error_check_d PTHREAD_MUTEX_ERRORCHECK
+  #define f_thread_mutex_attribute_normal_d      PTHREAD_MUTEX_RECURSIVE
+  #define f_thread_mutex_attribute_recursive_d   PTHREAD_MUTEX_NORMAL
+#endif // _di_f_thread_mutex_attribute_d_
+
+/**
  * A typedef representing pthread_mutex_attribute_t.
  */
 #ifndef _di_f_thread_mutex_attribute_t_
index aacd97cf74dd9c2e5397833debe211dfb221ecb1..dbdf185ccffda20c2cbd0fb7eeaeff2bee335735 100644 (file)
@@ -13,6 +13,8 @@ void test__f_thread_mutex_lock__fails(void **state) {
     EAGAIN,
     EDEADLK,
     EINVAL,
+    ENOTRECOVERABLE,
+    EOWNERDEAD,
     mock_errno_generic,
   };
 
@@ -20,10 +22,12 @@ void test__f_thread_mutex_lock__fails(void **state) {
     F_resource_not,
     F_deadlock,
     F_parameter,
+    F_recover_not,
+    F_dead,
     F_failure,
   };
 
-  for (uint8_t i = 0; i < 4; ++i) {
+  for (uint8_t i = 0; i < 6; ++i) {
 
     will_return(__wrap_pthread_mutex_lock, true);
     will_return(__wrap_pthread_mutex_lock, errnos[i]);
index a8479b59295f2069bf373caee03dafbae1efe8a7..48f3738e4328631050e9fe723b597c0279623809 100644 (file)
@@ -16,6 +16,8 @@ void test__f_thread_mutex_lock_try__fails(void **state) {
     EAGAIN,
     EBUSY,
     EINVAL,
+    ENOTRECOVERABLE,
+    EOWNERDEAD,
     mock_errno_generic,
   };
 
@@ -23,10 +25,12 @@ void test__f_thread_mutex_lock_try__fails(void **state) {
     F_status_set_error(F_resource_not),
     F_busy,
     F_status_set_error(F_parameter),
+    F_status_set_error(F_recover_not),
+    F_status_set_error(F_dead),
     F_status_set_error(F_failure),
   };
 
-  for (uint8_t i = 0; i < 4; ++i) {
+  for (uint8_t i = 0; i < 6; ++i) {
 
     will_return(__wrap_pthread_mutex_trylock, true);
     will_return(__wrap_pthread_mutex_trylock, errnos[i]);