15 #ifndef STXXL_COMMON_MUTEX_HEADER
16 #define STXXL_COMMON_MUTEX_HEADER
21 #if STXXL_STD_THREADS && STXXL_WINDOWS && STXXL_MSVC >= 1700
27 #elif STXXL_BOOST_THREADS
28 #include <boost/thread/mutex.hpp>
29 #elif STXXL_POSIX_THREADS
35 #error "Thread implementation not detected."
42 typedef std::mutex mutex;
44 #elif STXXL_BOOST_THREADS
46 typedef boost::mutex mutex;
48 #elif STXXL_POSIX_THREADS
65 int res = pthread_mutex_destroy(&m_mutex);
69 res = pthread_mutex_trylock(&m_mutex);
71 if (res == 0 || res == EBUSY) {
97 #endif // STXXL_POSIX_THREADS
99 #if STXXL_STD_THREADS && STXXL_WINDOWS && STXXL_MSVC >= 1700
110 #if STXXL_STD_THREADS
115 #elif STXXL_BOOST_THREADS
134 : m_mutex(m), is_locked(true)
154 return m_mutex.native_handle();
162 #if STXXL_STD_THREADS && STXXL_WINDOWS && STXXL_MSVC >= 1700
167 #if STXXL_MSVC < 1800
170 lck.clear(std::memory_order_release);
179 while (lck.test_and_set(std::memory_order_acquire))
185 lck.clear(std::memory_order_release);
189 #if STXXL_MSVC >= 1800
190 std::atomic_flag lck = ATOMIC_FLAG_INIT;
191 spin_lock(
const spin_lock&) =
delete;
192 spin_lock& operator = (
const spin_lock&) =
delete;
194 std::atomic_flag lck;
195 spin_lock(
const spin_lock&);
196 spin_lock& operator = (
const spin_lock&);
203 #endif // !STXXL_COMMON_MUTEX_HEADER
scoped_mutex_lock(mutex &m)
lock mutex
#define STXXL_CHECK_PTHREAD_CALL(expr)
Checks pthread call, if return != 0, throws stxxl::resource_error with "Error in [function] : [pthrea...
void unlock()
unlock mutex hold prematurely
bool is_locked
marker if already unlocked by this thread (needs no synchronization)
#define STXXL_THROW_ERRNO2(exception_type, error_message, errno_value)
Throws exception_type with "Error in [function] : [error_message] : [errno_value message]".
void lock()
lock mutex, may block
~scoped_mutex_lock()
unlock mutex hold when object goes out of scope.
pthread_mutex_t & native_handle()
return platform specific handle
Aquire a lock that's valid until the end of scope.
#define STXXL_BEGIN_NAMESPACE
pthread_mutex_t m_mutex
mutex handle
mutex()
construct unlocked mutex
scoped_mutex_lock scoped_fast_mutex_lock
mutex & m_mutex
mutex reference
void unlock()
unlock mutex
pthread_mutex_t & native_handle()
return platform specific handle
#define STXXL_END_NAMESPACE
~mutex() noexcept(false)
destroy mutex handle