[libc-commits] [libc] [libc][Semaphore] Add public sem_t type and entry (PR #213489)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Sun Aug 2 14:42:58 PDT 2026


================
@@ -0,0 +1,102 @@
+//===-- Unittests for named 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/semaphore_macros.h"
+#include "hdr/types/sem_t.h"
+#include "src/semaphore/sem_close.h"
+#include "src/semaphore/sem_getvalue.h"
+#include "src/semaphore/sem_open.h"
+#include "src/semaphore/sem_post.h"
+#include "src/semaphore/sem_unlink.h"
+#include "src/semaphore/sem_wait.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+using LlvmLibcSemOpenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
----------------
kaladron wrote:

```
If a process makes multiple successful calls to sem_open() with the same value for name, there have been no intervening calls to sem_unlink() for name, and at least one open handle for this semaphore has not been closed with a sem_close() call, it is implementation-defined whether the same handle or a unique handle is returned for each such successful call.
```

If this implementation is choosing to use the same handle, i'm not seeing a test here for it.  We likely want to match glibc's behaviour here, though (whatever it is).  I believe it used to be required in older versions of POSIX.

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


More information about the libc-commits mailing list