[libc-commits] [libc] [libc][semaphore] Add unnamed semaphore implementation (PR #190851)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Apr 8 13:26:44 PDT 2026


================
@@ -0,0 +1,67 @@
+//===-- Internal Semaphore types and helpers for POSIX semaphores ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SEMAPHORE_POSIX_SEMAPHORE_H
+#define LLVM_LIBC_SRC_SEMAPHORE_POSIX_SEMAPHORE_H
+
+#include "hdr/types/sem_t.h"
+#include "src/__support/CPP/atomic.h"
+#include "src/__support/common.h"
+#include "src/__support/threads/linux/futex_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+class Semaphore {
+  Futex value;
+  unsigned int canary;
+
+  // 0x53 = S, 0x45 = E, 0x4D = M, 0x31 = 1
+  static constexpr unsigned int SEM_CANARY = 0x53454D31U;
----------------
michaelrj-google wrote:

add a comment explaining what this value is used for and why this value was chosen.

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


More information about the libc-commits mailing list