003 File Manager
Current Path:
/usr/src/contrib/llvm-project/libcxx/src
usr
/
src
/
contrib
/
llvm-project
/
libcxx
/
src
/
📁
..
📄
algorithm.cpp
(3.73 KB)
📄
any.cpp
(933 B)
📄
atomic.cpp
(7.67 KB)
📄
barrier.cpp
(3.77 KB)
📄
bind.cpp
(715 B)
📄
charconv.cpp
(4.51 KB)
📄
chrono.cpp
(4.94 KB)
📄
condition_variable.cpp
(2.73 KB)
📄
condition_variable_destructor.cpp
(1.26 KB)
📄
debug.cpp
(13.37 KB)
📄
exception.cpp
(1.25 KB)
📁
experimental
📁
filesystem
📄
functional.cpp
(656 B)
📄
future.cpp
(6.21 KB)
📄
hash.cpp
(13.04 KB)
📁
include
📄
ios.cpp
(12.62 KB)
📄
iostream.cpp
(5.66 KB)
📄
locale.cpp
(189.52 KB)
📄
memory.cpp
(6.15 KB)
📄
mutex.cpp
(5.77 KB)
📄
mutex_destructor.cpp
(1.44 KB)
📄
new.cpp
(5.98 KB)
📄
optional.cpp
(1.16 KB)
📄
random.cpp
(3.98 KB)
📄
random_shuffle.cpp
(1.26 KB)
📄
regex.cpp
(8.22 KB)
📄
shared_mutex.cpp
(2.86 KB)
📄
stdexcept.cpp
(592 B)
📄
string.cpp
(11.54 KB)
📄
strstream.cpp
(8.46 KB)
📁
support
📄
system_error.cpp
(6.88 KB)
📄
thread.cpp
(5.42 KB)
📄
typeinfo.cpp
(1.79 KB)
📄
utility.cpp
(497 B)
📄
valarray.cpp
(1.67 KB)
📄
variant.cpp
(517 B)
📄
vector.cpp
(529 B)
Editing: shared_mutex.cpp
//===---------------------- shared_mutex.cpp ------------------------------===// // // 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 "__config" #ifndef _LIBCPP_HAS_NO_THREADS #include "shared_mutex" #if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB) #pragma comment(lib, "pthread") #endif _LIBCPP_BEGIN_NAMESPACE_STD // Shared Mutex Base __shared_mutex_base::__shared_mutex_base() : __state_(0) { } // Exclusive ownership void __shared_mutex_base::lock() { unique_lock<mutex> lk(__mut_); while (__state_ & __write_entered_) __gate1_.wait(lk); __state_ |= __write_entered_; while (__state_ & __n_readers_) __gate2_.wait(lk); } bool __shared_mutex_base::try_lock() { unique_lock<mutex> lk(__mut_); if (__state_ == 0) { __state_ = __write_entered_; return true; } return false; } void __shared_mutex_base::unlock() { lock_guard<mutex> _(__mut_); __state_ = 0; __gate1_.notify_all(); } // Shared ownership void __shared_mutex_base::lock_shared() { unique_lock<mutex> lk(__mut_); while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_) __gate1_.wait(lk); unsigned num_readers = (__state_ & __n_readers_) + 1; __state_ &= ~__n_readers_; __state_ |= num_readers; } bool __shared_mutex_base::try_lock_shared() { unique_lock<mutex> lk(__mut_); unsigned num_readers = __state_ & __n_readers_; if (!(__state_ & __write_entered_) && num_readers != __n_readers_) { ++num_readers; __state_ &= ~__n_readers_; __state_ |= num_readers; return true; } return false; } void __shared_mutex_base::unlock_shared() { lock_guard<mutex> _(__mut_); unsigned num_readers = (__state_ & __n_readers_) - 1; __state_ &= ~__n_readers_; __state_ |= num_readers; if (__state_ & __write_entered_) { if (num_readers == 0) __gate2_.notify_one(); } else { if (num_readers == __n_readers_ - 1) __gate1_.notify_one(); } } // Shared Timed Mutex // These routines are here for ABI stability shared_timed_mutex::shared_timed_mutex() : __base() {} void shared_timed_mutex::lock() { return __base.lock(); } bool shared_timed_mutex::try_lock() { return __base.try_lock(); } void shared_timed_mutex::unlock() { return __base.unlock(); } void shared_timed_mutex::lock_shared() { return __base.lock_shared(); } bool shared_timed_mutex::try_lock_shared() { return __base.try_lock_shared(); } void shared_timed_mutex::unlock_shared() { return __base.unlock_shared(); } _LIBCPP_END_NAMESPACE_STD #endif // !_LIBCPP_HAS_NO_THREADS
Upload File
Create Folder