/usr/include/stxxl/bits/common
NameSizeModeActions
addressable_queues.h60360644editdlrm
aligned_alloc.h53870644editdlrm
binary_buffer.h200630644editdlrm
cmdline.h234820644editdlrm
condition_variable.h21410644editdlrm
counting_ptr.h164040644editdlrm
error_handling.h77020644editdlrm
exceptions.h20000644editdlrm
exithandler.h14000644editdlrm
external_shared_ptr.h37600644editdlrm
is_sorted.h18180644editdlrm
log.h12650644editdlrm
mutex.h33320644editdlrm
new_alloc.h39010644editdlrm
onoff_switch.h21460644editdlrm
rand.h81910644editdlrm
seed.h8630644editdlrm
semaphore.h24490644editdlrm
settings.h9710644editdlrm
simple_vector.h46390644editdlrm
state.h16870644editdlrm
timer.h46620644editdlrm
tmeta.h29880644editdlrm
tuple.h195530644editdlrm
types.h19230644editdlrm
uint_types.h95720644editdlrm
utils.h83800644editdlrm
Edit: /usr/include/stxxl/bits/common/mutex.h (3332B)
/*************************************************************************** * include/stxxl/bits/common/mutex.h * * Part of the STXXL. See http://stxxl.sourceforge.net * * Copyright (C) 2002 Roman Dementiev * Copyright (C) 2008 Andreas Beckmann * Copyright (C) 2013 Timo Bingmann * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) **************************************************************************/ #ifndef STXXL_COMMON_MUTEX_HEADER #define STXXL_COMMON_MUTEX_HEADER #include #include #if STXXL_STD_THREADS #include #elif STXXL_BOOST_THREADS #include #elif STXXL_POSIX_THREADS #include #include #include #else #error "Thread implementation not detected." #endif STXXL_BEGIN_NAMESPACE #if STXXL_STD_THREADS typedef std::mutex mutex; #elif STXXL_BOOST_THREADS typedef boost::mutex mutex; #elif STXXL_POSIX_THREADS class mutex : private noncopyable { //! mutex handle pthread_mutex_t m_mutex; public: //! construct unlocked mutex mutex() { STXXL_CHECK_PTHREAD_CALL(pthread_mutex_init(&m_mutex, NULL)); } //! destroy mutex handle ~mutex() { // try simple delete first int res = pthread_mutex_destroy(&m_mutex); if (res == 0) return; // try to lock and unlock mutex res = pthread_mutex_trylock(&m_mutex); if (res == 0 || res == EBUSY) { STXXL_CHECK_PTHREAD_CALL(pthread_mutex_unlock(&m_mutex)); } else { STXXL_THROW_ERRNO2(resource_error, "pthread_mutex_trylock() failed", res); } STXXL_CHECK_PTHREAD_CALL(pthread_mutex_destroy(&m_mutex)); } //! lock mutex, may block void lock() { STXXL_CHECK_PTHREAD_CALL(pthread_mutex_lock(&m_mutex)); } //! unlock mutex void unlock() { STXXL_CHECK_PTHREAD_CALL(pthread_mutex_unlock(&m_mutex)); } //! return platform specific handle pthread_mutex_t & native_handle() { return m_mutex; } }; #endif #if STXXL_STD_THREADS typedef std::unique_lock scoped_mutex_lock; #elif STXXL_BOOST_THREADS typedef boost::mutex::scoped_lock scoped_mutex_lock; #else //! Aquire a lock that's valid until the end of scope. class scoped_mutex_lock { //! mutex reference mutex& m_mutex; //! marker if already unlocked by this thread (needs no synchronization) bool is_locked; public: //! lock mutex scoped_mutex_lock(mutex& m) : m_mutex(m), is_locked(true) { m_mutex.lock(); } //! unlock mutex hold when object goes out of scope. ~scoped_mutex_lock() { unlock(); } //! unlock mutex hold prematurely void unlock() { if (is_locked) { is_locked = false; m_mutex.unlock(); } } //! return platform specific handle pthread_mutex_t & native_handle() { return m_mutex.native_handle(); } }; #endif STXXL_END_NAMESPACE #endif // !STXXL_COMMON_MUTEX_HEADER