noexcept and constexpr applied to <mutex>.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
46623a09ee
commit
499c61f999
@ -39,9 +39,9 @@ class _LIBCPP_VISIBLE mutex
|
|||||||
public:
|
public:
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
constexpr mutex() : __m_ PTHREAD_MUTEX_INITIALIZER {}
|
constexpr mutex() _NOEXCEPT : __m_ PTHREAD_MUTEX_INITIALIZER {}
|
||||||
#else
|
#else
|
||||||
mutex() {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
|
mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
|
||||||
#endif
|
#endif
|
||||||
~mutex();
|
~mutex();
|
||||||
|
|
||||||
@ -51,8 +51,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() _NOEXCEPT;
|
||||||
void unlock();
|
void unlock() _NOEXCEPT;
|
||||||
|
|
||||||
typedef pthread_mutex_t* native_handle_type;
|
typedef pthread_mutex_t* native_handle_type;
|
||||||
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
|
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
|
||||||
@ -62,17 +62,19 @@ struct _LIBCPP_VISIBLE defer_lock_t {};
|
|||||||
struct _LIBCPP_VISIBLE try_to_lock_t {};
|
struct _LIBCPP_VISIBLE try_to_lock_t {};
|
||||||
struct _LIBCPP_VISIBLE adopt_lock_t {};
|
struct _LIBCPP_VISIBLE adopt_lock_t {};
|
||||||
|
|
||||||
//constexpr
|
#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MUTEX)
|
||||||
extern const
|
|
||||||
defer_lock_t defer_lock;
|
|
||||||
|
|
||||||
//constexpr
|
extern const defer_lock_t defer_lock;
|
||||||
extern const
|
extern const try_to_lock_t try_to_lock;
|
||||||
try_to_lock_t try_to_lock;
|
extern const adopt_lock_t adopt_lock;
|
||||||
|
|
||||||
//constexpr
|
#else
|
||||||
extern const
|
|
||||||
adopt_lock_t adopt_lock;
|
constexpr defer_lock_t defer_lock = defer_lock_t();
|
||||||
|
constexpr try_to_lock_t try_to_lock = try_to_lock_t();
|
||||||
|
constexpr adopt_lock_t adopt_lock = adopt_lock_t();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class _Mutex>
|
template <class _Mutex>
|
||||||
class _LIBCPP_VISIBLE lock_guard
|
class _LIBCPP_VISIBLE lock_guard
|
||||||
@ -110,12 +112,12 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
unique_lock() : __m_(nullptr), __owns_(false) {}
|
unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
explicit unique_lock(mutex_type& __m)
|
explicit unique_lock(mutex_type& __m)
|
||||||
: __m_(&__m), __owns_(true) {__m_->lock();}
|
: __m_(&__m), __owns_(true) {__m_->lock();}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
unique_lock(mutex_type& __m, defer_lock_t)
|
unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
|
||||||
: __m_(&__m), __owns_(false) {}
|
: __m_(&__m), __owns_(false) {}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
unique_lock(mutex_type& __m, try_to_lock_t)
|
unique_lock(mutex_type& __m, try_to_lock_t)
|
||||||
@ -145,11 +147,11 @@ private:
|
|||||||
public:
|
public:
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
unique_lock(unique_lock&& __u)
|
unique_lock(unique_lock&& __u) _NOEXCEPT
|
||||||
: __m_(__u.__m_), __owns_(__u.__owns_)
|
: __m_(__u.__m_), __owns_(__u.__owns_)
|
||||||
{__u.__m_ = nullptr; __u.__owns_ = false;}
|
{__u.__m_ = nullptr; __u.__owns_ = false;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
unique_lock& operator=(unique_lock&& __u)
|
unique_lock& operator=(unique_lock&& __u) _NOEXCEPT
|
||||||
{
|
{
|
||||||
if (__owns_)
|
if (__owns_)
|
||||||
__m_->unlock();
|
__m_->unlock();
|
||||||
@ -194,13 +196,13 @@ public:
|
|||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
void swap(unique_lock& __u)
|
void swap(unique_lock& __u) _NOEXCEPT
|
||||||
{
|
{
|
||||||
_VSTD::swap(__m_, __u.__m_);
|
_VSTD::swap(__m_, __u.__m_);
|
||||||
_VSTD::swap(__owns_, __u.__owns_);
|
_VSTD::swap(__owns_, __u.__owns_);
|
||||||
}
|
}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
mutex_type* release()
|
mutex_type* release() _NOEXCEPT
|
||||||
{
|
{
|
||||||
mutex_type* __m = __m_;
|
mutex_type* __m = __m_;
|
||||||
__m_ = nullptr;
|
__m_ = nullptr;
|
||||||
@ -209,12 +211,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
bool owns_lock() const {return __owns_;}
|
bool owns_lock() const _NOEXCEPT {return __owns_;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
_LIBCPP_EXPLICIT
|
_LIBCPP_EXPLICIT
|
||||||
operator bool () const {return __owns_;}
|
operator bool () const _NOEXCEPT {return __owns_;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
mutex_type* mutex() const {return __m_;}
|
mutex_type* mutex() const _NOEXCEPT {return __m_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class _Mutex>
|
template <class _Mutex>
|
||||||
@ -280,7 +282,8 @@ unique_lock<_Mutex>::unlock()
|
|||||||
template <class _Mutex>
|
template <class _Mutex>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
void
|
void
|
||||||
swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) {__x.swap(__y);}
|
swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT
|
||||||
|
{__x.swap(__y);}
|
||||||
|
|
||||||
struct _LIBCPP_VISIBLE cv_status
|
struct _LIBCPP_VISIBLE cv_status
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ namespace std
|
|||||||
class mutex
|
class mutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
mutex();
|
constexpr mutex() noexcept;
|
||||||
~mutex();
|
~mutex();
|
||||||
|
|
||||||
mutex(const mutex&) = delete;
|
mutex(const mutex&) = delete;
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
recursive_mutex& operator=(const recursive_mutex&) = delete;
|
recursive_mutex& operator=(const recursive_mutex&) = delete;
|
||||||
|
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() noexcept;
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
typedef pthread_mutex_t* native_handle_type;
|
typedef pthread_mutex_t* native_handle_type;
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
|
recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
|
||||||
|
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() noexcept;
|
||||||
template <class Rep, class Period>
|
template <class Rep, class Period>
|
||||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||||
template <class Clock, class Duration>
|
template <class Clock, class Duration>
|
||||||
@ -114,9 +114,9 @@ class unique_lock
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Mutex mutex_type;
|
typedef Mutex mutex_type;
|
||||||
unique_lock();
|
unique_lock() noexcept;
|
||||||
explicit unique_lock(mutex_type& m);
|
explicit unique_lock(mutex_type& m);
|
||||||
unique_lock(mutex_type& m, defer_lock_t);
|
unique_lock(mutex_type& m, defer_lock_t) noexcept;
|
||||||
unique_lock(mutex_type& m, try_to_lock_t);
|
unique_lock(mutex_type& m, try_to_lock_t);
|
||||||
unique_lock(mutex_type& m, adopt_lock_t);
|
unique_lock(mutex_type& m, adopt_lock_t);
|
||||||
template <class Clock, class Duration>
|
template <class Clock, class Duration>
|
||||||
@ -128,8 +128,8 @@ public:
|
|||||||
unique_lock(unique_lock const&) = delete;
|
unique_lock(unique_lock const&) = delete;
|
||||||
unique_lock& operator=(unique_lock const&) = delete;
|
unique_lock& operator=(unique_lock const&) = delete;
|
||||||
|
|
||||||
unique_lock(unique_lock&& u);
|
unique_lock(unique_lock&& u) noexcept;
|
||||||
unique_lock& operator=(unique_lock&& u);
|
unique_lock& operator=(unique_lock&& u) noexcept;
|
||||||
|
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock();
|
||||||
@ -141,16 +141,16 @@ public:
|
|||||||
|
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
void swap(unique_lock& u);
|
void swap(unique_lock& u) noexcept;
|
||||||
mutex_type* release();
|
mutex_type* release() noexcept;
|
||||||
|
|
||||||
bool owns_lock() const;
|
bool owns_lock() const noexcept;
|
||||||
explicit operator bool () const;
|
explicit operator bool () const noexcept;
|
||||||
mutex_type* mutex() const;
|
mutex_type* mutex() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Mutex>
|
template <class Mutex>
|
||||||
void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);
|
void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
|
||||||
|
|
||||||
template <class L1, class L2, class... L3>
|
template <class L1, class L2, class... L3>
|
||||||
int try_lock(L1&, L2&, L3&...);
|
int try_lock(L1&, L2&, L3&...);
|
||||||
@ -159,7 +159,7 @@ template <class L1, class L2, class... L3>
|
|||||||
|
|
||||||
struct once_flag
|
struct once_flag
|
||||||
{
|
{
|
||||||
constexpr once_flag();
|
constexpr once_flag() noexcept;
|
||||||
|
|
||||||
once_flag(const once_flag&) = delete;
|
once_flag(const once_flag&) = delete;
|
||||||
once_flag& operator=(const once_flag&) = delete;
|
once_flag& operator=(const once_flag&) = delete;
|
||||||
@ -201,8 +201,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() _NOEXCEPT;
|
||||||
void unlock();
|
void unlock() _NOEXCEPT;
|
||||||
|
|
||||||
typedef pthread_mutex_t* native_handle_type;
|
typedef pthread_mutex_t* native_handle_type;
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
@ -224,14 +224,14 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() _NOEXCEPT;
|
||||||
template <class _Rep, class _Period>
|
template <class _Rep, class _Period>
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
|
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
|
||||||
{return try_lock_until(chrono::steady_clock::now() + __d);}
|
{return try_lock_until(chrono::steady_clock::now() + __d);}
|
||||||
template <class _Clock, class _Duration>
|
template <class _Clock, class _Duration>
|
||||||
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
|
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
|
||||||
void unlock();
|
void unlock() _NOEXCEPT;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class _Clock, class _Duration>
|
template <class _Clock, class _Duration>
|
||||||
@ -267,14 +267,14 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void lock();
|
void lock();
|
||||||
bool try_lock();
|
bool try_lock() _NOEXCEPT;
|
||||||
template <class _Rep, class _Period>
|
template <class _Rep, class _Period>
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
|
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
|
||||||
{return try_lock_until(chrono::steady_clock::now() + __d);}
|
{return try_lock_until(chrono::steady_clock::now() + __d);}
|
||||||
template <class _Clock, class _Duration>
|
template <class _Clock, class _Duration>
|
||||||
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
|
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
|
||||||
void unlock();
|
void unlock() _NOEXCEPT;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class _Clock, class _Duration>
|
template <class _Clock, class _Duration>
|
||||||
@ -442,8 +442,8 @@ template<class _Callable>
|
|||||||
struct _LIBCPP_VISIBLE once_flag
|
struct _LIBCPP_VISIBLE once_flag
|
||||||
{
|
{
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
// constexpr
|
_LIBCPP_CONSTEXPR
|
||||||
once_flag() {}
|
once_flag() _NOEXCEPT : __state_(0) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
once_flag(const once_flag&); // = delete;
|
once_flag(const once_flag&); // = delete;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#define _LIBCPP_BUILDING_MUTEX
|
||||||
#include "mutex"
|
#include "mutex"
|
||||||
#include "limits"
|
#include "limits"
|
||||||
#include "system_error"
|
#include "system_error"
|
||||||
@ -32,13 +33,13 @@ mutex::lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mutex::try_lock()
|
mutex::try_lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
return pthread_mutex_trylock(&__m_) == 0;
|
return pthread_mutex_trylock(&__m_) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mutex::unlock()
|
mutex::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
int ec = pthread_mutex_unlock(&__m_);
|
int ec = pthread_mutex_unlock(&__m_);
|
||||||
assert(ec == 0);
|
assert(ec == 0);
|
||||||
@ -90,14 +91,14 @@ recursive_mutex::lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
recursive_mutex::unlock()
|
recursive_mutex::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
int e = pthread_mutex_unlock(&__m_);
|
int e = pthread_mutex_unlock(&__m_);
|
||||||
assert(e == 0);
|
assert(e == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
recursive_mutex::try_lock()
|
recursive_mutex::try_lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
return pthread_mutex_trylock(&__m_) == 0;
|
return pthread_mutex_trylock(&__m_) == 0;
|
||||||
}
|
}
|
||||||
@ -124,7 +125,7 @@ timed_mutex::lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timed_mutex::try_lock()
|
timed_mutex::try_lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lk(__m_, try_to_lock);
|
unique_lock<mutex> lk(__m_, try_to_lock);
|
||||||
if (lk.owns_lock() && !__locked_)
|
if (lk.owns_lock() && !__locked_)
|
||||||
@ -136,7 +137,7 @@ timed_mutex::try_lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
timed_mutex::unlock()
|
timed_mutex::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
lock_guard<mutex> _(__m_);
|
lock_guard<mutex> _(__m_);
|
||||||
__locked_ = false;
|
__locked_ = false;
|
||||||
@ -175,7 +176,7 @@ recursive_timed_mutex::lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
recursive_timed_mutex::try_lock()
|
recursive_timed_mutex::try_lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
pthread_t id = pthread_self();
|
pthread_t id = pthread_self();
|
||||||
unique_lock<mutex> lk(__m_, try_to_lock);
|
unique_lock<mutex> lk(__m_, try_to_lock);
|
||||||
@ -191,7 +192,7 @@ recursive_timed_mutex::try_lock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
recursive_timed_mutex::unlock()
|
recursive_timed_mutex::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lk(__m_);
|
unique_lock<mutex> lk(__m_);
|
||||||
if (--__count_ == 0)
|
if (--__count_ == 0)
|
||||||
|
@ -11,11 +11,18 @@
|
|||||||
|
|
||||||
// struct once_flag;
|
// struct once_flag;
|
||||||
|
|
||||||
// constexpr once_flag();
|
// constexpr once_flag() noexcept;
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
std::once_flag f;
|
std::once_flag f;
|
||||||
}
|
}
|
||||||
|
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
|
||||||
|
{
|
||||||
|
constexpr std::once_flag f;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user