[libc-commits] [libc] [libc] add spin lock family functions (PR #100509)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Sat Jul 27 18:16:11 PDT 2024


================
@@ -0,0 +1,46 @@
+//===-- Implementation of pthread_spin_destroy function ------------------===//
+//
+// 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 "src/pthread/pthread_spin_destroy.h"
+#include "hdr/errno_macros.h"
+#include "src/__support/common.h"
+#include "src/__support/threads/spin_lock.h"
+namespace LIBC_NAMESPACE_DECL {
+
+static_assert(sizeof(pthread_spinlock_t::__lockword) == sizeof(SpinLock) &&
+                  alignof(decltype(pthread_spinlock_t::__lockword)) ==
+                      alignof(SpinLock),
+              "pthread_spinlock_t::__lockword and SpinLock must be of the same "
+              "size and alignment");
+
+LLVM_LIBC_FUNCTION(int, pthread_spin_destroy,
+                   ([[maybe_unused]] pthread_spinlock_t * lock)) {
+  auto *spin_lock = reinterpret_cast<SpinLock *>(&lock->__lockword);
----------------
SchrodingerZhu wrote:

ouch, I wrote sth silly. Will correcting it.

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


More information about the libc-commits mailing list