[libc-commits] [libc] [libc] rework mutex (PR #92168)

via libc-commits libc-commits at lists.llvm.org
Tue May 14 13:46:23 PDT 2024


================
@@ -9,114 +9,81 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_MUTEX_H
 #define LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_MUTEX_H
 
+#include "hdr/types/pid_t.h"
+#include "src/__support/CPP/optional.h"
 #include "src/__support/threads/linux/futex_utils.h"
+#include "src/__support/threads/linux/raw_mutex.h"
 #include "src/__support/threads/mutex_common.h"
 
 namespace LIBC_NAMESPACE {
-struct Mutex {
-  unsigned char timed;
+
+// TODO: support shared/recursive/robust mutexes.
+class Mutex final : private internal::RawMutex {
+  // reserved timed, may be useful when combined with other flags.
+  [[maybe_unused]] unsigned char timed;
   unsigned char recursive;
   unsigned char robust;
+  unsigned char pshared;
 
-  void *owner;
+  // TLS address may not work across forked processes. Use thread id instead.
+  pid_t owner;
   unsigned long long lock_count;
 
-  Futex futex_word;
-
   enum class LockState : FutexWordType {
-    Free,
-    Locked,
-    Waiting,
+    Free = UNLOCKED,
+    Locked = LOCKED,
+    Waiting = CONTENTED,
   };
----------------
QuarticCat wrote:

This enum seems to be redundant now.

https://github.com/llvm/llvm-project/pull/92168


More information about the libc-commits mailing list