Contemplating this <atomic> reorganization...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@115087 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5b6af69387
commit
767ae2b483
237
include/atomic
237
include/atomic
@ -2415,6 +2415,85 @@ void atomic_signal_fence(memory_order);
|
|||||||
|
|
||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
|
|
||||||
|
// Begin "Intrinsics"
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_relaxed(volatile bool* __b)
|
||||||
|
{
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_consume(volatile bool* __b)
|
||||||
|
{
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_acquire(volatile bool* __b)
|
||||||
|
{
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_release(volatile bool* __b)
|
||||||
|
{
|
||||||
|
__sync_synchronize();
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_acq_rel(volatile bool* __b)
|
||||||
|
{
|
||||||
|
__sync_synchronize();
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
__test_and_set_seq_cst(volatile bool* __b)
|
||||||
|
{
|
||||||
|
__sync_synchronize();
|
||||||
|
return __sync_lock_test_and_set(__b, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
__atomic_store_relaxed(volatile bool* __b, bool __x)
|
||||||
|
{
|
||||||
|
__sync_lock_test_and_set(__b, __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
__atomic_store_consume(volatile bool* __b, bool __x)
|
||||||
|
{
|
||||||
|
__sync_lock_test_and_set(__b, __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
__atomic_store_release(volatile bool* __b, bool __x)
|
||||||
|
{
|
||||||
|
__sync_synchronize();
|
||||||
|
__sync_lock_test_and_set(__b, __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
__atomic_store_seq_cst(volatile bool* __b, bool __x)
|
||||||
|
{
|
||||||
|
__sync_synchronize();
|
||||||
|
__sync_lock_test_and_set(__b, __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// End "Intrinsics"
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
typedef enum memory_order
|
typedef enum memory_order
|
||||||
@ -2433,42 +2512,54 @@ kill_dependency(_Tp __y)
|
|||||||
|
|
||||||
// flag type and operations
|
// flag type and operations
|
||||||
|
|
||||||
struct __atomic_flag_init {};
|
struct atomic_flag;
|
||||||
|
|
||||||
typedef struct atomic_flag
|
bool atomic_flag_test_and_set(volatile atomic_flag*);
|
||||||
|
bool atomic_flag_test_and_set(atomic_flag*);
|
||||||
|
bool atomic_flag_test_and_set_explicit(volatile atomic_flag*, memory_order);
|
||||||
|
bool atomic_flag_test_and_set_explicit(atomic_flag*, memory_order);
|
||||||
|
void atomic_flag_clear(volatile atomic_flag*);
|
||||||
|
void atomic_flag_clear(atomic_flag*);
|
||||||
|
void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order);
|
||||||
|
void atomic_flag_clear_explicit(atomic_flag*, memory_order);
|
||||||
|
|
||||||
|
typedef struct _LIBCPP_VISIBLE atomic_flag
|
||||||
{
|
{
|
||||||
bool __flg_;
|
bool __flg_;
|
||||||
|
|
||||||
bool test_and_set(memory_order __o = memory_order_seq_cst) volatile
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
{
|
bool test_and_set() volatile
|
||||||
switch (__o)
|
{return atomic_flag_test_and_set(this);}
|
||||||
{
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
case memory_order_relaxed:
|
bool test_and_set(memory_order __o) volatile
|
||||||
case memory_order_consume:
|
{return atomic_flag_test_and_set_explicit(this, __o);}
|
||||||
case memory_order_acquire:
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
return __sync_lock_test_and_set(&__flg_, true);
|
bool test_and_set()
|
||||||
case memory_order_release:
|
{return atomic_flag_test_and_set(this);}
|
||||||
case memory_order_acq_rel:
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
case memory_order_seq_cst:
|
bool test_and_set(memory_order __o)
|
||||||
bool __r = __sync_lock_test_and_set(&__flg_, true);
|
{return atomic_flag_test_and_set_explicit(this, __o);}
|
||||||
__sync_synchronize();
|
|
||||||
return __r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_and_set(memory_order __o = memory_order_seq_cst)
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
{return const_cast<volatile atomic_flag*>(this)->test_and_set(__o);}
|
void clear() volatile
|
||||||
void clear(memory_order = memory_order_seq_cst) volatile;
|
{atomic_flag_clear(this);}
|
||||||
void clear(memory_order = memory_order_seq_cst);
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
void clear(memory_order __o) volatile
|
||||||
|
{atomic_flag_clear_explicit(this, __o);}
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
void clear()
|
||||||
|
{atomic_flag_clear(this);}
|
||||||
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
void clear(memory_order __o)
|
||||||
|
{atomic_flag_clear_explicit(this, __o);}
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
|
#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
|
||||||
atomic_flag() = default;
|
atomic_flag() = default;
|
||||||
#else
|
#else
|
||||||
atomic_flag() {};
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
atomic_flag() : __flg_(false) {};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
|
#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
|
||||||
atomic_flag(const atomic_flag&) = delete;
|
atomic_flag(const atomic_flag&) = delete;
|
||||||
atomic_flag& operator=(const atomic_flag&) = delete;
|
atomic_flag& operator=(const atomic_flag&) = delete;
|
||||||
@ -2480,21 +2571,93 @@ private:
|
|||||||
atomic_flag& operator=(const atomic_flag&) volatile;
|
atomic_flag& operator=(const atomic_flag&) volatile;
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
atomic_flag(__atomic_flag_init) : __flg_(false) {} // temporary
|
|
||||||
#endif
|
|
||||||
} atomic_flag;
|
} atomic_flag;
|
||||||
|
|
||||||
bool atomic_flag_test_and_set(volatile atomic_flag*);
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
bool atomic_flag_test_and_set(atomic_flag*);
|
bool
|
||||||
bool atomic_flag_test_and_set_explicit(volatile atomic_flag*, memory_order);
|
atomic_flag_test_and_set(volatile atomic_flag* __f)
|
||||||
bool atomic_flag_test_and_set_explicit(atomic_flag*, memory_order);
|
{
|
||||||
void atomic_flag_clear(volatile atomic_flag*);
|
return __test_and_set_seq_cst(&__f->__flg_);
|
||||||
void atomic_flag_clear(atomic_flag*);
|
}
|
||||||
void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order);
|
|
||||||
void atomic_flag_clear_explicit(atomic_flag*, memory_order);
|
|
||||||
|
|
||||||
#define ATOMIC_FLAG_INIT _STD::__atomic_flag_init()
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
atomic_flag_test_and_set(atomic_flag* __f)
|
||||||
|
{
|
||||||
|
return atomic_flag_test_and_set(const_cast<volatile atomic_flag*>(__f));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
atomic_flag_test_and_set_explicit(volatile atomic_flag* __f, memory_order __o)
|
||||||
|
{
|
||||||
|
switch (__o)
|
||||||
|
{
|
||||||
|
case memory_order_relaxed:
|
||||||
|
return __test_and_set_relaxed(&__f->__flg_);
|
||||||
|
case memory_order_consume:
|
||||||
|
return __test_and_set_consume(&__f->__flg_);
|
||||||
|
case memory_order_acquire:
|
||||||
|
return __test_and_set_acquire(&__f->__flg_);
|
||||||
|
case memory_order_release:
|
||||||
|
return __test_and_set_release(&__f->__flg_);
|
||||||
|
case memory_order_acq_rel:
|
||||||
|
return __test_and_set_acq_rel(&__f->__flg_);
|
||||||
|
case memory_order_seq_cst:
|
||||||
|
return __test_and_set_seq_cst(&__f->__flg_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool
|
||||||
|
atomic_flag_test_and_set_explicit(atomic_flag* __f, memory_order __o)
|
||||||
|
{
|
||||||
|
return atomic_flag_test_and_set_explicit(const_cast<volatile atomic_flag*>(__f), __o);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
atomic_flag_clear(volatile atomic_flag* __f)
|
||||||
|
{
|
||||||
|
return __atomic_store_seq_cst(&__f->__flg_, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
atomic_flag_clear(atomic_flag* __f)
|
||||||
|
{
|
||||||
|
atomic_flag_clear(const_cast<volatile atomic_flag*>(__f));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
atomic_flag_clear_explicit(volatile atomic_flag* __f, memory_order __o)
|
||||||
|
{
|
||||||
|
switch (__o)
|
||||||
|
{
|
||||||
|
case memory_order_relaxed:
|
||||||
|
__atomic_store_relaxed(&__f->__flg_, false);
|
||||||
|
break;
|
||||||
|
case memory_order_consume:
|
||||||
|
__atomic_store_consume(&__f->__flg_, false);
|
||||||
|
break;
|
||||||
|
case memory_order_release:
|
||||||
|
__atomic_store_release(&__f->__flg_, false);
|
||||||
|
break;
|
||||||
|
case memory_order_seq_cst:
|
||||||
|
__atomic_store_seq_cst(&__f->__flg_, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
void
|
||||||
|
atomic_flag_clear_explicit(atomic_flag* __f, memory_order __o)
|
||||||
|
{
|
||||||
|
atomic_flag_clear_explicit(const_cast<volatile atomic_flag*>(__f), __o);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ATOMIC_FLAG_INIT {false}
|
||||||
|
|
||||||
_LIBCPP_END_NAMESPACE_STD
|
_LIBCPP_END_NAMESPACE_STD
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::atomic_flag f = ATOMIC_FLAG_INIT;
|
std::atomic_flag f;
|
||||||
assert(f.test_and_set() == 0);
|
assert(f.test_and_set() == 0);
|
||||||
assert(f.test_and_set() == 1);
|
assert(f.test_and_set() == 1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user