| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===-- Implementation for Rwlock's 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_rwlock_destroy.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_destroy, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| auto *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| RwLock::LockResult res = rw->check_for_destroy(); | ||
|
|
||
| // this is currently no-op, but we still call the destructor as a symmetry | ||
| // to its constructor call; | ||
| if (res == RwLock::LockResult::Success) | ||
| rw->~RwLock(); | ||
|
|
||
| return static_cast<int>(res); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's destroy function -------*-C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_DESTROY_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_DESTROY_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_DESTROY_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //===-- Linux implementation of the pthread_rwlock_init 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_rwlock_init.h" | ||
|
|
||
| #include "src/__support/CPP/new.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/libc_assert.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_init, | ||
| (pthread_rwlock_t * rwlock, | ||
| const pthread_rwlockattr_t *__restrict attr)) { | ||
| pthread_rwlockattr_t rwlockattr{ | ||
| /*pshared=*/PTHREAD_PROCESS_PRIVATE, | ||
| /*pref*/ PTHREAD_RWLOCK_PREFER_READER_NP, | ||
| }; | ||
| // POSIX does not specify this check, so we add an assertion to catch it. | ||
| LIBC_ASSERT(rwlock && "rwlock is null"); | ||
| if (attr) | ||
| rwlockattr = *attr; | ||
|
|
||
| // PTHREAD_RWLOCK_PREFER_WRITER_NP is not supported. | ||
| rwlock::Role preference; | ||
| switch (rwlockattr.pref) { | ||
| case PTHREAD_RWLOCK_PREFER_READER_NP: | ||
| preference = rwlock::Role::Reader; | ||
| break; | ||
| case PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP: | ||
| preference = rwlock::Role::Writer; | ||
| break; | ||
| default: | ||
| return EINVAL; | ||
| } | ||
| bool is_pshared; | ||
| switch (rwlockattr.pshared) { | ||
| case PTHREAD_PROCESS_PRIVATE: | ||
| is_pshared = false; | ||
| break; | ||
| case PTHREAD_PROCESS_SHARED: | ||
| is_pshared = true; | ||
| break; | ||
| default: | ||
| return EINVAL; | ||
| } | ||
|
|
||
| new (rwlock) RwLock(preference, is_pshared); | ||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for pthread_rwlock_init function ---*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_INIT_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_INIT_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_init(pthread_rwlock_t *rwlock, | ||
| const pthread_rwlockattr_t *__restrict attr); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_INIT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //===-- Implementation of the Rwlock's rdlock 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_rwlock_rdlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_rdlock, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| return static_cast<int>(rw->read_lock()); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's rdlock function -------*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_RDLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_RDLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_RDLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //===-- Implementation of the Rwlock's timedrdlock 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_rwlock_timedrdlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/libc_assert.h" | ||
| #include "src/__support/macros/optimization.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
| #include "src/__support/time/linux/abs_timeout.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_timedrdlock, | ||
| (pthread_rwlock_t * rwlock, | ||
| const struct timespec *abstime)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| LIBC_ASSERT(abstime && "timedrdlock called with a null timeout"); | ||
| auto timeout = | ||
| internal::AbsTimeout::from_timespec(*abstime, /*is_realtime=*/true); | ||
| if (LIBC_LIKELY(timeout.has_value())) | ||
| return static_cast<int>(rw->read_lock(timeout.value())); | ||
|
|
||
| switch (timeout.error()) { | ||
| case internal::AbsTimeout::Error::Invalid: | ||
| return EINVAL; | ||
| case internal::AbsTimeout::Error::BeforeEpoch: | ||
| return ETIMEDOUT; | ||
| // default: unreachable, all two cases are covered. | ||
| } | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for Rwlock's timedrdlock function --*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_TIMEDRDLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TIMEDRDLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict rwlock, | ||
| const struct timespec *__restrict abs_timeout); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TIMEDRDLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //===-- Implementation for Rwlock's timedwrlock 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_rwlock_timedwrlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/libc_assert.h" | ||
| #include "src/__support/macros/optimization.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
| #include "src/__support/time/linux/abs_timeout.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_timedwrlock, | ||
| (pthread_rwlock_t *__restrict rwlock, | ||
| const struct timespec *__restrict abstime)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| LIBC_ASSERT(abstime && "timedwrlock called with a null timeout"); | ||
| auto timeout = | ||
| internal::AbsTimeout::from_timespec(*abstime, /*is_realtime=*/true); | ||
| if (LIBC_LIKELY(timeout.has_value())) | ||
| return static_cast<int>(rw->write_lock(timeout.value())); | ||
|
|
||
| switch (timeout.error()) { | ||
| case internal::AbsTimeout::Error::Invalid: | ||
| return EINVAL; | ||
| case internal::AbsTimeout::Error::BeforeEpoch: | ||
| return ETIMEDOUT; | ||
| // default: unreachable, all two cases are covered. | ||
| } | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for Rwlock's timedwrlock function --*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_TIMEDWRLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TIMEDWRLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict rwlock, | ||
| const struct timespec *__restrict abs_timeout); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TIMEDWRLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //===-- Implementation of the Rwlock's tryrdlock 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_rwlock_tryrdlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_tryrdlock, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| return static_cast<int>(rw->try_read_lock()); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's tryrdlock function ----*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_TRYRDLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TRYRDLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TRYRDLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //===-- Implementation for Rwlock's trywrlock 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_rwlock_trywrlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_trywrlock, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| return static_cast<int>(rw->try_write_lock()); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's trywrlock function ----*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_TRYWRLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TRYWRLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_TRYWRLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===-- Implementation for Rwlock's unlock 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_rwlock_unlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_unlock, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| auto *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| return static_cast<int>(rw->unlock()); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's unlock function -------*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_UNLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_UNLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_UNLOCK_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //===-- Implementation for Rwlock's wrlock 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_rwlock_wrlock.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
| #include "src/__support/threads/linux/rwlock.h" | ||
|
|
||
| #include <errno.h> | ||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| static_assert( | ||
| sizeof(RwLock) == sizeof(pthread_rwlock_t) && | ||
| alignof(RwLock) == alignof(pthread_rwlock_t), | ||
| "The public pthread_rwlock_t type must be of the same size and alignment " | ||
| "as the internal rwlock type."); | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, pthread_rwlock_wrlock, (pthread_rwlock_t * rwlock)) { | ||
| if (!rwlock) | ||
| return EINVAL; | ||
| RwLock *rw = reinterpret_cast<RwLock *>(rwlock); | ||
| return static_cast<int>(rw->write_lock()); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation header for Rwlock's wrlock function -------*- C++-*-===// | ||
| // | ||
| // 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_PTHREAD_PTHREAD_RWLOCK_WRLOCK_H | ||
| #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_WRLOCK_H | ||
|
|
||
| #include <pthread.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCK_WRLOCK_H |