123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442 |
- // -*- C++ -*-
- //===--------------------------- atomic -----------------------------------===//
- //
- // 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
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP_ATOMIC
- #define _LIBCPP_ATOMIC
- /*
- atomic synopsis
- namespace std
- {
- // feature test macro
- #define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
- // order and consistency
- enum memory_order: unspecified // enum class in C++20
- {
- relaxed,
- consume, // load-consume
- acquire, // load-acquire
- release, // store-release
- acq_rel, // store-release load-acquire
- seq_cst // store-release load-acquire
- };
- inline constexpr auto memory_order_relaxed = memory_order::relaxed;
- inline constexpr auto memory_order_consume = memory_order::consume;
- inline constexpr auto memory_order_acquire = memory_order::acquire;
- inline constexpr auto memory_order_release = memory_order::release;
- inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
- inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
- template <class T> T kill_dependency(T y) noexcept;
- // lock-free property
- #define ATOMIC_BOOL_LOCK_FREE unspecified
- #define ATOMIC_CHAR_LOCK_FREE unspecified
- #define ATOMIC_CHAR16_T_LOCK_FREE unspecified
- #define ATOMIC_CHAR32_T_LOCK_FREE unspecified
- #define ATOMIC_WCHAR_T_LOCK_FREE unspecified
- #define ATOMIC_SHORT_LOCK_FREE unspecified
- #define ATOMIC_INT_LOCK_FREE unspecified
- #define ATOMIC_LONG_LOCK_FREE unspecified
- #define ATOMIC_LLONG_LOCK_FREE unspecified
- #define ATOMIC_POINTER_LOCK_FREE unspecified
- // flag type and operations
- typedef struct atomic_flag
- {
- bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
- bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
- void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
- void clear(memory_order m = memory_order_seq_cst) noexcept;
- atomic_flag() noexcept = default;
- atomic_flag(const atomic_flag&) = delete;
- atomic_flag& operator=(const atomic_flag&) = delete;
- atomic_flag& operator=(const atomic_flag&) volatile = delete;
- } atomic_flag;
- bool
- atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
- bool
- atomic_flag_test_and_set(atomic_flag* obj) noexcept;
- bool
- atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
- memory_order m) noexcept;
- bool
- atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
- void
- atomic_flag_clear(volatile atomic_flag* obj) noexcept;
- void
- atomic_flag_clear(atomic_flag* obj) noexcept;
- void
- atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
- void
- atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
- #define ATOMIC_FLAG_INIT see below
- #define ATOMIC_VAR_INIT(value) see below
- template <class T>
- struct atomic
- {
- static constexpr bool is_always_lock_free;
- bool is_lock_free() const volatile noexcept;
- bool is_lock_free() const noexcept;
- void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
- void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
- T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
- T load(memory_order m = memory_order_seq_cst) const noexcept;
- operator T() const volatile noexcept;
- operator T() const noexcept;
- T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
- T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_weak(T& expc, T desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
- bool compare_exchange_strong(T& expc, T desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_strong(T& expc, T desr,
- memory_order s, memory_order f) noexcept;
- bool compare_exchange_weak(T& expc, T desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_weak(T& expc, T desr,
- memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_strong(T& expc, T desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_strong(T& expc, T desr,
- memory_order m = memory_order_seq_cst) noexcept;
- atomic() noexcept = default;
- constexpr atomic(T desr) noexcept;
- atomic(const atomic&) = delete;
- atomic& operator=(const atomic&) = delete;
- atomic& operator=(const atomic&) volatile = delete;
- T operator=(T) volatile noexcept;
- T operator=(T) noexcept;
- };
- template <>
- struct atomic<integral>
- {
- static constexpr bool is_always_lock_free;
- bool is_lock_free() const volatile noexcept;
- bool is_lock_free() const noexcept;
- void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
- void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
- integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
- integral load(memory_order m = memory_order_seq_cst) const noexcept;
- operator integral() const volatile noexcept;
- operator integral() const noexcept;
- integral exchange(integral desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_weak(integral& expc, integral desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_weak(integral& expc, integral desr,
- memory_order s, memory_order f) noexcept;
- bool compare_exchange_strong(integral& expc, integral desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_strong(integral& expc, integral desr,
- memory_order s, memory_order f) noexcept;
- bool compare_exchange_weak(integral& expc, integral desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_weak(integral& expc, integral desr,
- memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_strong(integral& expc, integral desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_strong(integral& expc, integral desr,
- memory_order m = memory_order_seq_cst) noexcept;
- integral
- fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
- integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
- integral
- fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
- integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
- integral
- fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
- integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
- integral
- fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
- integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
- integral
- fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
- integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
- atomic() noexcept = default;
- constexpr atomic(integral desr) noexcept;
- atomic(const atomic&) = delete;
- atomic& operator=(const atomic&) = delete;
- atomic& operator=(const atomic&) volatile = delete;
- integral operator=(integral desr) volatile noexcept;
- integral operator=(integral desr) noexcept;
- integral operator++(int) volatile noexcept;
- integral operator++(int) noexcept;
- integral operator--(int) volatile noexcept;
- integral operator--(int) noexcept;
- integral operator++() volatile noexcept;
- integral operator++() noexcept;
- integral operator--() volatile noexcept;
- integral operator--() noexcept;
- integral operator+=(integral op) volatile noexcept;
- integral operator+=(integral op) noexcept;
- integral operator-=(integral op) volatile noexcept;
- integral operator-=(integral op) noexcept;
- integral operator&=(integral op) volatile noexcept;
- integral operator&=(integral op) noexcept;
- integral operator|=(integral op) volatile noexcept;
- integral operator|=(integral op) noexcept;
- integral operator^=(integral op) volatile noexcept;
- integral operator^=(integral op) noexcept;
- };
- template <class T>
- struct atomic<T*>
- {
- static constexpr bool is_always_lock_free;
- bool is_lock_free() const volatile noexcept;
- bool is_lock_free() const noexcept;
- void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
- void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
- T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
- T* load(memory_order m = memory_order_seq_cst) const noexcept;
- operator T*() const volatile noexcept;
- operator T*() const noexcept;
- T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
- T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_weak(T*& expc, T* desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_weak(T*& expc, T* desr,
- memory_order s, memory_order f) noexcept;
- bool compare_exchange_strong(T*& expc, T* desr,
- memory_order s, memory_order f) volatile noexcept;
- bool compare_exchange_strong(T*& expc, T* desr,
- memory_order s, memory_order f) noexcept;
- bool compare_exchange_weak(T*& expc, T* desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_weak(T*& expc, T* desr,
- memory_order m = memory_order_seq_cst) noexcept;
- bool compare_exchange_strong(T*& expc, T* desr,
- memory_order m = memory_order_seq_cst) volatile noexcept;
- bool compare_exchange_strong(T*& expc, T* desr,
- memory_order m = memory_order_seq_cst) noexcept;
- T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
- T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
- T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
- T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
- atomic() noexcept = default;
- constexpr atomic(T* desr) noexcept;
- atomic(const atomic&) = delete;
- atomic& operator=(const atomic&) = delete;
- atomic& operator=(const atomic&) volatile = delete;
- T* operator=(T*) volatile noexcept;
- T* operator=(T*) noexcept;
- T* operator++(int) volatile noexcept;
- T* operator++(int) noexcept;
- T* operator--(int) volatile noexcept;
- T* operator--(int) noexcept;
- T* operator++() volatile noexcept;
- T* operator++() noexcept;
- T* operator--() volatile noexcept;
- T* operator--() noexcept;
- T* operator+=(ptrdiff_t op) volatile noexcept;
- T* operator+=(ptrdiff_t op) noexcept;
- T* operator-=(ptrdiff_t op) volatile noexcept;
- T* operator-=(ptrdiff_t op) noexcept;
- };
- template <class T>
- bool
- atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
- template <class T>
- bool
- atomic_is_lock_free(const atomic<T>* obj) noexcept;
- template <class T>
- void
- atomic_init(volatile atomic<T>* obj, T desr) noexcept;
- template <class T>
- void
- atomic_init(atomic<T>* obj, T desr) noexcept;
- template <class T>
- void
- atomic_store(volatile atomic<T>* obj, T desr) noexcept;
- template <class T>
- void
- atomic_store(atomic<T>* obj, T desr) noexcept;
- template <class T>
- void
- atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
- template <class T>
- void
- atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
- template <class T>
- T
- atomic_load(const volatile atomic<T>* obj) noexcept;
- template <class T>
- T
- atomic_load(const atomic<T>* obj) noexcept;
- template <class T>
- T
- atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
- template <class T>
- T
- atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
- template <class T>
- T
- atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
- template <class T>
- T
- atomic_exchange(atomic<T>* obj, T desr) noexcept;
- template <class T>
- T
- atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
- template <class T>
- T
- atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
- T desr,
- memory_order s, memory_order f) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
- memory_order s, memory_order f) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
- T* expc, T desr,
- memory_order s, memory_order f) noexcept;
- template <class T>
- bool
- atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
- T desr,
- memory_order s, memory_order f) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class Integral>
- Integral
- atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
- memory_order m) noexcept;
- template <class T>
- T*
- atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
- template <class T>
- T*
- atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
- template <class T>
- T*
- atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
- memory_order m) noexcept;
- template <class T>
- T*
- atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
- template <class T>
- T*
- atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
- template <class T>
- T*
- atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
- template <class T>
- T*
- atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
- memory_order m) noexcept;
- template <class T>
- T*
- atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
- // Atomics for standard typedef types
- typedef atomic<bool> atomic_bool;
- typedef atomic<char> atomic_char;
- typedef atomic<signed char> atomic_schar;
- typedef atomic<unsigned char> atomic_uchar;
- typedef atomic<short> atomic_short;
- typedef atomic<unsigned short> atomic_ushort;
- typedef atomic<int> atomic_int;
- typedef atomic<unsigned int> atomic_uint;
- typedef atomic<long> atomic_long;
- typedef atomic<unsigned long> atomic_ulong;
- typedef atomic<long long> atomic_llong;
- typedef atomic<unsigned long long> atomic_ullong;
- typedef atomic<char16_t> atomic_char16_t;
- typedef atomic<char32_t> atomic_char32_t;
- typedef atomic<wchar_t> atomic_wchar_t;
- typedef atomic<int_least8_t> atomic_int_least8_t;
- typedef atomic<uint_least8_t> atomic_uint_least8_t;
- typedef atomic<int_least16_t> atomic_int_least16_t;
- typedef atomic<uint_least16_t> atomic_uint_least16_t;
- typedef atomic<int_least32_t> atomic_int_least32_t;
- typedef atomic<uint_least32_t> atomic_uint_least32_t;
- typedef atomic<int_least64_t> atomic_int_least64_t;
- typedef atomic<uint_least64_t> atomic_uint_least64_t;
- typedef atomic<int_fast8_t> atomic_int_fast8_t;
- typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
- typedef atomic<int_fast16_t> atomic_int_fast16_t;
- typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
- typedef atomic<int_fast32_t> atomic_int_fast32_t;
- typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
- typedef atomic<int_fast64_t> atomic_int_fast64_t;
- typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
- typedef atomic<int8_t> atomic_int8_t;
- typedef atomic<uint8_t> atomic_uint8_t;
- typedef atomic<int16_t> atomic_int16_t;
- typedef atomic<uint16_t> atomic_uint16_t;
- typedef atomic<int32_t> atomic_int32_t;
- typedef atomic<uint32_t> atomic_uint32_t;
- typedef atomic<int64_t> atomic_int64_t;
- typedef atomic<uint64_t> atomic_uint64_t;
- typedef atomic<intptr_t> atomic_intptr_t;
- typedef atomic<uintptr_t> atomic_uintptr_t;
- typedef atomic<size_t> atomic_size_t;
- typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
- typedef atomic<intmax_t> atomic_intmax_t;
- typedef atomic<uintmax_t> atomic_uintmax_t;
- // fences
- void atomic_thread_fence(memory_order m) noexcept;
- void atomic_signal_fence(memory_order m) noexcept;
- } // std
- */
- #include <__config>
- #include <cstddef>
- #include <cstdint>
- #include <type_traits>
- #include <version>
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- #pragma GCC system_header
- #endif
- #ifdef _LIBCPP_HAS_NO_THREADS
- # error <atomic> is not supported on this single threaded system
- #endif
- #ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
- # error <atomic> is not implemented
- #endif
- #ifdef kill_dependency
- # error C++ standard library is incompatible with <stdatomic.h>
- #endif
- #define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
- _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
- __m == memory_order_acquire || \
- __m == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
- #define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
- _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
- __m == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
- #define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
- _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
- __f == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
- _LIBCPP_BEGIN_NAMESPACE_STD
- // Figure out what the underlying type for `memory_order` would be if it were
- // declared as an unscoped enum (accounting for -fshort-enums). Use this result
- // to pin the underlying type in C++20.
- enum __legacy_memory_order {
- __mo_relaxed,
- __mo_consume,
- __mo_acquire,
- __mo_release,
- __mo_acq_rel,
- __mo_seq_cst
- };
- typedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t;
- #if _LIBCPP_STD_VER > 17
- enum class memory_order : __memory_order_underlying_t {
- relaxed = __mo_relaxed,
- consume = __mo_consume,
- acquire = __mo_acquire,
- release = __mo_release,
- acq_rel = __mo_acq_rel,
- seq_cst = __mo_seq_cst
- };
- inline constexpr auto memory_order_relaxed = memory_order::relaxed;
- inline constexpr auto memory_order_consume = memory_order::consume;
- inline constexpr auto memory_order_acquire = memory_order::acquire;
- inline constexpr auto memory_order_release = memory_order::release;
- inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
- inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
- #else
- typedef enum memory_order {
- memory_order_relaxed = __mo_relaxed,
- memory_order_consume = __mo_consume,
- memory_order_acquire = __mo_acquire,
- memory_order_release = __mo_release,
- memory_order_acq_rel = __mo_acq_rel,
- memory_order_seq_cst = __mo_seq_cst,
- } memory_order;
- #endif // _LIBCPP_STD_VER > 17
- static_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value),
- "unexpected underlying type for std::memory_order");
- #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \
- defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
- // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
- // the default operator= in an object is not volatile, a byte-by-byte copy
- // is required.
- template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
- typename enable_if<is_assignable<_Tp&, _Tv>::value>::type
- __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
- __a_value = __val;
- }
- template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
- typename enable_if<is_assignable<_Tp&, _Tv>::value>::type
- __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
- volatile char* __to = reinterpret_cast<volatile char*>(&__a_value);
- volatile char* __end = __to + sizeof(_Tp);
- volatile const char* __from = reinterpret_cast<volatile const char*>(&__val);
- while (__to != __end)
- *__to++ = *__from++;
- }
- #endif
- #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
- template <typename _Tp>
- struct __cxx_atomic_base_impl {
- _LIBCPP_INLINE_VISIBILITY
- #ifndef _LIBCPP_CXX03_LANG
- __cxx_atomic_base_impl() _NOEXCEPT = default;
- #else
- __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
- #endif // _LIBCPP_CXX03_LANG
- _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
- : __a_value(value) {}
- _Tp __a_value;
- };
- _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
- // Avoid switch statement to make this a constexpr.
- return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
- (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
- (__order == memory_order_release ? __ATOMIC_RELEASE:
- (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
- (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
- __ATOMIC_CONSUME))));
- }
- _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
- // Avoid switch statement to make this a constexpr.
- return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
- (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
- (__order == memory_order_release ? __ATOMIC_RELAXED:
- (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
- (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
- __ATOMIC_CONSUME))));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
- __cxx_atomic_assign_volatile(__a->__a_value, __val);
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
- __a->__a_value = __val;
- }
- _LIBCPP_INLINE_VISIBILITY inline
- void __cxx_atomic_thread_fence(memory_order __order) {
- __atomic_thread_fence(__to_gcc_order(__order));
- }
- _LIBCPP_INLINE_VISIBILITY inline
- void __cxx_atomic_signal_fence(memory_order __order) {
- __atomic_signal_fence(__to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val,
- memory_order __order) {
- __atomic_store(&__a->__a_value, &__val,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val,
- memory_order __order) {
- __atomic_store(&__a->__a_value, &__val,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a,
- memory_order __order) {
- _Tp __ret;
- __atomic_load(&__a->__a_value, &__ret,
- __to_gcc_order(__order));
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
- _Tp __ret;
- __atomic_load(&__a->__a_value, &__ret,
- __to_gcc_order(__order));
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Tp __value, memory_order __order) {
- _Tp __ret;
- __atomic_exchange(&__a->__a_value, &__value, &__ret,
- __to_gcc_order(__order));
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value,
- memory_order __order) {
- _Tp __ret;
- __atomic_exchange(&__a->__a_value, &__value, &__ret,
- __to_gcc_order(__order));
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(
- volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
- memory_order __success, memory_order __failure) {
- return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
- false,
- __to_gcc_order(__success),
- __to_gcc_failure_order(__failure));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(
- __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
- memory_order __failure) {
- return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
- false,
- __to_gcc_order(__success),
- __to_gcc_failure_order(__failure));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(
- volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
- memory_order __success, memory_order __failure) {
- return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
- true,
- __to_gcc_order(__success),
- __to_gcc_failure_order(__failure));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(
- __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
- memory_order __failure) {
- return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
- true,
- __to_gcc_order(__success),
- __to_gcc_failure_order(__failure));
- }
- template <typename _Tp>
- struct __skip_amt { enum {value = 1}; };
- template <typename _Tp>
- struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
- // FIXME: Haven't figured out what the spec says about using arrays with
- // atomic_fetch_add. Force a failure rather than creating bad behavior.
- template <typename _Tp>
- struct __skip_amt<_Tp[]> { };
- template <typename _Tp, int n>
- struct __skip_amt<_Tp[n]> { };
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Td __delta, memory_order __order) {
- return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
- __to_gcc_order(__order));
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
- memory_order __order) {
- return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
- __to_gcc_order(__order));
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Td __delta, memory_order __order) {
- return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
- __to_gcc_order(__order));
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
- memory_order __order) {
- return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Tp __pattern, memory_order __order) {
- return __atomic_fetch_and(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a,
- _Tp __pattern, memory_order __order) {
- return __atomic_fetch_and(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Tp __pattern, memory_order __order) {
- return __atomic_fetch_or(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
- memory_order __order) {
- return __atomic_fetch_or(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a,
- _Tp __pattern, memory_order __order) {
- return __atomic_fetch_xor(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
- memory_order __order) {
- return __atomic_fetch_xor(&__a->__a_value, __pattern,
- __to_gcc_order(__order));
- }
- #define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
- #elif defined(_LIBCPP_HAS_C_ATOMIC_IMP)
- template <typename _Tp>
- struct __cxx_atomic_base_impl {
- _LIBCPP_INLINE_VISIBILITY
- #ifndef _LIBCPP_CXX03_LANG
- __cxx_atomic_base_impl() _NOEXCEPT = default;
- #else
- __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
- #endif // _LIBCPP_CXX03_LANG
- _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
- : __a_value(value) {}
- _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
- };
- #define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
- _LIBCPP_INLINE_VISIBILITY inline
- void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
- __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
- }
- _LIBCPP_INLINE_VISIBILITY inline
- void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
- __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
- __c11_atomic_init(&__a->__a_value, __val);
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) _NOEXCEPT {
- __c11_atomic_init(&__a->__a_value, __val);
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
- __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) _NOEXCEPT {
- __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
- using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
- return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
- using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
- return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
- return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) _NOEXCEPT {
- return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
- return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
- return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
- return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
- return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- template<class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
- return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
- }
- #endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp kill_dependency(_Tp __y) _NOEXCEPT
- {
- return __y;
- }
- #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
- # define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
- # define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
- # define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
- # define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
- # define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
- # define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE
- # define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE
- # define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE
- # define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE
- # define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE
- #elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
- # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
- # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
- # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
- # define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
- # define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
- # define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
- # define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
- # define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
- # define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
- # define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
- #endif
- #ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
- template<typename _Tp>
- struct __cxx_atomic_lock_impl {
- _LIBCPP_INLINE_VISIBILITY
- __cxx_atomic_lock_impl() _NOEXCEPT
- : __a_value(), __a_lock(0) {}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit
- __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT
- : __a_value(value), __a_lock(0) {}
- _Tp __a_value;
- mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock;
- _LIBCPP_INLINE_VISIBILITY void __lock() const volatile {
- while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
- /*spin*/;
- }
- _LIBCPP_INLINE_VISIBILITY void __lock() const {
- while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
- /*spin*/;
- }
- _LIBCPP_INLINE_VISIBILITY void __unlock() const volatile {
- __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
- }
- _LIBCPP_INLINE_VISIBILITY void __unlock() const {
- __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
- }
- _LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile {
- __lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a_value);
- __unlock();
- return __old;
- }
- _LIBCPP_INLINE_VISIBILITY _Tp __read() const {
- __lock();
- _Tp __old = __a_value;
- __unlock();
- return __old;
- }
- };
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
- __cxx_atomic_assign_volatile(__a->__a_value, __val);
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
- __a->__a_value = __val;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
- __a->__lock();
- __cxx_atomic_assign_volatile(__a->__a_value, __val);
- __a->__unlock();
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
- __a->__lock();
- __a->__a_value = __val;
- __a->__unlock();
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
- return __a->__read();
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
- return __a->__read();
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, __value);
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value = __value;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Tp* __expected, _Tp __value, memory_order, memory_order) {
- __a->__lock();
- _Tp temp;
- __cxx_atomic_assign_volatile(temp, __a->__a_value);
- bool __ret = temp == *__expected;
- if(__ret)
- __cxx_atomic_assign_volatile(__a->__a_value, __value);
- else
- __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
- __a->__unlock();
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a,
- _Tp* __expected, _Tp __value, memory_order, memory_order) {
- __a->__lock();
- bool __ret = __a->__a_value == *__expected;
- if(__ret)
- __a->__a_value = __value;
- else
- *__expected = __a->__a_value;
- __a->__unlock();
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Tp* __expected, _Tp __value, memory_order, memory_order) {
- __a->__lock();
- _Tp temp;
- __cxx_atomic_assign_volatile(temp, __a->__a_value);
- bool __ret = temp == *__expected;
- if(__ret)
- __cxx_atomic_assign_volatile(__a->__a_value, __value);
- else
- __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
- __a->__unlock();
- return __ret;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a,
- _Tp* __expected, _Tp __value, memory_order, memory_order) {
- __a->__lock();
- bool __ret = __a->__a_value == *__expected;
- if(__ret)
- __a->__a_value = __value;
- else
- *__expected = __a->__a_value;
- __a->__unlock();
- return __ret;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Td __delta, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta));
- __a->__unlock();
- return __old;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a,
- _Td __delta, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value += __delta;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a,
- ptrdiff_t __delta, memory_order) {
- __a->__lock();
- _Tp* __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, __old + __delta);
- __a->__unlock();
- return __old;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a,
- ptrdiff_t __delta, memory_order) {
- __a->__lock();
- _Tp* __old = __a->__a_value;
- __a->__a_value += __delta;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Td __delta, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta));
- __a->__unlock();
- return __old;
- }
- template <typename _Tp, typename _Td>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a,
- _Td __delta, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value -= __delta;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern));
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value &= __pattern;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern));
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value |= __pattern;
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old;
- __cxx_atomic_assign_volatile(__old, __a->__a_value);
- __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern));
- __a->__unlock();
- return __old;
- }
- template <typename _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
- _Tp __pattern, memory_order) {
- __a->__lock();
- _Tp __old = __a->__a_value;
- __a->__a_value ^= __pattern;
- __a->__unlock();
- return __old;
- }
- #ifdef __cpp_lib_atomic_is_always_lock_free
- template<typename _Tp> struct __cxx_is_always_lock_free {
- enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; };
- #else
- template<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; };
- // Implementations must match the C ATOMIC_*_LOCK_FREE macro values.
- template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
- template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
- template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
- #endif //__cpp_lib_atomic_is_always_lock_free
- template <typename _Tp,
- typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value,
- __cxx_atomic_base_impl<_Tp>,
- __cxx_atomic_lock_impl<_Tp> >::type>
- #else
- template <typename _Tp,
- typename _Base = __cxx_atomic_base_impl<_Tp> >
- #endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
- struct __cxx_atomic_impl : public _Base {
- #if _GNUC_VER >= 501
- static_assert(is_trivially_copyable<_Tp>::value,
- "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
- #endif
- _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
- : _Base(value) {}
- };
- // general atomic<T>
- template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
- struct __atomic_base // false
- {
- mutable __cxx_atomic_impl<_Tp> __a_;
- #if defined(__cpp_lib_atomic_is_always_lock_free)
- static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
- #endif
- _LIBCPP_INLINE_VISIBILITY
- bool is_lock_free() const volatile _NOEXCEPT
- {return __cxx_atomic_is_lock_free(sizeof(_Tp));}
- _LIBCPP_INLINE_VISIBILITY
- bool is_lock_free() const _NOEXCEPT
- {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
- _LIBCPP_INLINE_VISIBILITY
- void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
- {__cxx_atomic_store(&__a_, __d, __m);}
- _LIBCPP_INLINE_VISIBILITY
- void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
- {__cxx_atomic_store(&__a_, __d, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
- _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
- {return __cxx_atomic_load(&__a_, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
- _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
- {return __cxx_atomic_load(&__a_, __m);}
- _LIBCPP_INLINE_VISIBILITY
- operator _Tp() const volatile _NOEXCEPT {return load();}
- _LIBCPP_INLINE_VISIBILITY
- operator _Tp() const _NOEXCEPT {return load();}
- _LIBCPP_INLINE_VISIBILITY
- _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_exchange(&__a_, __d, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_exchange(&__a_, __d, __m);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_weak(_Tp& __e, _Tp __d,
- memory_order __s, memory_order __f) volatile _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_weak(_Tp& __e, _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_strong(_Tp& __e, _Tp __d,
- memory_order __s, memory_order __f) volatile _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_strong(_Tp& __e, _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_weak(_Tp& __e, _Tp __d,
- memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_weak(_Tp& __e, _Tp __d,
- memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_strong(_Tp& __e, _Tp __d,
- memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
- _LIBCPP_INLINE_VISIBILITY
- bool compare_exchange_strong(_Tp& __e, _Tp __d,
- memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
- _LIBCPP_INLINE_VISIBILITY
- __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
- #ifndef _LIBCPP_CXX03_LANG
- __atomic_base(const __atomic_base&) = delete;
- __atomic_base& operator=(const __atomic_base&) = delete;
- __atomic_base& operator=(const __atomic_base&) volatile = delete;
- #else
- private:
- __atomic_base(const __atomic_base&);
- __atomic_base& operator=(const __atomic_base&);
- __atomic_base& operator=(const __atomic_base&) volatile;
- #endif
- };
- #if defined(__cpp_lib_atomic_is_always_lock_free)
- template <class _Tp, bool __b>
- _LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
- #endif
- // atomic<Integral>
- template <class _Tp>
- struct __atomic_base<_Tp, true>
- : public __atomic_base<_Tp, false>
- {
- typedef __atomic_base<_Tp, false> __base;
- _LIBCPP_INLINE_VISIBILITY
- __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
- };
- // atomic<T>
- template <class _Tp>
- struct atomic
- : public __atomic_base<_Tp>
- {
- typedef __atomic_base<_Tp> __base;
- _LIBCPP_INLINE_VISIBILITY
- atomic() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator=(_Tp __d) volatile _NOEXCEPT
- {__base::store(__d); return __d;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp operator=(_Tp __d) _NOEXCEPT
- {__base::store(__d); return __d;}
- };
- // atomic<T*>
- template <class _Tp>
- struct atomic<_Tp*>
- : public __atomic_base<_Tp*>
- {
- typedef __atomic_base<_Tp*> __base;
- _LIBCPP_INLINE_VISIBILITY
- atomic() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
- {__base::store(__d); return __d;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator=(_Tp* __d) _NOEXCEPT
- {__base::store(__d); return __d;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
- volatile _NOEXCEPT
- {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
- volatile _NOEXCEPT
- {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
- _LIBCPP_INLINE_VISIBILITY
- _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
- };
- // atomic_is_lock_free
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
- {
- return __o->is_lock_free();
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
- {
- return __o->is_lock_free();
- }
- // atomic_init
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- __cxx_atomic_init(&__o->__a_, __d);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- __cxx_atomic_init(&__o->__a_, __d);
- }
- // atomic_store
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- __o->store(__d);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- __o->store(__d);
- }
- // atomic_store_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
- _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
- {
- __o->store(__d, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- void
- atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
- _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
- {
- __o->store(__d, __m);
- }
- // atomic_load
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
- {
- return __o->load();
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
- {
- return __o->load();
- }
- // atomic_load_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
- _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
- {
- return __o->load(__m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
- _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
- {
- return __o->load(__m);
- }
- // atomic_exchange
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- return __o->exchange(__d);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
- {
- return __o->exchange(__d);
- }
- // atomic_exchange_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
- {
- return __o->exchange(__d, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp
- atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
- {
- return __o->exchange(__d, __m);
- }
- // atomic_compare_exchange_weak
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
- {
- return __o->compare_exchange_weak(*__e, __d);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
- {
- return __o->compare_exchange_weak(*__e, __d);
- }
- // atomic_compare_exchange_strong
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
- {
- return __o->compare_exchange_strong(*__e, __d);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
- {
- return __o->compare_exchange_strong(*__e, __d);
- }
- // atomic_compare_exchange_weak_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
- _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {
- return __o->compare_exchange_weak(*__e, __d, __s, __f);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {
- return __o->compare_exchange_weak(*__e, __d, __s, __f);
- }
- // atomic_compare_exchange_strong_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
- _Tp* __e, _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {
- return __o->compare_exchange_strong(*__e, __d, __s, __f);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
- _Tp __d,
- memory_order __s, memory_order __f) _NOEXCEPT
- _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
- {
- return __o->compare_exchange_strong(*__e, __d, __s, __f);
- }
- // atomic_fetch_add
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_add(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_add(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
- {
- return __o->fetch_add(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
- {
- return __o->fetch_add(__op);
- }
- // atomic_fetch_add_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_add(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_add(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
- memory_order __m) _NOEXCEPT
- {
- return __o->fetch_add(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_add(__op, __m);
- }
- // atomic_fetch_sub
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_sub(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_sub(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
- {
- return __o->fetch_sub(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
- {
- return __o->fetch_sub(__op);
- }
- // atomic_fetch_sub_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_sub(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_sub(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
- memory_order __m) _NOEXCEPT
- {
- return __o->fetch_sub(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- _Tp*
- atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_sub(__op, __m);
- }
- // atomic_fetch_and
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_and(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_and(__op);
- }
- // atomic_fetch_and_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_and(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_and(__op, __m);
- }
- // atomic_fetch_or
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_or(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_or(__op);
- }
- // atomic_fetch_or_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_or(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_or(__op, __m);
- }
- // atomic_fetch_xor
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_xor(__op);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
- {
- return __o->fetch_xor(__op);
- }
- // atomic_fetch_xor_explicit
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_xor(__op, __m);
- }
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY
- typename enable_if
- <
- is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
- _Tp
- >::type
- atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
- {
- return __o->fetch_xor(__op, __m);
- }
- // flag type and operations
- typedef struct atomic_flag
- {
- __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
- _LIBCPP_INLINE_VISIBILITY
- bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
- _LIBCPP_INLINE_VISIBILITY
- bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
- _LIBCPP_INLINE_VISIBILITY
- void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
- {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
- _LIBCPP_INLINE_VISIBILITY
- void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
- {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
- _LIBCPP_INLINE_VISIBILITY
- atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
- #ifndef _LIBCPP_CXX03_LANG
- atomic_flag(const atomic_flag&) = delete;
- atomic_flag& operator=(const atomic_flag&) = delete;
- atomic_flag& operator=(const atomic_flag&) volatile = delete;
- #else
- private:
- atomic_flag(const atomic_flag&);
- atomic_flag& operator=(const atomic_flag&);
- atomic_flag& operator=(const atomic_flag&) volatile;
- #endif
- } atomic_flag;
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
- {
- return __o->test_and_set();
- }
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
- {
- return __o->test_and_set();
- }
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
- {
- return __o->test_and_set(__m);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
- {
- return __o->test_and_set(__m);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
- {
- __o->clear();
- }
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
- {
- __o->clear();
- }
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
- {
- __o->clear(__m);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
- {
- __o->clear(__m);
- }
- // fences
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_thread_fence(memory_order __m) _NOEXCEPT
- {
- __cxx_atomic_thread_fence(__m);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- void
- atomic_signal_fence(memory_order __m) _NOEXCEPT
- {
- __cxx_atomic_signal_fence(__m);
- }
- // Atomics for standard typedef types
- typedef atomic<bool> atomic_bool;
- typedef atomic<char> atomic_char;
- typedef atomic<signed char> atomic_schar;
- typedef atomic<unsigned char> atomic_uchar;
- typedef atomic<short> atomic_short;
- typedef atomic<unsigned short> atomic_ushort;
- typedef atomic<int> atomic_int;
- typedef atomic<unsigned int> atomic_uint;
- typedef atomic<long> atomic_long;
- typedef atomic<unsigned long> atomic_ulong;
- typedef atomic<long long> atomic_llong;
- typedef atomic<unsigned long long> atomic_ullong;
- typedef atomic<char16_t> atomic_char16_t;
- typedef atomic<char32_t> atomic_char32_t;
- typedef atomic<wchar_t> atomic_wchar_t;
- typedef atomic<int_least8_t> atomic_int_least8_t;
- typedef atomic<uint_least8_t> atomic_uint_least8_t;
- typedef atomic<int_least16_t> atomic_int_least16_t;
- typedef atomic<uint_least16_t> atomic_uint_least16_t;
- typedef atomic<int_least32_t> atomic_int_least32_t;
- typedef atomic<uint_least32_t> atomic_uint_least32_t;
- typedef atomic<int_least64_t> atomic_int_least64_t;
- typedef atomic<uint_least64_t> atomic_uint_least64_t;
- typedef atomic<int_fast8_t> atomic_int_fast8_t;
- typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
- typedef atomic<int_fast16_t> atomic_int_fast16_t;
- typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
- typedef atomic<int_fast32_t> atomic_int_fast32_t;
- typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
- typedef atomic<int_fast64_t> atomic_int_fast64_t;
- typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
- typedef atomic< int8_t> atomic_int8_t;
- typedef atomic<uint8_t> atomic_uint8_t;
- typedef atomic< int16_t> atomic_int16_t;
- typedef atomic<uint16_t> atomic_uint16_t;
- typedef atomic< int32_t> atomic_int32_t;
- typedef atomic<uint32_t> atomic_uint32_t;
- typedef atomic< int64_t> atomic_int64_t;
- typedef atomic<uint64_t> atomic_uint64_t;
- typedef atomic<intptr_t> atomic_intptr_t;
- typedef atomic<uintptr_t> atomic_uintptr_t;
- typedef atomic<size_t> atomic_size_t;
- typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
- typedef atomic<intmax_t> atomic_intmax_t;
- typedef atomic<uintmax_t> atomic_uintmax_t;
- #define ATOMIC_FLAG_INIT {false}
- #define ATOMIC_VAR_INIT(__v) {__v}
- _LIBCPP_END_NAMESPACE_STD
- #endif // _LIBCPP_ATOMIC
|