···11-/* SPDX-License-Identifier: GPL-2.0 */11+// SPDX-License-Identifier: GPL-2.022+33+// Generated by scripts/atomic/gen-atomic-long.sh44+// DO NOT MODIFY THIS FILE DIRECTLY55+26#ifndef _ASM_GENERIC_ATOMIC_LONG_H37#define _ASM_GENERIC_ATOMIC_LONG_H44-/*55- * Copyright (C) 2005 Silicon Graphics, Inc.66- * Christoph Lameter77- *88- * Allows to provide arch independent atomic definitions without the need to99- * edit all arch specific atomic.h files.1010- */118129#include <asm/types.h>13101414-/*1515- * Suppport for atomic_long_t1616- *1717- * Casts for parameters are avoided for existing atomic functions in order to1818- * avoid issues with cast-as-lval under gcc 4.x and other limitations that the1919- * macros of a platform may have.2020- */2121-2222-#if BITS_PER_LONG == 642323-1111+#ifdef CONFIG_64BIT2412typedef atomic64_t atomic_long_t;2525-2626-#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)2727-#define ATOMIC_LONG_PFX(x) atomic64 ## x2828-#define ATOMIC_LONG_TYPE s642929-1313+#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)1414+#define atomic_long_cond_read_acquire atomic64_cond_read_acquire1515+#define atomic_long_cond_read_relaxed atomic64_cond_read_relaxed3016#else3131-3217typedef atomic_t atomic_long_t;3333-3434-#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)3535-#define ATOMIC_LONG_PFX(x) atomic ## x3636-#define ATOMIC_LONG_TYPE int3737-1818+#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)1919+#define atomic_long_cond_read_acquire atomic_cond_read_acquire2020+#define atomic_long_cond_read_relaxed atomic_cond_read_relaxed3821#endif39224040-#define ATOMIC_LONG_READ_OP(mo) \4141-static inline long atomic_long_read##mo(const atomic_long_t *l) \4242-{ \4343- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \4444- \4545- return (long)ATOMIC_LONG_PFX(_read##mo)(v); \4646-}4747-ATOMIC_LONG_READ_OP()4848-ATOMIC_LONG_READ_OP(_acquire)2323+#ifdef CONFIG_64BIT49245050-#undef ATOMIC_LONG_READ_OP5151-5252-#define ATOMIC_LONG_SET_OP(mo) \5353-static inline void atomic_long_set##mo(atomic_long_t *l, long i) \5454-{ \5555- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \5656- \5757- ATOMIC_LONG_PFX(_set##mo)(v, i); \5858-}5959-ATOMIC_LONG_SET_OP()6060-ATOMIC_LONG_SET_OP(_release)6161-6262-#undef ATOMIC_LONG_SET_OP6363-6464-#define ATOMIC_LONG_ADD_SUB_OP(op, mo) \6565-static inline long \6666-atomic_long_##op##_return##mo(long i, atomic_long_t *l) \6767-{ \6868- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \6969- \7070- return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(i, v); \7171-}7272-ATOMIC_LONG_ADD_SUB_OP(add,)7373-ATOMIC_LONG_ADD_SUB_OP(add, _relaxed)7474-ATOMIC_LONG_ADD_SUB_OP(add, _acquire)7575-ATOMIC_LONG_ADD_SUB_OP(add, _release)7676-ATOMIC_LONG_ADD_SUB_OP(sub,)7777-ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed)7878-ATOMIC_LONG_ADD_SUB_OP(sub, _acquire)7979-ATOMIC_LONG_ADD_SUB_OP(sub, _release)8080-8181-#undef ATOMIC_LONG_ADD_SUB_OP8282-8383-#define atomic_long_cmpxchg_relaxed(l, old, new) \8484- (ATOMIC_LONG_PFX(_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \8585- (old), (new)))8686-#define atomic_long_cmpxchg_acquire(l, old, new) \8787- (ATOMIC_LONG_PFX(_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \8888- (old), (new)))8989-#define atomic_long_cmpxchg_release(l, old, new) \9090- (ATOMIC_LONG_PFX(_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \9191- (old), (new)))9292-#define atomic_long_cmpxchg(l, old, new) \9393- (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new)))9494-9595-9696-#define atomic_long_try_cmpxchg_relaxed(l, old, new) \9797- (ATOMIC_LONG_PFX(_try_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \9898- (ATOMIC_LONG_TYPE *)(old), (ATOMIC_LONG_TYPE)(new)))9999-#define atomic_long_try_cmpxchg_acquire(l, old, new) \100100- (ATOMIC_LONG_PFX(_try_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \101101- (ATOMIC_LONG_TYPE *)(old), (ATOMIC_LONG_TYPE)(new)))102102-#define atomic_long_try_cmpxchg_release(l, old, new) \103103- (ATOMIC_LONG_PFX(_try_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \104104- (ATOMIC_LONG_TYPE *)(old), (ATOMIC_LONG_TYPE)(new)))105105-#define atomic_long_try_cmpxchg(l, old, new) \106106- (ATOMIC_LONG_PFX(_try_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), \107107- (ATOMIC_LONG_TYPE *)(old), (ATOMIC_LONG_TYPE)(new)))108108-109109-110110-#define atomic_long_xchg_relaxed(v, new) \111111- (ATOMIC_LONG_PFX(_xchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(v), (new)))112112-#define atomic_long_xchg_acquire(v, new) \113113- (ATOMIC_LONG_PFX(_xchg_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (new)))114114-#define atomic_long_xchg_release(v, new) \115115- (ATOMIC_LONG_PFX(_xchg_release)((ATOMIC_LONG_PFX(_t) *)(v), (new)))116116-#define atomic_long_xchg(v, new) \117117- (ATOMIC_LONG_PFX(_xchg)((ATOMIC_LONG_PFX(_t) *)(v), (new)))118118-119119-static __always_inline void atomic_long_inc(atomic_long_t *l)2525+static inline long2626+atomic_long_read(const atomic_long_t *v)12027{121121- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;122122-123123- ATOMIC_LONG_PFX(_inc)(v);2828+ return atomic64_read(v);12429}12530126126-static __always_inline void atomic_long_dec(atomic_long_t *l)3131+static inline long3232+atomic_long_read_acquire(const atomic_long_t *v)12733{128128- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;129129-130130- ATOMIC_LONG_PFX(_dec)(v);3434+ return atomic64_read_acquire(v);13135}13236133133-#define ATOMIC_LONG_FETCH_OP(op, mo) \134134-static inline long \135135-atomic_long_fetch_##op##mo(long i, atomic_long_t *l) \136136-{ \137137- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \138138- \139139- return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(i, v); \140140-}141141-142142-ATOMIC_LONG_FETCH_OP(add, )143143-ATOMIC_LONG_FETCH_OP(add, _relaxed)144144-ATOMIC_LONG_FETCH_OP(add, _acquire)145145-ATOMIC_LONG_FETCH_OP(add, _release)146146-ATOMIC_LONG_FETCH_OP(sub, )147147-ATOMIC_LONG_FETCH_OP(sub, _relaxed)148148-ATOMIC_LONG_FETCH_OP(sub, _acquire)149149-ATOMIC_LONG_FETCH_OP(sub, _release)150150-ATOMIC_LONG_FETCH_OP(and, )151151-ATOMIC_LONG_FETCH_OP(and, _relaxed)152152-ATOMIC_LONG_FETCH_OP(and, _acquire)153153-ATOMIC_LONG_FETCH_OP(and, _release)154154-ATOMIC_LONG_FETCH_OP(andnot, )155155-ATOMIC_LONG_FETCH_OP(andnot, _relaxed)156156-ATOMIC_LONG_FETCH_OP(andnot, _acquire)157157-ATOMIC_LONG_FETCH_OP(andnot, _release)158158-ATOMIC_LONG_FETCH_OP(or, )159159-ATOMIC_LONG_FETCH_OP(or, _relaxed)160160-ATOMIC_LONG_FETCH_OP(or, _acquire)161161-ATOMIC_LONG_FETCH_OP(or, _release)162162-ATOMIC_LONG_FETCH_OP(xor, )163163-ATOMIC_LONG_FETCH_OP(xor, _relaxed)164164-ATOMIC_LONG_FETCH_OP(xor, _acquire)165165-ATOMIC_LONG_FETCH_OP(xor, _release)166166-167167-#undef ATOMIC_LONG_FETCH_OP168168-169169-#define ATOMIC_LONG_FETCH_INC_DEC_OP(op, mo) \170170-static inline long \171171-atomic_long_fetch_##op##mo(atomic_long_t *l) \172172-{ \173173- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \174174- \175175- return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(v); \176176-}177177-178178-ATOMIC_LONG_FETCH_INC_DEC_OP(inc,)179179-ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed)180180-ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire)181181-ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release)182182-ATOMIC_LONG_FETCH_INC_DEC_OP(dec,)183183-ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed)184184-ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire)185185-ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _release)186186-187187-#undef ATOMIC_LONG_FETCH_INC_DEC_OP188188-189189-#define ATOMIC_LONG_OP(op) \190190-static __always_inline void \191191-atomic_long_##op(long i, atomic_long_t *l) \192192-{ \193193- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \194194- \195195- ATOMIC_LONG_PFX(_##op)(i, v); \196196-}197197-198198-ATOMIC_LONG_OP(add)199199-ATOMIC_LONG_OP(sub)200200-ATOMIC_LONG_OP(and)201201-ATOMIC_LONG_OP(andnot)202202-ATOMIC_LONG_OP(or)203203-ATOMIC_LONG_OP(xor)204204-205205-#undef ATOMIC_LONG_OP206206-207207-static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)3737+static inline void3838+atomic_long_set(atomic_long_t *v, long i)20839{209209- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;210210-211211- return ATOMIC_LONG_PFX(_sub_and_test)(i, v);4040+ atomic64_set(v, i);21241}21342214214-static inline int atomic_long_dec_and_test(atomic_long_t *l)4343+static inline void4444+atomic_long_set_release(atomic_long_t *v, long i)21545{216216- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;217217-218218- return ATOMIC_LONG_PFX(_dec_and_test)(v);4646+ atomic64_set_release(v, i);21947}22048221221-static inline int atomic_long_inc_and_test(atomic_long_t *l)4949+static inline void5050+atomic_long_add(long i, atomic_long_t *v)22251{223223- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;224224-225225- return ATOMIC_LONG_PFX(_inc_and_test)(v);5252+ atomic64_add(i, v);22653}22754228228-static inline int atomic_long_add_negative(long i, atomic_long_t *l)5555+static inline long5656+atomic_long_add_return(long i, atomic_long_t *v)22957{230230- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;231231-232232- return ATOMIC_LONG_PFX(_add_negative)(i, v);5858+ return atomic64_add_return(i, v);23359}23460235235-#define ATOMIC_LONG_INC_DEC_OP(op, mo) \236236-static inline long \237237-atomic_long_##op##_return##mo(atomic_long_t *l) \238238-{ \239239- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \240240- \241241- return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(v); \242242-}243243-ATOMIC_LONG_INC_DEC_OP(inc,)244244-ATOMIC_LONG_INC_DEC_OP(inc, _relaxed)245245-ATOMIC_LONG_INC_DEC_OP(inc, _acquire)246246-ATOMIC_LONG_INC_DEC_OP(inc, _release)247247-ATOMIC_LONG_INC_DEC_OP(dec,)248248-ATOMIC_LONG_INC_DEC_OP(dec, _relaxed)249249-ATOMIC_LONG_INC_DEC_OP(dec, _acquire)250250-ATOMIC_LONG_INC_DEC_OP(dec, _release)251251-252252-#undef ATOMIC_LONG_INC_DEC_OP253253-254254-static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)6161+static inline long6262+atomic_long_add_return_acquire(long i, atomic_long_t *v)25563{256256- ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;257257-258258- return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u);6464+ return atomic64_add_return_acquire(i, v);25965}26066261261-#define atomic_long_inc_not_zero(l) \262262- ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))6767+static inline long6868+atomic_long_add_return_release(long i, atomic_long_t *v)6969+{7070+ return atomic64_add_return_release(i, v);7171+}26372264264-#define atomic_long_cond_read_relaxed(v, c) \265265- ATOMIC_LONG_PFX(_cond_read_relaxed)((ATOMIC_LONG_PFX(_t) *)(v), (c))266266-#define atomic_long_cond_read_acquire(v, c) \267267- ATOMIC_LONG_PFX(_cond_read_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (c))7373+static inline long7474+atomic_long_add_return_relaxed(long i, atomic_long_t *v)7575+{7676+ return atomic64_add_return_relaxed(i, v);7777+}26878269269-#endif /* _ASM_GENERIC_ATOMIC_LONG_H */7979+static inline long8080+atomic_long_fetch_add(long i, atomic_long_t *v)8181+{8282+ return atomic64_fetch_add(i, v);8383+}8484+8585+static inline long8686+atomic_long_fetch_add_acquire(long i, atomic_long_t *v)8787+{8888+ return atomic64_fetch_add_acquire(i, v);8989+}9090+9191+static inline long9292+atomic_long_fetch_add_release(long i, atomic_long_t *v)9393+{9494+ return atomic64_fetch_add_release(i, v);9595+}9696+9797+static inline long9898+atomic_long_fetch_add_relaxed(long i, atomic_long_t *v)9999+{100100+ return atomic64_fetch_add_relaxed(i, v);101101+}102102+103103+static inline void104104+atomic_long_sub(long i, atomic_long_t *v)105105+{106106+ atomic64_sub(i, v);107107+}108108+109109+static inline long110110+atomic_long_sub_return(long i, atomic_long_t *v)111111+{112112+ return atomic64_sub_return(i, v);113113+}114114+115115+static inline long116116+atomic_long_sub_return_acquire(long i, atomic_long_t *v)117117+{118118+ return atomic64_sub_return_acquire(i, v);119119+}120120+121121+static inline long122122+atomic_long_sub_return_release(long i, atomic_long_t *v)123123+{124124+ return atomic64_sub_return_release(i, v);125125+}126126+127127+static inline long128128+atomic_long_sub_return_relaxed(long i, atomic_long_t *v)129129+{130130+ return atomic64_sub_return_relaxed(i, v);131131+}132132+133133+static inline long134134+atomic_long_fetch_sub(long i, atomic_long_t *v)135135+{136136+ return atomic64_fetch_sub(i, v);137137+}138138+139139+static inline long140140+atomic_long_fetch_sub_acquire(long i, atomic_long_t *v)141141+{142142+ return atomic64_fetch_sub_acquire(i, v);143143+}144144+145145+static inline long146146+atomic_long_fetch_sub_release(long i, atomic_long_t *v)147147+{148148+ return atomic64_fetch_sub_release(i, v);149149+}150150+151151+static inline long152152+atomic_long_fetch_sub_relaxed(long i, atomic_long_t *v)153153+{154154+ return atomic64_fetch_sub_relaxed(i, v);155155+}156156+157157+static inline void158158+atomic_long_inc(atomic_long_t *v)159159+{160160+ atomic64_inc(v);161161+}162162+163163+static inline long164164+atomic_long_inc_return(atomic_long_t *v)165165+{166166+ return atomic64_inc_return(v);167167+}168168+169169+static inline long170170+atomic_long_inc_return_acquire(atomic_long_t *v)171171+{172172+ return atomic64_inc_return_acquire(v);173173+}174174+175175+static inline long176176+atomic_long_inc_return_release(atomic_long_t *v)177177+{178178+ return atomic64_inc_return_release(v);179179+}180180+181181+static inline long182182+atomic_long_inc_return_relaxed(atomic_long_t *v)183183+{184184+ return atomic64_inc_return_relaxed(v);185185+}186186+187187+static inline long188188+atomic_long_fetch_inc(atomic_long_t *v)189189+{190190+ return atomic64_fetch_inc(v);191191+}192192+193193+static inline long194194+atomic_long_fetch_inc_acquire(atomic_long_t *v)195195+{196196+ return atomic64_fetch_inc_acquire(v);197197+}198198+199199+static inline long200200+atomic_long_fetch_inc_release(atomic_long_t *v)201201+{202202+ return atomic64_fetch_inc_release(v);203203+}204204+205205+static inline long206206+atomic_long_fetch_inc_relaxed(atomic_long_t *v)207207+{208208+ return atomic64_fetch_inc_relaxed(v);209209+}210210+211211+static inline void212212+atomic_long_dec(atomic_long_t *v)213213+{214214+ atomic64_dec(v);215215+}216216+217217+static inline long218218+atomic_long_dec_return(atomic_long_t *v)219219+{220220+ return atomic64_dec_return(v);221221+}222222+223223+static inline long224224+atomic_long_dec_return_acquire(atomic_long_t *v)225225+{226226+ return atomic64_dec_return_acquire(v);227227+}228228+229229+static inline long230230+atomic_long_dec_return_release(atomic_long_t *v)231231+{232232+ return atomic64_dec_return_release(v);233233+}234234+235235+static inline long236236+atomic_long_dec_return_relaxed(atomic_long_t *v)237237+{238238+ return atomic64_dec_return_relaxed(v);239239+}240240+241241+static inline long242242+atomic_long_fetch_dec(atomic_long_t *v)243243+{244244+ return atomic64_fetch_dec(v);245245+}246246+247247+static inline long248248+atomic_long_fetch_dec_acquire(atomic_long_t *v)249249+{250250+ return atomic64_fetch_dec_acquire(v);251251+}252252+253253+static inline long254254+atomic_long_fetch_dec_release(atomic_long_t *v)255255+{256256+ return atomic64_fetch_dec_release(v);257257+}258258+259259+static inline long260260+atomic_long_fetch_dec_relaxed(atomic_long_t *v)261261+{262262+ return atomic64_fetch_dec_relaxed(v);263263+}264264+265265+static inline void266266+atomic_long_and(long i, atomic_long_t *v)267267+{268268+ atomic64_and(i, v);269269+}270270+271271+static inline long272272+atomic_long_fetch_and(long i, atomic_long_t *v)273273+{274274+ return atomic64_fetch_and(i, v);275275+}276276+277277+static inline long278278+atomic_long_fetch_and_acquire(long i, atomic_long_t *v)279279+{280280+ return atomic64_fetch_and_acquire(i, v);281281+}282282+283283+static inline long284284+atomic_long_fetch_and_release(long i, atomic_long_t *v)285285+{286286+ return atomic64_fetch_and_release(i, v);287287+}288288+289289+static inline long290290+atomic_long_fetch_and_relaxed(long i, atomic_long_t *v)291291+{292292+ return atomic64_fetch_and_relaxed(i, v);293293+}294294+295295+static inline void296296+atomic_long_andnot(long i, atomic_long_t *v)297297+{298298+ atomic64_andnot(i, v);299299+}300300+301301+static inline long302302+atomic_long_fetch_andnot(long i, atomic_long_t *v)303303+{304304+ return atomic64_fetch_andnot(i, v);305305+}306306+307307+static inline long308308+atomic_long_fetch_andnot_acquire(long i, atomic_long_t *v)309309+{310310+ return atomic64_fetch_andnot_acquire(i, v);311311+}312312+313313+static inline long314314+atomic_long_fetch_andnot_release(long i, atomic_long_t *v)315315+{316316+ return atomic64_fetch_andnot_release(i, v);317317+}318318+319319+static inline long320320+atomic_long_fetch_andnot_relaxed(long i, atomic_long_t *v)321321+{322322+ return atomic64_fetch_andnot_relaxed(i, v);323323+}324324+325325+static inline void326326+atomic_long_or(long i, atomic_long_t *v)327327+{328328+ atomic64_or(i, v);329329+}330330+331331+static inline long332332+atomic_long_fetch_or(long i, atomic_long_t *v)333333+{334334+ return atomic64_fetch_or(i, v);335335+}336336+337337+static inline long338338+atomic_long_fetch_or_acquire(long i, atomic_long_t *v)339339+{340340+ return atomic64_fetch_or_acquire(i, v);341341+}342342+343343+static inline long344344+atomic_long_fetch_or_release(long i, atomic_long_t *v)345345+{346346+ return atomic64_fetch_or_release(i, v);347347+}348348+349349+static inline long350350+atomic_long_fetch_or_relaxed(long i, atomic_long_t *v)351351+{352352+ return atomic64_fetch_or_relaxed(i, v);353353+}354354+355355+static inline void356356+atomic_long_xor(long i, atomic_long_t *v)357357+{358358+ atomic64_xor(i, v);359359+}360360+361361+static inline long362362+atomic_long_fetch_xor(long i, atomic_long_t *v)363363+{364364+ return atomic64_fetch_xor(i, v);365365+}366366+367367+static inline long368368+atomic_long_fetch_xor_acquire(long i, atomic_long_t *v)369369+{370370+ return atomic64_fetch_xor_acquire(i, v);371371+}372372+373373+static inline long374374+atomic_long_fetch_xor_release(long i, atomic_long_t *v)375375+{376376+ return atomic64_fetch_xor_release(i, v);377377+}378378+379379+static inline long380380+atomic_long_fetch_xor_relaxed(long i, atomic_long_t *v)381381+{382382+ return atomic64_fetch_xor_relaxed(i, v);383383+}384384+385385+static inline long386386+atomic_long_xchg(atomic_long_t *v, long i)387387+{388388+ return atomic64_xchg(v, i);389389+}390390+391391+static inline long392392+atomic_long_xchg_acquire(atomic_long_t *v, long i)393393+{394394+ return atomic64_xchg_acquire(v, i);395395+}396396+397397+static inline long398398+atomic_long_xchg_release(atomic_long_t *v, long i)399399+{400400+ return atomic64_xchg_release(v, i);401401+}402402+403403+static inline long404404+atomic_long_xchg_relaxed(atomic_long_t *v, long i)405405+{406406+ return atomic64_xchg_relaxed(v, i);407407+}408408+409409+static inline long410410+atomic_long_cmpxchg(atomic_long_t *v, long old, long new)411411+{412412+ return atomic64_cmpxchg(v, old, new);413413+}414414+415415+static inline long416416+atomic_long_cmpxchg_acquire(atomic_long_t *v, long old, long new)417417+{418418+ return atomic64_cmpxchg_acquire(v, old, new);419419+}420420+421421+static inline long422422+atomic_long_cmpxchg_release(atomic_long_t *v, long old, long new)423423+{424424+ return atomic64_cmpxchg_release(v, old, new);425425+}426426+427427+static inline long428428+atomic_long_cmpxchg_relaxed(atomic_long_t *v, long old, long new)429429+{430430+ return atomic64_cmpxchg_relaxed(v, old, new);431431+}432432+433433+static inline bool434434+atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)435435+{436436+ return atomic64_try_cmpxchg(v, (s64 *)old, new);437437+}438438+439439+static inline bool440440+atomic_long_try_cmpxchg_acquire(atomic_long_t *v, long *old, long new)441441+{442442+ return atomic64_try_cmpxchg_acquire(v, (s64 *)old, new);443443+}444444+445445+static inline bool446446+atomic_long_try_cmpxchg_release(atomic_long_t *v, long *old, long new)447447+{448448+ return atomic64_try_cmpxchg_release(v, (s64 *)old, new);449449+}450450+451451+static inline bool452452+atomic_long_try_cmpxchg_relaxed(atomic_long_t *v, long *old, long new)453453+{454454+ return atomic64_try_cmpxchg_relaxed(v, (s64 *)old, new);455455+}456456+457457+static inline bool458458+atomic_long_sub_and_test(long i, atomic_long_t *v)459459+{460460+ return atomic64_sub_and_test(i, v);461461+}462462+463463+static inline bool464464+atomic_long_dec_and_test(atomic_long_t *v)465465+{466466+ return atomic64_dec_and_test(v);467467+}468468+469469+static inline bool470470+atomic_long_inc_and_test(atomic_long_t *v)471471+{472472+ return atomic64_inc_and_test(v);473473+}474474+475475+static inline bool476476+atomic_long_add_negative(long i, atomic_long_t *v)477477+{478478+ return atomic64_add_negative(i, v);479479+}480480+481481+static inline long482482+atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)483483+{484484+ return atomic64_fetch_add_unless(v, a, u);485485+}486486+487487+static inline bool488488+atomic_long_add_unless(atomic_long_t *v, long a, long u)489489+{490490+ return atomic64_add_unless(v, a, u);491491+}492492+493493+static inline bool494494+atomic_long_inc_not_zero(atomic_long_t *v)495495+{496496+ return atomic64_inc_not_zero(v);497497+}498498+499499+static inline bool500500+atomic_long_inc_unless_negative(atomic_long_t *v)501501+{502502+ return atomic64_inc_unless_negative(v);503503+}504504+505505+static inline bool506506+atomic_long_dec_unless_positive(atomic_long_t *v)507507+{508508+ return atomic64_dec_unless_positive(v);509509+}510510+511511+static inline long512512+atomic_long_dec_if_positive(atomic_long_t *v)513513+{514514+ return atomic64_dec_if_positive(v);515515+}516516+517517+#else /* CONFIG_64BIT */518518+519519+static inline long520520+atomic_long_read(const atomic_long_t *v)521521+{522522+ return atomic_read(v);523523+}524524+525525+static inline long526526+atomic_long_read_acquire(const atomic_long_t *v)527527+{528528+ return atomic_read_acquire(v);529529+}530530+531531+static inline void532532+atomic_long_set(atomic_long_t *v, long i)533533+{534534+ atomic_set(v, i);535535+}536536+537537+static inline void538538+atomic_long_set_release(atomic_long_t *v, long i)539539+{540540+ atomic_set_release(v, i);541541+}542542+543543+static inline void544544+atomic_long_add(long i, atomic_long_t *v)545545+{546546+ atomic_add(i, v);547547+}548548+549549+static inline long550550+atomic_long_add_return(long i, atomic_long_t *v)551551+{552552+ return atomic_add_return(i, v);553553+}554554+555555+static inline long556556+atomic_long_add_return_acquire(long i, atomic_long_t *v)557557+{558558+ return atomic_add_return_acquire(i, v);559559+}560560+561561+static inline long562562+atomic_long_add_return_release(long i, atomic_long_t *v)563563+{564564+ return atomic_add_return_release(i, v);565565+}566566+567567+static inline long568568+atomic_long_add_return_relaxed(long i, atomic_long_t *v)569569+{570570+ return atomic_add_return_relaxed(i, v);571571+}572572+573573+static inline long574574+atomic_long_fetch_add(long i, atomic_long_t *v)575575+{576576+ return atomic_fetch_add(i, v);577577+}578578+579579+static inline long580580+atomic_long_fetch_add_acquire(long i, atomic_long_t *v)581581+{582582+ return atomic_fetch_add_acquire(i, v);583583+}584584+585585+static inline long586586+atomic_long_fetch_add_release(long i, atomic_long_t *v)587587+{588588+ return atomic_fetch_add_release(i, v);589589+}590590+591591+static inline long592592+atomic_long_fetch_add_relaxed(long i, atomic_long_t *v)593593+{594594+ return atomic_fetch_add_relaxed(i, v);595595+}596596+597597+static inline void598598+atomic_long_sub(long i, atomic_long_t *v)599599+{600600+ atomic_sub(i, v);601601+}602602+603603+static inline long604604+atomic_long_sub_return(long i, atomic_long_t *v)605605+{606606+ return atomic_sub_return(i, v);607607+}608608+609609+static inline long610610+atomic_long_sub_return_acquire(long i, atomic_long_t *v)611611+{612612+ return atomic_sub_return_acquire(i, v);613613+}614614+615615+static inline long616616+atomic_long_sub_return_release(long i, atomic_long_t *v)617617+{618618+ return atomic_sub_return_release(i, v);619619+}620620+621621+static inline long622622+atomic_long_sub_return_relaxed(long i, atomic_long_t *v)623623+{624624+ return atomic_sub_return_relaxed(i, v);625625+}626626+627627+static inline long628628+atomic_long_fetch_sub(long i, atomic_long_t *v)629629+{630630+ return atomic_fetch_sub(i, v);631631+}632632+633633+static inline long634634+atomic_long_fetch_sub_acquire(long i, atomic_long_t *v)635635+{636636+ return atomic_fetch_sub_acquire(i, v);637637+}638638+639639+static inline long640640+atomic_long_fetch_sub_release(long i, atomic_long_t *v)641641+{642642+ return atomic_fetch_sub_release(i, v);643643+}644644+645645+static inline long646646+atomic_long_fetch_sub_relaxed(long i, atomic_long_t *v)647647+{648648+ return atomic_fetch_sub_relaxed(i, v);649649+}650650+651651+static inline void652652+atomic_long_inc(atomic_long_t *v)653653+{654654+ atomic_inc(v);655655+}656656+657657+static inline long658658+atomic_long_inc_return(atomic_long_t *v)659659+{660660+ return atomic_inc_return(v);661661+}662662+663663+static inline long664664+atomic_long_inc_return_acquire(atomic_long_t *v)665665+{666666+ return atomic_inc_return_acquire(v);667667+}668668+669669+static inline long670670+atomic_long_inc_return_release(atomic_long_t *v)671671+{672672+ return atomic_inc_return_release(v);673673+}674674+675675+static inline long676676+atomic_long_inc_return_relaxed(atomic_long_t *v)677677+{678678+ return atomic_inc_return_relaxed(v);679679+}680680+681681+static inline long682682+atomic_long_fetch_inc(atomic_long_t *v)683683+{684684+ return atomic_fetch_inc(v);685685+}686686+687687+static inline long688688+atomic_long_fetch_inc_acquire(atomic_long_t *v)689689+{690690+ return atomic_fetch_inc_acquire(v);691691+}692692+693693+static inline long694694+atomic_long_fetch_inc_release(atomic_long_t *v)695695+{696696+ return atomic_fetch_inc_release(v);697697+}698698+699699+static inline long700700+atomic_long_fetch_inc_relaxed(atomic_long_t *v)701701+{702702+ return atomic_fetch_inc_relaxed(v);703703+}704704+705705+static inline void706706+atomic_long_dec(atomic_long_t *v)707707+{708708+ atomic_dec(v);709709+}710710+711711+static inline long712712+atomic_long_dec_return(atomic_long_t *v)713713+{714714+ return atomic_dec_return(v);715715+}716716+717717+static inline long718718+atomic_long_dec_return_acquire(atomic_long_t *v)719719+{720720+ return atomic_dec_return_acquire(v);721721+}722722+723723+static inline long724724+atomic_long_dec_return_release(atomic_long_t *v)725725+{726726+ return atomic_dec_return_release(v);727727+}728728+729729+static inline long730730+atomic_long_dec_return_relaxed(atomic_long_t *v)731731+{732732+ return atomic_dec_return_relaxed(v);733733+}734734+735735+static inline long736736+atomic_long_fetch_dec(atomic_long_t *v)737737+{738738+ return atomic_fetch_dec(v);739739+}740740+741741+static inline long742742+atomic_long_fetch_dec_acquire(atomic_long_t *v)743743+{744744+ return atomic_fetch_dec_acquire(v);745745+}746746+747747+static inline long748748+atomic_long_fetch_dec_release(atomic_long_t *v)749749+{750750+ return atomic_fetch_dec_release(v);751751+}752752+753753+static inline long754754+atomic_long_fetch_dec_relaxed(atomic_long_t *v)755755+{756756+ return atomic_fetch_dec_relaxed(v);757757+}758758+759759+static inline void760760+atomic_long_and(long i, atomic_long_t *v)761761+{762762+ atomic_and(i, v);763763+}764764+765765+static inline long766766+atomic_long_fetch_and(long i, atomic_long_t *v)767767+{768768+ return atomic_fetch_and(i, v);769769+}770770+771771+static inline long772772+atomic_long_fetch_and_acquire(long i, atomic_long_t *v)773773+{774774+ return atomic_fetch_and_acquire(i, v);775775+}776776+777777+static inline long778778+atomic_long_fetch_and_release(long i, atomic_long_t *v)779779+{780780+ return atomic_fetch_and_release(i, v);781781+}782782+783783+static inline long784784+atomic_long_fetch_and_relaxed(long i, atomic_long_t *v)785785+{786786+ return atomic_fetch_and_relaxed(i, v);787787+}788788+789789+static inline void790790+atomic_long_andnot(long i, atomic_long_t *v)791791+{792792+ atomic_andnot(i, v);793793+}794794+795795+static inline long796796+atomic_long_fetch_andnot(long i, atomic_long_t *v)797797+{798798+ return atomic_fetch_andnot(i, v);799799+}800800+801801+static inline long802802+atomic_long_fetch_andnot_acquire(long i, atomic_long_t *v)803803+{804804+ return atomic_fetch_andnot_acquire(i, v);805805+}806806+807807+static inline long808808+atomic_long_fetch_andnot_release(long i, atomic_long_t *v)809809+{810810+ return atomic_fetch_andnot_release(i, v);811811+}812812+813813+static inline long814814+atomic_long_fetch_andnot_relaxed(long i, atomic_long_t *v)815815+{816816+ return atomic_fetch_andnot_relaxed(i, v);817817+}818818+819819+static inline void820820+atomic_long_or(long i, atomic_long_t *v)821821+{822822+ atomic_or(i, v);823823+}824824+825825+static inline long826826+atomic_long_fetch_or(long i, atomic_long_t *v)827827+{828828+ return atomic_fetch_or(i, v);829829+}830830+831831+static inline long832832+atomic_long_fetch_or_acquire(long i, atomic_long_t *v)833833+{834834+ return atomic_fetch_or_acquire(i, v);835835+}836836+837837+static inline long838838+atomic_long_fetch_or_release(long i, atomic_long_t *v)839839+{840840+ return atomic_fetch_or_release(i, v);841841+}842842+843843+static inline long844844+atomic_long_fetch_or_relaxed(long i, atomic_long_t *v)845845+{846846+ return atomic_fetch_or_relaxed(i, v);847847+}848848+849849+static inline void850850+atomic_long_xor(long i, atomic_long_t *v)851851+{852852+ atomic_xor(i, v);853853+}854854+855855+static inline long856856+atomic_long_fetch_xor(long i, atomic_long_t *v)857857+{858858+ return atomic_fetch_xor(i, v);859859+}860860+861861+static inline long862862+atomic_long_fetch_xor_acquire(long i, atomic_long_t *v)863863+{864864+ return atomic_fetch_xor_acquire(i, v);865865+}866866+867867+static inline long868868+atomic_long_fetch_xor_release(long i, atomic_long_t *v)869869+{870870+ return atomic_fetch_xor_release(i, v);871871+}872872+873873+static inline long874874+atomic_long_fetch_xor_relaxed(long i, atomic_long_t *v)875875+{876876+ return atomic_fetch_xor_relaxed(i, v);877877+}878878+879879+static inline long880880+atomic_long_xchg(atomic_long_t *v, long i)881881+{882882+ return atomic_xchg(v, i);883883+}884884+885885+static inline long886886+atomic_long_xchg_acquire(atomic_long_t *v, long i)887887+{888888+ return atomic_xchg_acquire(v, i);889889+}890890+891891+static inline long892892+atomic_long_xchg_release(atomic_long_t *v, long i)893893+{894894+ return atomic_xchg_release(v, i);895895+}896896+897897+static inline long898898+atomic_long_xchg_relaxed(atomic_long_t *v, long i)899899+{900900+ return atomic_xchg_relaxed(v, i);901901+}902902+903903+static inline long904904+atomic_long_cmpxchg(atomic_long_t *v, long old, long new)905905+{906906+ return atomic_cmpxchg(v, old, new);907907+}908908+909909+static inline long910910+atomic_long_cmpxchg_acquire(atomic_long_t *v, long old, long new)911911+{912912+ return atomic_cmpxchg_acquire(v, old, new);913913+}914914+915915+static inline long916916+atomic_long_cmpxchg_release(atomic_long_t *v, long old, long new)917917+{918918+ return atomic_cmpxchg_release(v, old, new);919919+}920920+921921+static inline long922922+atomic_long_cmpxchg_relaxed(atomic_long_t *v, long old, long new)923923+{924924+ return atomic_cmpxchg_relaxed(v, old, new);925925+}926926+927927+static inline bool928928+atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)929929+{930930+ return atomic_try_cmpxchg(v, (int *)old, new);931931+}932932+933933+static inline bool934934+atomic_long_try_cmpxchg_acquire(atomic_long_t *v, long *old, long new)935935+{936936+ return atomic_try_cmpxchg_acquire(v, (int *)old, new);937937+}938938+939939+static inline bool940940+atomic_long_try_cmpxchg_release(atomic_long_t *v, long *old, long new)941941+{942942+ return atomic_try_cmpxchg_release(v, (int *)old, new);943943+}944944+945945+static inline bool946946+atomic_long_try_cmpxchg_relaxed(atomic_long_t *v, long *old, long new)947947+{948948+ return atomic_try_cmpxchg_relaxed(v, (int *)old, new);949949+}950950+951951+static inline bool952952+atomic_long_sub_and_test(long i, atomic_long_t *v)953953+{954954+ return atomic_sub_and_test(i, v);955955+}956956+957957+static inline bool958958+atomic_long_dec_and_test(atomic_long_t *v)959959+{960960+ return atomic_dec_and_test(v);961961+}962962+963963+static inline bool964964+atomic_long_inc_and_test(atomic_long_t *v)965965+{966966+ return atomic_inc_and_test(v);967967+}968968+969969+static inline bool970970+atomic_long_add_negative(long i, atomic_long_t *v)971971+{972972+ return atomic_add_negative(i, v);973973+}974974+975975+static inline long976976+atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)977977+{978978+ return atomic_fetch_add_unless(v, a, u);979979+}980980+981981+static inline bool982982+atomic_long_add_unless(atomic_long_t *v, long a, long u)983983+{984984+ return atomic_add_unless(v, a, u);985985+}986986+987987+static inline bool988988+atomic_long_inc_not_zero(atomic_long_t *v)989989+{990990+ return atomic_inc_not_zero(v);991991+}992992+993993+static inline bool994994+atomic_long_inc_unless_negative(atomic_long_t *v)995995+{996996+ return atomic_inc_unless_negative(v);997997+}998998+999999+static inline bool10001000+atomic_long_dec_unless_positive(atomic_long_t *v)10011001+{10021002+ return atomic_dec_unless_positive(v);10031003+}10041004+10051005+static inline long10061006+atomic_long_dec_if_positive(atomic_long_t *v)10071007+{10081008+ return atomic_dec_if_positive(v);10091009+}10101010+10111011+#endif /* CONFIG_64BIT */10121012+#endif /* _ASM_GENERIC_ATOMIC_LONG_H */
+2294
include/linux/atomic-fallback.h
···11+// SPDX-License-Identifier: GPL-2.022+33+// Generated by scripts/atomic/gen-atomic-fallback.sh44+// DO NOT MODIFY THIS FILE DIRECTLY55+66+#ifndef _LINUX_ATOMIC_FALLBACK_H77+#define _LINUX_ATOMIC_FALLBACK_H88+99+#ifndef xchg_relaxed1010+#define xchg_relaxed xchg1111+#define xchg_acquire xchg1212+#define xchg_release xchg1313+#else /* xchg_relaxed */1414+1515+#ifndef xchg_acquire1616+#define xchg_acquire(...) \1717+ __atomic_op_acquire(xchg, __VA_ARGS__)1818+#endif1919+2020+#ifndef xchg_release2121+#define xchg_release(...) \2222+ __atomic_op_release(xchg, __VA_ARGS__)2323+#endif2424+2525+#ifndef xchg2626+#define xchg(...) \2727+ __atomic_op_fence(xchg, __VA_ARGS__)2828+#endif2929+3030+#endif /* xchg_relaxed */3131+3232+#ifndef cmpxchg_relaxed3333+#define cmpxchg_relaxed cmpxchg3434+#define cmpxchg_acquire cmpxchg3535+#define cmpxchg_release cmpxchg3636+#else /* cmpxchg_relaxed */3737+3838+#ifndef cmpxchg_acquire3939+#define cmpxchg_acquire(...) \4040+ __atomic_op_acquire(cmpxchg, __VA_ARGS__)4141+#endif4242+4343+#ifndef cmpxchg_release4444+#define cmpxchg_release(...) \4545+ __atomic_op_release(cmpxchg, __VA_ARGS__)4646+#endif4747+4848+#ifndef cmpxchg4949+#define cmpxchg(...) \5050+ __atomic_op_fence(cmpxchg, __VA_ARGS__)5151+#endif5252+5353+#endif /* cmpxchg_relaxed */5454+5555+#ifndef cmpxchg64_relaxed5656+#define cmpxchg64_relaxed cmpxchg645757+#define cmpxchg64_acquire cmpxchg645858+#define cmpxchg64_release cmpxchg645959+#else /* cmpxchg64_relaxed */6060+6161+#ifndef cmpxchg64_acquire6262+#define cmpxchg64_acquire(...) \6363+ __atomic_op_acquire(cmpxchg64, __VA_ARGS__)6464+#endif6565+6666+#ifndef cmpxchg64_release6767+#define cmpxchg64_release(...) \6868+ __atomic_op_release(cmpxchg64, __VA_ARGS__)6969+#endif7070+7171+#ifndef cmpxchg647272+#define cmpxchg64(...) \7373+ __atomic_op_fence(cmpxchg64, __VA_ARGS__)7474+#endif7575+7676+#endif /* cmpxchg64_relaxed */7777+7878+#ifndef atomic_read_acquire7979+static inline int8080+atomic_read_acquire(const atomic_t *v)8181+{8282+ return smp_load_acquire(&(v)->counter);8383+}8484+#define atomic_read_acquire atomic_read_acquire8585+#endif8686+8787+#ifndef atomic_set_release8888+static inline void8989+atomic_set_release(atomic_t *v, int i)9090+{9191+ smp_store_release(&(v)->counter, i);9292+}9393+#define atomic_set_release atomic_set_release9494+#endif9595+9696+#ifndef atomic_add_return_relaxed9797+#define atomic_add_return_acquire atomic_add_return9898+#define atomic_add_return_release atomic_add_return9999+#define atomic_add_return_relaxed atomic_add_return100100+#else /* atomic_add_return_relaxed */101101+102102+#ifndef atomic_add_return_acquire103103+static inline int104104+atomic_add_return_acquire(int i, atomic_t *v)105105+{106106+ int ret = atomic_add_return_relaxed(i, v);107107+ __atomic_acquire_fence();108108+ return ret;109109+}110110+#define atomic_add_return_acquire atomic_add_return_acquire111111+#endif112112+113113+#ifndef atomic_add_return_release114114+static inline int115115+atomic_add_return_release(int i, atomic_t *v)116116+{117117+ __atomic_release_fence();118118+ return atomic_add_return_relaxed(i, v);119119+}120120+#define atomic_add_return_release atomic_add_return_release121121+#endif122122+123123+#ifndef atomic_add_return124124+static inline int125125+atomic_add_return(int i, atomic_t *v)126126+{127127+ int ret;128128+ __atomic_pre_full_fence();129129+ ret = atomic_add_return_relaxed(i, v);130130+ __atomic_post_full_fence();131131+ return ret;132132+}133133+#define atomic_add_return atomic_add_return134134+#endif135135+136136+#endif /* atomic_add_return_relaxed */137137+138138+#ifndef atomic_fetch_add_relaxed139139+#define atomic_fetch_add_acquire atomic_fetch_add140140+#define atomic_fetch_add_release atomic_fetch_add141141+#define atomic_fetch_add_relaxed atomic_fetch_add142142+#else /* atomic_fetch_add_relaxed */143143+144144+#ifndef atomic_fetch_add_acquire145145+static inline int146146+atomic_fetch_add_acquire(int i, atomic_t *v)147147+{148148+ int ret = atomic_fetch_add_relaxed(i, v);149149+ __atomic_acquire_fence();150150+ return ret;151151+}152152+#define atomic_fetch_add_acquire atomic_fetch_add_acquire153153+#endif154154+155155+#ifndef atomic_fetch_add_release156156+static inline int157157+atomic_fetch_add_release(int i, atomic_t *v)158158+{159159+ __atomic_release_fence();160160+ return atomic_fetch_add_relaxed(i, v);161161+}162162+#define atomic_fetch_add_release atomic_fetch_add_release163163+#endif164164+165165+#ifndef atomic_fetch_add166166+static inline int167167+atomic_fetch_add(int i, atomic_t *v)168168+{169169+ int ret;170170+ __atomic_pre_full_fence();171171+ ret = atomic_fetch_add_relaxed(i, v);172172+ __atomic_post_full_fence();173173+ return ret;174174+}175175+#define atomic_fetch_add atomic_fetch_add176176+#endif177177+178178+#endif /* atomic_fetch_add_relaxed */179179+180180+#ifndef atomic_sub_return_relaxed181181+#define atomic_sub_return_acquire atomic_sub_return182182+#define atomic_sub_return_release atomic_sub_return183183+#define atomic_sub_return_relaxed atomic_sub_return184184+#else /* atomic_sub_return_relaxed */185185+186186+#ifndef atomic_sub_return_acquire187187+static inline int188188+atomic_sub_return_acquire(int i, atomic_t *v)189189+{190190+ int ret = atomic_sub_return_relaxed(i, v);191191+ __atomic_acquire_fence();192192+ return ret;193193+}194194+#define atomic_sub_return_acquire atomic_sub_return_acquire195195+#endif196196+197197+#ifndef atomic_sub_return_release198198+static inline int199199+atomic_sub_return_release(int i, atomic_t *v)200200+{201201+ __atomic_release_fence();202202+ return atomic_sub_return_relaxed(i, v);203203+}204204+#define atomic_sub_return_release atomic_sub_return_release205205+#endif206206+207207+#ifndef atomic_sub_return208208+static inline int209209+atomic_sub_return(int i, atomic_t *v)210210+{211211+ int ret;212212+ __atomic_pre_full_fence();213213+ ret = atomic_sub_return_relaxed(i, v);214214+ __atomic_post_full_fence();215215+ return ret;216216+}217217+#define atomic_sub_return atomic_sub_return218218+#endif219219+220220+#endif /* atomic_sub_return_relaxed */221221+222222+#ifndef atomic_fetch_sub_relaxed223223+#define atomic_fetch_sub_acquire atomic_fetch_sub224224+#define atomic_fetch_sub_release atomic_fetch_sub225225+#define atomic_fetch_sub_relaxed atomic_fetch_sub226226+#else /* atomic_fetch_sub_relaxed */227227+228228+#ifndef atomic_fetch_sub_acquire229229+static inline int230230+atomic_fetch_sub_acquire(int i, atomic_t *v)231231+{232232+ int ret = atomic_fetch_sub_relaxed(i, v);233233+ __atomic_acquire_fence();234234+ return ret;235235+}236236+#define atomic_fetch_sub_acquire atomic_fetch_sub_acquire237237+#endif238238+239239+#ifndef atomic_fetch_sub_release240240+static inline int241241+atomic_fetch_sub_release(int i, atomic_t *v)242242+{243243+ __atomic_release_fence();244244+ return atomic_fetch_sub_relaxed(i, v);245245+}246246+#define atomic_fetch_sub_release atomic_fetch_sub_release247247+#endif248248+249249+#ifndef atomic_fetch_sub250250+static inline int251251+atomic_fetch_sub(int i, atomic_t *v)252252+{253253+ int ret;254254+ __atomic_pre_full_fence();255255+ ret = atomic_fetch_sub_relaxed(i, v);256256+ __atomic_post_full_fence();257257+ return ret;258258+}259259+#define atomic_fetch_sub atomic_fetch_sub260260+#endif261261+262262+#endif /* atomic_fetch_sub_relaxed */263263+264264+#ifndef atomic_inc265265+static inline void266266+atomic_inc(atomic_t *v)267267+{268268+ atomic_add(1, v);269269+}270270+#define atomic_inc atomic_inc271271+#endif272272+273273+#ifndef atomic_inc_return_relaxed274274+#ifdef atomic_inc_return275275+#define atomic_inc_return_acquire atomic_inc_return276276+#define atomic_inc_return_release atomic_inc_return277277+#define atomic_inc_return_relaxed atomic_inc_return278278+#endif /* atomic_inc_return */279279+280280+#ifndef atomic_inc_return281281+static inline int282282+atomic_inc_return(atomic_t *v)283283+{284284+ return atomic_add_return(1, v);285285+}286286+#define atomic_inc_return atomic_inc_return287287+#endif288288+289289+#ifndef atomic_inc_return_acquire290290+static inline int291291+atomic_inc_return_acquire(atomic_t *v)292292+{293293+ return atomic_add_return_acquire(1, v);294294+}295295+#define atomic_inc_return_acquire atomic_inc_return_acquire296296+#endif297297+298298+#ifndef atomic_inc_return_release299299+static inline int300300+atomic_inc_return_release(atomic_t *v)301301+{302302+ return atomic_add_return_release(1, v);303303+}304304+#define atomic_inc_return_release atomic_inc_return_release305305+#endif306306+307307+#ifndef atomic_inc_return_relaxed308308+static inline int309309+atomic_inc_return_relaxed(atomic_t *v)310310+{311311+ return atomic_add_return_relaxed(1, v);312312+}313313+#define atomic_inc_return_relaxed atomic_inc_return_relaxed314314+#endif315315+316316+#else /* atomic_inc_return_relaxed */317317+318318+#ifndef atomic_inc_return_acquire319319+static inline int320320+atomic_inc_return_acquire(atomic_t *v)321321+{322322+ int ret = atomic_inc_return_relaxed(v);323323+ __atomic_acquire_fence();324324+ return ret;325325+}326326+#define atomic_inc_return_acquire atomic_inc_return_acquire327327+#endif328328+329329+#ifndef atomic_inc_return_release330330+static inline int331331+atomic_inc_return_release(atomic_t *v)332332+{333333+ __atomic_release_fence();334334+ return atomic_inc_return_relaxed(v);335335+}336336+#define atomic_inc_return_release atomic_inc_return_release337337+#endif338338+339339+#ifndef atomic_inc_return340340+static inline int341341+atomic_inc_return(atomic_t *v)342342+{343343+ int ret;344344+ __atomic_pre_full_fence();345345+ ret = atomic_inc_return_relaxed(v);346346+ __atomic_post_full_fence();347347+ return ret;348348+}349349+#define atomic_inc_return atomic_inc_return350350+#endif351351+352352+#endif /* atomic_inc_return_relaxed */353353+354354+#ifndef atomic_fetch_inc_relaxed355355+#ifdef atomic_fetch_inc356356+#define atomic_fetch_inc_acquire atomic_fetch_inc357357+#define atomic_fetch_inc_release atomic_fetch_inc358358+#define atomic_fetch_inc_relaxed atomic_fetch_inc359359+#endif /* atomic_fetch_inc */360360+361361+#ifndef atomic_fetch_inc362362+static inline int363363+atomic_fetch_inc(atomic_t *v)364364+{365365+ return atomic_fetch_add(1, v);366366+}367367+#define atomic_fetch_inc atomic_fetch_inc368368+#endif369369+370370+#ifndef atomic_fetch_inc_acquire371371+static inline int372372+atomic_fetch_inc_acquire(atomic_t *v)373373+{374374+ return atomic_fetch_add_acquire(1, v);375375+}376376+#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire377377+#endif378378+379379+#ifndef atomic_fetch_inc_release380380+static inline int381381+atomic_fetch_inc_release(atomic_t *v)382382+{383383+ return atomic_fetch_add_release(1, v);384384+}385385+#define atomic_fetch_inc_release atomic_fetch_inc_release386386+#endif387387+388388+#ifndef atomic_fetch_inc_relaxed389389+static inline int390390+atomic_fetch_inc_relaxed(atomic_t *v)391391+{392392+ return atomic_fetch_add_relaxed(1, v);393393+}394394+#define atomic_fetch_inc_relaxed atomic_fetch_inc_relaxed395395+#endif396396+397397+#else /* atomic_fetch_inc_relaxed */398398+399399+#ifndef atomic_fetch_inc_acquire400400+static inline int401401+atomic_fetch_inc_acquire(atomic_t *v)402402+{403403+ int ret = atomic_fetch_inc_relaxed(v);404404+ __atomic_acquire_fence();405405+ return ret;406406+}407407+#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire408408+#endif409409+410410+#ifndef atomic_fetch_inc_release411411+static inline int412412+atomic_fetch_inc_release(atomic_t *v)413413+{414414+ __atomic_release_fence();415415+ return atomic_fetch_inc_relaxed(v);416416+}417417+#define atomic_fetch_inc_release atomic_fetch_inc_release418418+#endif419419+420420+#ifndef atomic_fetch_inc421421+static inline int422422+atomic_fetch_inc(atomic_t *v)423423+{424424+ int ret;425425+ __atomic_pre_full_fence();426426+ ret = atomic_fetch_inc_relaxed(v);427427+ __atomic_post_full_fence();428428+ return ret;429429+}430430+#define atomic_fetch_inc atomic_fetch_inc431431+#endif432432+433433+#endif /* atomic_fetch_inc_relaxed */434434+435435+#ifndef atomic_dec436436+static inline void437437+atomic_dec(atomic_t *v)438438+{439439+ atomic_sub(1, v);440440+}441441+#define atomic_dec atomic_dec442442+#endif443443+444444+#ifndef atomic_dec_return_relaxed445445+#ifdef atomic_dec_return446446+#define atomic_dec_return_acquire atomic_dec_return447447+#define atomic_dec_return_release atomic_dec_return448448+#define atomic_dec_return_relaxed atomic_dec_return449449+#endif /* atomic_dec_return */450450+451451+#ifndef atomic_dec_return452452+static inline int453453+atomic_dec_return(atomic_t *v)454454+{455455+ return atomic_sub_return(1, v);456456+}457457+#define atomic_dec_return atomic_dec_return458458+#endif459459+460460+#ifndef atomic_dec_return_acquire461461+static inline int462462+atomic_dec_return_acquire(atomic_t *v)463463+{464464+ return atomic_sub_return_acquire(1, v);465465+}466466+#define atomic_dec_return_acquire atomic_dec_return_acquire467467+#endif468468+469469+#ifndef atomic_dec_return_release470470+static inline int471471+atomic_dec_return_release(atomic_t *v)472472+{473473+ return atomic_sub_return_release(1, v);474474+}475475+#define atomic_dec_return_release atomic_dec_return_release476476+#endif477477+478478+#ifndef atomic_dec_return_relaxed479479+static inline int480480+atomic_dec_return_relaxed(atomic_t *v)481481+{482482+ return atomic_sub_return_relaxed(1, v);483483+}484484+#define atomic_dec_return_relaxed atomic_dec_return_relaxed485485+#endif486486+487487+#else /* atomic_dec_return_relaxed */488488+489489+#ifndef atomic_dec_return_acquire490490+static inline int491491+atomic_dec_return_acquire(atomic_t *v)492492+{493493+ int ret = atomic_dec_return_relaxed(v);494494+ __atomic_acquire_fence();495495+ return ret;496496+}497497+#define atomic_dec_return_acquire atomic_dec_return_acquire498498+#endif499499+500500+#ifndef atomic_dec_return_release501501+static inline int502502+atomic_dec_return_release(atomic_t *v)503503+{504504+ __atomic_release_fence();505505+ return atomic_dec_return_relaxed(v);506506+}507507+#define atomic_dec_return_release atomic_dec_return_release508508+#endif509509+510510+#ifndef atomic_dec_return511511+static inline int512512+atomic_dec_return(atomic_t *v)513513+{514514+ int ret;515515+ __atomic_pre_full_fence();516516+ ret = atomic_dec_return_relaxed(v);517517+ __atomic_post_full_fence();518518+ return ret;519519+}520520+#define atomic_dec_return atomic_dec_return521521+#endif522522+523523+#endif /* atomic_dec_return_relaxed */524524+525525+#ifndef atomic_fetch_dec_relaxed526526+#ifdef atomic_fetch_dec527527+#define atomic_fetch_dec_acquire atomic_fetch_dec528528+#define atomic_fetch_dec_release atomic_fetch_dec529529+#define atomic_fetch_dec_relaxed atomic_fetch_dec530530+#endif /* atomic_fetch_dec */531531+532532+#ifndef atomic_fetch_dec533533+static inline int534534+atomic_fetch_dec(atomic_t *v)535535+{536536+ return atomic_fetch_sub(1, v);537537+}538538+#define atomic_fetch_dec atomic_fetch_dec539539+#endif540540+541541+#ifndef atomic_fetch_dec_acquire542542+static inline int543543+atomic_fetch_dec_acquire(atomic_t *v)544544+{545545+ return atomic_fetch_sub_acquire(1, v);546546+}547547+#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire548548+#endif549549+550550+#ifndef atomic_fetch_dec_release551551+static inline int552552+atomic_fetch_dec_release(atomic_t *v)553553+{554554+ return atomic_fetch_sub_release(1, v);555555+}556556+#define atomic_fetch_dec_release atomic_fetch_dec_release557557+#endif558558+559559+#ifndef atomic_fetch_dec_relaxed560560+static inline int561561+atomic_fetch_dec_relaxed(atomic_t *v)562562+{563563+ return atomic_fetch_sub_relaxed(1, v);564564+}565565+#define atomic_fetch_dec_relaxed atomic_fetch_dec_relaxed566566+#endif567567+568568+#else /* atomic_fetch_dec_relaxed */569569+570570+#ifndef atomic_fetch_dec_acquire571571+static inline int572572+atomic_fetch_dec_acquire(atomic_t *v)573573+{574574+ int ret = atomic_fetch_dec_relaxed(v);575575+ __atomic_acquire_fence();576576+ return ret;577577+}578578+#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire579579+#endif580580+581581+#ifndef atomic_fetch_dec_release582582+static inline int583583+atomic_fetch_dec_release(atomic_t *v)584584+{585585+ __atomic_release_fence();586586+ return atomic_fetch_dec_relaxed(v);587587+}588588+#define atomic_fetch_dec_release atomic_fetch_dec_release589589+#endif590590+591591+#ifndef atomic_fetch_dec592592+static inline int593593+atomic_fetch_dec(atomic_t *v)594594+{595595+ int ret;596596+ __atomic_pre_full_fence();597597+ ret = atomic_fetch_dec_relaxed(v);598598+ __atomic_post_full_fence();599599+ return ret;600600+}601601+#define atomic_fetch_dec atomic_fetch_dec602602+#endif603603+604604+#endif /* atomic_fetch_dec_relaxed */605605+606606+#ifndef atomic_fetch_and_relaxed607607+#define atomic_fetch_and_acquire atomic_fetch_and608608+#define atomic_fetch_and_release atomic_fetch_and609609+#define atomic_fetch_and_relaxed atomic_fetch_and610610+#else /* atomic_fetch_and_relaxed */611611+612612+#ifndef atomic_fetch_and_acquire613613+static inline int614614+atomic_fetch_and_acquire(int i, atomic_t *v)615615+{616616+ int ret = atomic_fetch_and_relaxed(i, v);617617+ __atomic_acquire_fence();618618+ return ret;619619+}620620+#define atomic_fetch_and_acquire atomic_fetch_and_acquire621621+#endif622622+623623+#ifndef atomic_fetch_and_release624624+static inline int625625+atomic_fetch_and_release(int i, atomic_t *v)626626+{627627+ __atomic_release_fence();628628+ return atomic_fetch_and_relaxed(i, v);629629+}630630+#define atomic_fetch_and_release atomic_fetch_and_release631631+#endif632632+633633+#ifndef atomic_fetch_and634634+static inline int635635+atomic_fetch_and(int i, atomic_t *v)636636+{637637+ int ret;638638+ __atomic_pre_full_fence();639639+ ret = atomic_fetch_and_relaxed(i, v);640640+ __atomic_post_full_fence();641641+ return ret;642642+}643643+#define atomic_fetch_and atomic_fetch_and644644+#endif645645+646646+#endif /* atomic_fetch_and_relaxed */647647+648648+#ifndef atomic_andnot649649+static inline void650650+atomic_andnot(int i, atomic_t *v)651651+{652652+ atomic_and(~i, v);653653+}654654+#define atomic_andnot atomic_andnot655655+#endif656656+657657+#ifndef atomic_fetch_andnot_relaxed658658+#ifdef atomic_fetch_andnot659659+#define atomic_fetch_andnot_acquire atomic_fetch_andnot660660+#define atomic_fetch_andnot_release atomic_fetch_andnot661661+#define atomic_fetch_andnot_relaxed atomic_fetch_andnot662662+#endif /* atomic_fetch_andnot */663663+664664+#ifndef atomic_fetch_andnot665665+static inline int666666+atomic_fetch_andnot(int i, atomic_t *v)667667+{668668+ return atomic_fetch_and(~i, v);669669+}670670+#define atomic_fetch_andnot atomic_fetch_andnot671671+#endif672672+673673+#ifndef atomic_fetch_andnot_acquire674674+static inline int675675+atomic_fetch_andnot_acquire(int i, atomic_t *v)676676+{677677+ return atomic_fetch_and_acquire(~i, v);678678+}679679+#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire680680+#endif681681+682682+#ifndef atomic_fetch_andnot_release683683+static inline int684684+atomic_fetch_andnot_release(int i, atomic_t *v)685685+{686686+ return atomic_fetch_and_release(~i, v);687687+}688688+#define atomic_fetch_andnot_release atomic_fetch_andnot_release689689+#endif690690+691691+#ifndef atomic_fetch_andnot_relaxed692692+static inline int693693+atomic_fetch_andnot_relaxed(int i, atomic_t *v)694694+{695695+ return atomic_fetch_and_relaxed(~i, v);696696+}697697+#define atomic_fetch_andnot_relaxed atomic_fetch_andnot_relaxed698698+#endif699699+700700+#else /* atomic_fetch_andnot_relaxed */701701+702702+#ifndef atomic_fetch_andnot_acquire703703+static inline int704704+atomic_fetch_andnot_acquire(int i, atomic_t *v)705705+{706706+ int ret = atomic_fetch_andnot_relaxed(i, v);707707+ __atomic_acquire_fence();708708+ return ret;709709+}710710+#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire711711+#endif712712+713713+#ifndef atomic_fetch_andnot_release714714+static inline int715715+atomic_fetch_andnot_release(int i, atomic_t *v)716716+{717717+ __atomic_release_fence();718718+ return atomic_fetch_andnot_relaxed(i, v);719719+}720720+#define atomic_fetch_andnot_release atomic_fetch_andnot_release721721+#endif722722+723723+#ifndef atomic_fetch_andnot724724+static inline int725725+atomic_fetch_andnot(int i, atomic_t *v)726726+{727727+ int ret;728728+ __atomic_pre_full_fence();729729+ ret = atomic_fetch_andnot_relaxed(i, v);730730+ __atomic_post_full_fence();731731+ return ret;732732+}733733+#define atomic_fetch_andnot atomic_fetch_andnot734734+#endif735735+736736+#endif /* atomic_fetch_andnot_relaxed */737737+738738+#ifndef atomic_fetch_or_relaxed739739+#define atomic_fetch_or_acquire atomic_fetch_or740740+#define atomic_fetch_or_release atomic_fetch_or741741+#define atomic_fetch_or_relaxed atomic_fetch_or742742+#else /* atomic_fetch_or_relaxed */743743+744744+#ifndef atomic_fetch_or_acquire745745+static inline int746746+atomic_fetch_or_acquire(int i, atomic_t *v)747747+{748748+ int ret = atomic_fetch_or_relaxed(i, v);749749+ __atomic_acquire_fence();750750+ return ret;751751+}752752+#define atomic_fetch_or_acquire atomic_fetch_or_acquire753753+#endif754754+755755+#ifndef atomic_fetch_or_release756756+static inline int757757+atomic_fetch_or_release(int i, atomic_t *v)758758+{759759+ __atomic_release_fence();760760+ return atomic_fetch_or_relaxed(i, v);761761+}762762+#define atomic_fetch_or_release atomic_fetch_or_release763763+#endif764764+765765+#ifndef atomic_fetch_or766766+static inline int767767+atomic_fetch_or(int i, atomic_t *v)768768+{769769+ int ret;770770+ __atomic_pre_full_fence();771771+ ret = atomic_fetch_or_relaxed(i, v);772772+ __atomic_post_full_fence();773773+ return ret;774774+}775775+#define atomic_fetch_or atomic_fetch_or776776+#endif777777+778778+#endif /* atomic_fetch_or_relaxed */779779+780780+#ifndef atomic_fetch_xor_relaxed781781+#define atomic_fetch_xor_acquire atomic_fetch_xor782782+#define atomic_fetch_xor_release atomic_fetch_xor783783+#define atomic_fetch_xor_relaxed atomic_fetch_xor784784+#else /* atomic_fetch_xor_relaxed */785785+786786+#ifndef atomic_fetch_xor_acquire787787+static inline int788788+atomic_fetch_xor_acquire(int i, atomic_t *v)789789+{790790+ int ret = atomic_fetch_xor_relaxed(i, v);791791+ __atomic_acquire_fence();792792+ return ret;793793+}794794+#define atomic_fetch_xor_acquire atomic_fetch_xor_acquire795795+#endif796796+797797+#ifndef atomic_fetch_xor_release798798+static inline int799799+atomic_fetch_xor_release(int i, atomic_t *v)800800+{801801+ __atomic_release_fence();802802+ return atomic_fetch_xor_relaxed(i, v);803803+}804804+#define atomic_fetch_xor_release atomic_fetch_xor_release805805+#endif806806+807807+#ifndef atomic_fetch_xor808808+static inline int809809+atomic_fetch_xor(int i, atomic_t *v)810810+{811811+ int ret;812812+ __atomic_pre_full_fence();813813+ ret = atomic_fetch_xor_relaxed(i, v);814814+ __atomic_post_full_fence();815815+ return ret;816816+}817817+#define atomic_fetch_xor atomic_fetch_xor818818+#endif819819+820820+#endif /* atomic_fetch_xor_relaxed */821821+822822+#ifndef atomic_xchg_relaxed823823+#define atomic_xchg_acquire atomic_xchg824824+#define atomic_xchg_release atomic_xchg825825+#define atomic_xchg_relaxed atomic_xchg826826+#else /* atomic_xchg_relaxed */827827+828828+#ifndef atomic_xchg_acquire829829+static inline int830830+atomic_xchg_acquire(atomic_t *v, int i)831831+{832832+ int ret = atomic_xchg_relaxed(v, i);833833+ __atomic_acquire_fence();834834+ return ret;835835+}836836+#define atomic_xchg_acquire atomic_xchg_acquire837837+#endif838838+839839+#ifndef atomic_xchg_release840840+static inline int841841+atomic_xchg_release(atomic_t *v, int i)842842+{843843+ __atomic_release_fence();844844+ return atomic_xchg_relaxed(v, i);845845+}846846+#define atomic_xchg_release atomic_xchg_release847847+#endif848848+849849+#ifndef atomic_xchg850850+static inline int851851+atomic_xchg(atomic_t *v, int i)852852+{853853+ int ret;854854+ __atomic_pre_full_fence();855855+ ret = atomic_xchg_relaxed(v, i);856856+ __atomic_post_full_fence();857857+ return ret;858858+}859859+#define atomic_xchg atomic_xchg860860+#endif861861+862862+#endif /* atomic_xchg_relaxed */863863+864864+#ifndef atomic_cmpxchg_relaxed865865+#define atomic_cmpxchg_acquire atomic_cmpxchg866866+#define atomic_cmpxchg_release atomic_cmpxchg867867+#define atomic_cmpxchg_relaxed atomic_cmpxchg868868+#else /* atomic_cmpxchg_relaxed */869869+870870+#ifndef atomic_cmpxchg_acquire871871+static inline int872872+atomic_cmpxchg_acquire(atomic_t *v, int old, int new)873873+{874874+ int ret = atomic_cmpxchg_relaxed(v, old, new);875875+ __atomic_acquire_fence();876876+ return ret;877877+}878878+#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire879879+#endif880880+881881+#ifndef atomic_cmpxchg_release882882+static inline int883883+atomic_cmpxchg_release(atomic_t *v, int old, int new)884884+{885885+ __atomic_release_fence();886886+ return atomic_cmpxchg_relaxed(v, old, new);887887+}888888+#define atomic_cmpxchg_release atomic_cmpxchg_release889889+#endif890890+891891+#ifndef atomic_cmpxchg892892+static inline int893893+atomic_cmpxchg(atomic_t *v, int old, int new)894894+{895895+ int ret;896896+ __atomic_pre_full_fence();897897+ ret = atomic_cmpxchg_relaxed(v, old, new);898898+ __atomic_post_full_fence();899899+ return ret;900900+}901901+#define atomic_cmpxchg atomic_cmpxchg902902+#endif903903+904904+#endif /* atomic_cmpxchg_relaxed */905905+906906+#ifndef atomic_try_cmpxchg_relaxed907907+#ifdef atomic_try_cmpxchg908908+#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg909909+#define atomic_try_cmpxchg_release atomic_try_cmpxchg910910+#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg911911+#endif /* atomic_try_cmpxchg */912912+913913+#ifndef atomic_try_cmpxchg914914+static inline bool915915+atomic_try_cmpxchg(atomic_t *v, int *old, int new)916916+{917917+ int r, o = *old;918918+ r = atomic_cmpxchg(v, o, new);919919+ if (unlikely(r != o))920920+ *old = r;921921+ return likely(r == o);922922+}923923+#define atomic_try_cmpxchg atomic_try_cmpxchg924924+#endif925925+926926+#ifndef atomic_try_cmpxchg_acquire927927+static inline bool928928+atomic_try_cmpxchg_acquire(atomic_t *v, int *old, int new)929929+{930930+ int r, o = *old;931931+ r = atomic_cmpxchg_acquire(v, o, new);932932+ if (unlikely(r != o))933933+ *old = r;934934+ return likely(r == o);935935+}936936+#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire937937+#endif938938+939939+#ifndef atomic_try_cmpxchg_release940940+static inline bool941941+atomic_try_cmpxchg_release(atomic_t *v, int *old, int new)942942+{943943+ int r, o = *old;944944+ r = atomic_cmpxchg_release(v, o, new);945945+ if (unlikely(r != o))946946+ *old = r;947947+ return likely(r == o);948948+}949949+#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release950950+#endif951951+952952+#ifndef atomic_try_cmpxchg_relaxed953953+static inline bool954954+atomic_try_cmpxchg_relaxed(atomic_t *v, int *old, int new)955955+{956956+ int r, o = *old;957957+ r = atomic_cmpxchg_relaxed(v, o, new);958958+ if (unlikely(r != o))959959+ *old = r;960960+ return likely(r == o);961961+}962962+#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg_relaxed963963+#endif964964+965965+#else /* atomic_try_cmpxchg_relaxed */966966+967967+#ifndef atomic_try_cmpxchg_acquire968968+static inline bool969969+atomic_try_cmpxchg_acquire(atomic_t *v, int *old, int new)970970+{971971+ bool ret = atomic_try_cmpxchg_relaxed(v, old, new);972972+ __atomic_acquire_fence();973973+ return ret;974974+}975975+#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire976976+#endif977977+978978+#ifndef atomic_try_cmpxchg_release979979+static inline bool980980+atomic_try_cmpxchg_release(atomic_t *v, int *old, int new)981981+{982982+ __atomic_release_fence();983983+ return atomic_try_cmpxchg_relaxed(v, old, new);984984+}985985+#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release986986+#endif987987+988988+#ifndef atomic_try_cmpxchg989989+static inline bool990990+atomic_try_cmpxchg(atomic_t *v, int *old, int new)991991+{992992+ bool ret;993993+ __atomic_pre_full_fence();994994+ ret = atomic_try_cmpxchg_relaxed(v, old, new);995995+ __atomic_post_full_fence();996996+ return ret;997997+}998998+#define atomic_try_cmpxchg atomic_try_cmpxchg999999+#endif10001000+10011001+#endif /* atomic_try_cmpxchg_relaxed */10021002+10031003+#ifndef atomic_sub_and_test10041004+/**10051005+ * atomic_sub_and_test - subtract value from variable and test result10061006+ * @i: integer value to subtract10071007+ * @v: pointer of type atomic_t10081008+ *10091009+ * Atomically subtracts @i from @v and returns10101010+ * true if the result is zero, or false for all10111011+ * other cases.10121012+ */10131013+static inline bool10141014+atomic_sub_and_test(int i, atomic_t *v)10151015+{10161016+ return atomic_sub_return(i, v) == 0;10171017+}10181018+#define atomic_sub_and_test atomic_sub_and_test10191019+#endif10201020+10211021+#ifndef atomic_dec_and_test10221022+/**10231023+ * atomic_dec_and_test - decrement and test10241024+ * @v: pointer of type atomic_t10251025+ *10261026+ * Atomically decrements @v by 1 and10271027+ * returns true if the result is 0, or false for all other10281028+ * cases.10291029+ */10301030+static inline bool10311031+atomic_dec_and_test(atomic_t *v)10321032+{10331033+ return atomic_dec_return(v) == 0;10341034+}10351035+#define atomic_dec_and_test atomic_dec_and_test10361036+#endif10371037+10381038+#ifndef atomic_inc_and_test10391039+/**10401040+ * atomic_inc_and_test - increment and test10411041+ * @v: pointer of type atomic_t10421042+ *10431043+ * Atomically increments @v by 110441044+ * and returns true if the result is zero, or false for all10451045+ * other cases.10461046+ */10471047+static inline bool10481048+atomic_inc_and_test(atomic_t *v)10491049+{10501050+ return atomic_inc_return(v) == 0;10511051+}10521052+#define atomic_inc_and_test atomic_inc_and_test10531053+#endif10541054+10551055+#ifndef atomic_add_negative10561056+/**10571057+ * atomic_add_negative - add and test if negative10581058+ * @i: integer value to add10591059+ * @v: pointer of type atomic_t10601060+ *10611061+ * Atomically adds @i to @v and returns true10621062+ * if the result is negative, or false when10631063+ * result is greater than or equal to zero.10641064+ */10651065+static inline bool10661066+atomic_add_negative(int i, atomic_t *v)10671067+{10681068+ return atomic_add_return(i, v) < 0;10691069+}10701070+#define atomic_add_negative atomic_add_negative10711071+#endif10721072+10731073+#ifndef atomic_fetch_add_unless10741074+/**10751075+ * atomic_fetch_add_unless - add unless the number is already a given value10761076+ * @v: pointer of type atomic_t10771077+ * @a: the amount to add to v...10781078+ * @u: ...unless v is equal to u.10791079+ *10801080+ * Atomically adds @a to @v, so long as @v was not already @u.10811081+ * Returns original value of @v10821082+ */10831083+static inline int10841084+atomic_fetch_add_unless(atomic_t *v, int a, int u)10851085+{10861086+ int c = atomic_read(v);10871087+10881088+ do {10891089+ if (unlikely(c == u))10901090+ break;10911091+ } while (!atomic_try_cmpxchg(v, &c, c + a));10921092+10931093+ return c;10941094+}10951095+#define atomic_fetch_add_unless atomic_fetch_add_unless10961096+#endif10971097+10981098+#ifndef atomic_add_unless10991099+/**11001100+ * atomic_add_unless - add unless the number is already a given value11011101+ * @v: pointer of type atomic_t11021102+ * @a: the amount to add to v...11031103+ * @u: ...unless v is equal to u.11041104+ *11051105+ * Atomically adds @a to @v, if @v was not already @u.11061106+ * Returns true if the addition was done.11071107+ */11081108+static inline bool11091109+atomic_add_unless(atomic_t *v, int a, int u)11101110+{11111111+ return atomic_fetch_add_unless(v, a, u) != u;11121112+}11131113+#define atomic_add_unless atomic_add_unless11141114+#endif11151115+11161116+#ifndef atomic_inc_not_zero11171117+/**11181118+ * atomic_inc_not_zero - increment unless the number is zero11191119+ * @v: pointer of type atomic_t11201120+ *11211121+ * Atomically increments @v by 1, if @v is non-zero.11221122+ * Returns true if the increment was done.11231123+ */11241124+static inline bool11251125+atomic_inc_not_zero(atomic_t *v)11261126+{11271127+ return atomic_add_unless(v, 1, 0);11281128+}11291129+#define atomic_inc_not_zero atomic_inc_not_zero11301130+#endif11311131+11321132+#ifndef atomic_inc_unless_negative11331133+static inline bool11341134+atomic_inc_unless_negative(atomic_t *v)11351135+{11361136+ int c = atomic_read(v);11371137+11381138+ do {11391139+ if (unlikely(c < 0))11401140+ return false;11411141+ } while (!atomic_try_cmpxchg(v, &c, c + 1));11421142+11431143+ return true;11441144+}11451145+#define atomic_inc_unless_negative atomic_inc_unless_negative11461146+#endif11471147+11481148+#ifndef atomic_dec_unless_positive11491149+static inline bool11501150+atomic_dec_unless_positive(atomic_t *v)11511151+{11521152+ int c = atomic_read(v);11531153+11541154+ do {11551155+ if (unlikely(c > 0))11561156+ return false;11571157+ } while (!atomic_try_cmpxchg(v, &c, c - 1));11581158+11591159+ return true;11601160+}11611161+#define atomic_dec_unless_positive atomic_dec_unless_positive11621162+#endif11631163+11641164+#ifndef atomic_dec_if_positive11651165+static inline int11661166+atomic_dec_if_positive(atomic_t *v)11671167+{11681168+ int dec, c = atomic_read(v);11691169+11701170+ do {11711171+ dec = c - 1;11721172+ if (unlikely(dec < 0))11731173+ break;11741174+ } while (!atomic_try_cmpxchg(v, &c, dec));11751175+11761176+ return dec;11771177+}11781178+#define atomic_dec_if_positive atomic_dec_if_positive11791179+#endif11801180+11811181+#define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))11821182+#define atomic_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))11831183+11841184+#ifdef CONFIG_GENERIC_ATOMIC6411851185+#include <asm-generic/atomic64.h>11861186+#endif11871187+11881188+#ifndef atomic64_read_acquire11891189+static inline s6411901190+atomic64_read_acquire(const atomic64_t *v)11911191+{11921192+ return smp_load_acquire(&(v)->counter);11931193+}11941194+#define atomic64_read_acquire atomic64_read_acquire11951195+#endif11961196+11971197+#ifndef atomic64_set_release11981198+static inline void11991199+atomic64_set_release(atomic64_t *v, s64 i)12001200+{12011201+ smp_store_release(&(v)->counter, i);12021202+}12031203+#define atomic64_set_release atomic64_set_release12041204+#endif12051205+12061206+#ifndef atomic64_add_return_relaxed12071207+#define atomic64_add_return_acquire atomic64_add_return12081208+#define atomic64_add_return_release atomic64_add_return12091209+#define atomic64_add_return_relaxed atomic64_add_return12101210+#else /* atomic64_add_return_relaxed */12111211+12121212+#ifndef atomic64_add_return_acquire12131213+static inline s6412141214+atomic64_add_return_acquire(s64 i, atomic64_t *v)12151215+{12161216+ s64 ret = atomic64_add_return_relaxed(i, v);12171217+ __atomic_acquire_fence();12181218+ return ret;12191219+}12201220+#define atomic64_add_return_acquire atomic64_add_return_acquire12211221+#endif12221222+12231223+#ifndef atomic64_add_return_release12241224+static inline s6412251225+atomic64_add_return_release(s64 i, atomic64_t *v)12261226+{12271227+ __atomic_release_fence();12281228+ return atomic64_add_return_relaxed(i, v);12291229+}12301230+#define atomic64_add_return_release atomic64_add_return_release12311231+#endif12321232+12331233+#ifndef atomic64_add_return12341234+static inline s6412351235+atomic64_add_return(s64 i, atomic64_t *v)12361236+{12371237+ s64 ret;12381238+ __atomic_pre_full_fence();12391239+ ret = atomic64_add_return_relaxed(i, v);12401240+ __atomic_post_full_fence();12411241+ return ret;12421242+}12431243+#define atomic64_add_return atomic64_add_return12441244+#endif12451245+12461246+#endif /* atomic64_add_return_relaxed */12471247+12481248+#ifndef atomic64_fetch_add_relaxed12491249+#define atomic64_fetch_add_acquire atomic64_fetch_add12501250+#define atomic64_fetch_add_release atomic64_fetch_add12511251+#define atomic64_fetch_add_relaxed atomic64_fetch_add12521252+#else /* atomic64_fetch_add_relaxed */12531253+12541254+#ifndef atomic64_fetch_add_acquire12551255+static inline s6412561256+atomic64_fetch_add_acquire(s64 i, atomic64_t *v)12571257+{12581258+ s64 ret = atomic64_fetch_add_relaxed(i, v);12591259+ __atomic_acquire_fence();12601260+ return ret;12611261+}12621262+#define atomic64_fetch_add_acquire atomic64_fetch_add_acquire12631263+#endif12641264+12651265+#ifndef atomic64_fetch_add_release12661266+static inline s6412671267+atomic64_fetch_add_release(s64 i, atomic64_t *v)12681268+{12691269+ __atomic_release_fence();12701270+ return atomic64_fetch_add_relaxed(i, v);12711271+}12721272+#define atomic64_fetch_add_release atomic64_fetch_add_release12731273+#endif12741274+12751275+#ifndef atomic64_fetch_add12761276+static inline s6412771277+atomic64_fetch_add(s64 i, atomic64_t *v)12781278+{12791279+ s64 ret;12801280+ __atomic_pre_full_fence();12811281+ ret = atomic64_fetch_add_relaxed(i, v);12821282+ __atomic_post_full_fence();12831283+ return ret;12841284+}12851285+#define atomic64_fetch_add atomic64_fetch_add12861286+#endif12871287+12881288+#endif /* atomic64_fetch_add_relaxed */12891289+12901290+#ifndef atomic64_sub_return_relaxed12911291+#define atomic64_sub_return_acquire atomic64_sub_return12921292+#define atomic64_sub_return_release atomic64_sub_return12931293+#define atomic64_sub_return_relaxed atomic64_sub_return12941294+#else /* atomic64_sub_return_relaxed */12951295+12961296+#ifndef atomic64_sub_return_acquire12971297+static inline s6412981298+atomic64_sub_return_acquire(s64 i, atomic64_t *v)12991299+{13001300+ s64 ret = atomic64_sub_return_relaxed(i, v);13011301+ __atomic_acquire_fence();13021302+ return ret;13031303+}13041304+#define atomic64_sub_return_acquire atomic64_sub_return_acquire13051305+#endif13061306+13071307+#ifndef atomic64_sub_return_release13081308+static inline s6413091309+atomic64_sub_return_release(s64 i, atomic64_t *v)13101310+{13111311+ __atomic_release_fence();13121312+ return atomic64_sub_return_relaxed(i, v);13131313+}13141314+#define atomic64_sub_return_release atomic64_sub_return_release13151315+#endif13161316+13171317+#ifndef atomic64_sub_return13181318+static inline s6413191319+atomic64_sub_return(s64 i, atomic64_t *v)13201320+{13211321+ s64 ret;13221322+ __atomic_pre_full_fence();13231323+ ret = atomic64_sub_return_relaxed(i, v);13241324+ __atomic_post_full_fence();13251325+ return ret;13261326+}13271327+#define atomic64_sub_return atomic64_sub_return13281328+#endif13291329+13301330+#endif /* atomic64_sub_return_relaxed */13311331+13321332+#ifndef atomic64_fetch_sub_relaxed13331333+#define atomic64_fetch_sub_acquire atomic64_fetch_sub13341334+#define atomic64_fetch_sub_release atomic64_fetch_sub13351335+#define atomic64_fetch_sub_relaxed atomic64_fetch_sub13361336+#else /* atomic64_fetch_sub_relaxed */13371337+13381338+#ifndef atomic64_fetch_sub_acquire13391339+static inline s6413401340+atomic64_fetch_sub_acquire(s64 i, atomic64_t *v)13411341+{13421342+ s64 ret = atomic64_fetch_sub_relaxed(i, v);13431343+ __atomic_acquire_fence();13441344+ return ret;13451345+}13461346+#define atomic64_fetch_sub_acquire atomic64_fetch_sub_acquire13471347+#endif13481348+13491349+#ifndef atomic64_fetch_sub_release13501350+static inline s6413511351+atomic64_fetch_sub_release(s64 i, atomic64_t *v)13521352+{13531353+ __atomic_release_fence();13541354+ return atomic64_fetch_sub_relaxed(i, v);13551355+}13561356+#define atomic64_fetch_sub_release atomic64_fetch_sub_release13571357+#endif13581358+13591359+#ifndef atomic64_fetch_sub13601360+static inline s6413611361+atomic64_fetch_sub(s64 i, atomic64_t *v)13621362+{13631363+ s64 ret;13641364+ __atomic_pre_full_fence();13651365+ ret = atomic64_fetch_sub_relaxed(i, v);13661366+ __atomic_post_full_fence();13671367+ return ret;13681368+}13691369+#define atomic64_fetch_sub atomic64_fetch_sub13701370+#endif13711371+13721372+#endif /* atomic64_fetch_sub_relaxed */13731373+13741374+#ifndef atomic64_inc13751375+static inline void13761376+atomic64_inc(atomic64_t *v)13771377+{13781378+ atomic64_add(1, v);13791379+}13801380+#define atomic64_inc atomic64_inc13811381+#endif13821382+13831383+#ifndef atomic64_inc_return_relaxed13841384+#ifdef atomic64_inc_return13851385+#define atomic64_inc_return_acquire atomic64_inc_return13861386+#define atomic64_inc_return_release atomic64_inc_return13871387+#define atomic64_inc_return_relaxed atomic64_inc_return13881388+#endif /* atomic64_inc_return */13891389+13901390+#ifndef atomic64_inc_return13911391+static inline s6413921392+atomic64_inc_return(atomic64_t *v)13931393+{13941394+ return atomic64_add_return(1, v);13951395+}13961396+#define atomic64_inc_return atomic64_inc_return13971397+#endif13981398+13991399+#ifndef atomic64_inc_return_acquire14001400+static inline s6414011401+atomic64_inc_return_acquire(atomic64_t *v)14021402+{14031403+ return atomic64_add_return_acquire(1, v);14041404+}14051405+#define atomic64_inc_return_acquire atomic64_inc_return_acquire14061406+#endif14071407+14081408+#ifndef atomic64_inc_return_release14091409+static inline s6414101410+atomic64_inc_return_release(atomic64_t *v)14111411+{14121412+ return atomic64_add_return_release(1, v);14131413+}14141414+#define atomic64_inc_return_release atomic64_inc_return_release14151415+#endif14161416+14171417+#ifndef atomic64_inc_return_relaxed14181418+static inline s6414191419+atomic64_inc_return_relaxed(atomic64_t *v)14201420+{14211421+ return atomic64_add_return_relaxed(1, v);14221422+}14231423+#define atomic64_inc_return_relaxed atomic64_inc_return_relaxed14241424+#endif14251425+14261426+#else /* atomic64_inc_return_relaxed */14271427+14281428+#ifndef atomic64_inc_return_acquire14291429+static inline s6414301430+atomic64_inc_return_acquire(atomic64_t *v)14311431+{14321432+ s64 ret = atomic64_inc_return_relaxed(v);14331433+ __atomic_acquire_fence();14341434+ return ret;14351435+}14361436+#define atomic64_inc_return_acquire atomic64_inc_return_acquire14371437+#endif14381438+14391439+#ifndef atomic64_inc_return_release14401440+static inline s6414411441+atomic64_inc_return_release(atomic64_t *v)14421442+{14431443+ __atomic_release_fence();14441444+ return atomic64_inc_return_relaxed(v);14451445+}14461446+#define atomic64_inc_return_release atomic64_inc_return_release14471447+#endif14481448+14491449+#ifndef atomic64_inc_return14501450+static inline s6414511451+atomic64_inc_return(atomic64_t *v)14521452+{14531453+ s64 ret;14541454+ __atomic_pre_full_fence();14551455+ ret = atomic64_inc_return_relaxed(v);14561456+ __atomic_post_full_fence();14571457+ return ret;14581458+}14591459+#define atomic64_inc_return atomic64_inc_return14601460+#endif14611461+14621462+#endif /* atomic64_inc_return_relaxed */14631463+14641464+#ifndef atomic64_fetch_inc_relaxed14651465+#ifdef atomic64_fetch_inc14661466+#define atomic64_fetch_inc_acquire atomic64_fetch_inc14671467+#define atomic64_fetch_inc_release atomic64_fetch_inc14681468+#define atomic64_fetch_inc_relaxed atomic64_fetch_inc14691469+#endif /* atomic64_fetch_inc */14701470+14711471+#ifndef atomic64_fetch_inc14721472+static inline s6414731473+atomic64_fetch_inc(atomic64_t *v)14741474+{14751475+ return atomic64_fetch_add(1, v);14761476+}14771477+#define atomic64_fetch_inc atomic64_fetch_inc14781478+#endif14791479+14801480+#ifndef atomic64_fetch_inc_acquire14811481+static inline s6414821482+atomic64_fetch_inc_acquire(atomic64_t *v)14831483+{14841484+ return atomic64_fetch_add_acquire(1, v);14851485+}14861486+#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire14871487+#endif14881488+14891489+#ifndef atomic64_fetch_inc_release14901490+static inline s6414911491+atomic64_fetch_inc_release(atomic64_t *v)14921492+{14931493+ return atomic64_fetch_add_release(1, v);14941494+}14951495+#define atomic64_fetch_inc_release atomic64_fetch_inc_release14961496+#endif14971497+14981498+#ifndef atomic64_fetch_inc_relaxed14991499+static inline s6415001500+atomic64_fetch_inc_relaxed(atomic64_t *v)15011501+{15021502+ return atomic64_fetch_add_relaxed(1, v);15031503+}15041504+#define atomic64_fetch_inc_relaxed atomic64_fetch_inc_relaxed15051505+#endif15061506+15071507+#else /* atomic64_fetch_inc_relaxed */15081508+15091509+#ifndef atomic64_fetch_inc_acquire15101510+static inline s6415111511+atomic64_fetch_inc_acquire(atomic64_t *v)15121512+{15131513+ s64 ret = atomic64_fetch_inc_relaxed(v);15141514+ __atomic_acquire_fence();15151515+ return ret;15161516+}15171517+#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire15181518+#endif15191519+15201520+#ifndef atomic64_fetch_inc_release15211521+static inline s6415221522+atomic64_fetch_inc_release(atomic64_t *v)15231523+{15241524+ __atomic_release_fence();15251525+ return atomic64_fetch_inc_relaxed(v);15261526+}15271527+#define atomic64_fetch_inc_release atomic64_fetch_inc_release15281528+#endif15291529+15301530+#ifndef atomic64_fetch_inc15311531+static inline s6415321532+atomic64_fetch_inc(atomic64_t *v)15331533+{15341534+ s64 ret;15351535+ __atomic_pre_full_fence();15361536+ ret = atomic64_fetch_inc_relaxed(v);15371537+ __atomic_post_full_fence();15381538+ return ret;15391539+}15401540+#define atomic64_fetch_inc atomic64_fetch_inc15411541+#endif15421542+15431543+#endif /* atomic64_fetch_inc_relaxed */15441544+15451545+#ifndef atomic64_dec15461546+static inline void15471547+atomic64_dec(atomic64_t *v)15481548+{15491549+ atomic64_sub(1, v);15501550+}15511551+#define atomic64_dec atomic64_dec15521552+#endif15531553+15541554+#ifndef atomic64_dec_return_relaxed15551555+#ifdef atomic64_dec_return15561556+#define atomic64_dec_return_acquire atomic64_dec_return15571557+#define atomic64_dec_return_release atomic64_dec_return15581558+#define atomic64_dec_return_relaxed atomic64_dec_return15591559+#endif /* atomic64_dec_return */15601560+15611561+#ifndef atomic64_dec_return15621562+static inline s6415631563+atomic64_dec_return(atomic64_t *v)15641564+{15651565+ return atomic64_sub_return(1, v);15661566+}15671567+#define atomic64_dec_return atomic64_dec_return15681568+#endif15691569+15701570+#ifndef atomic64_dec_return_acquire15711571+static inline s6415721572+atomic64_dec_return_acquire(atomic64_t *v)15731573+{15741574+ return atomic64_sub_return_acquire(1, v);15751575+}15761576+#define atomic64_dec_return_acquire atomic64_dec_return_acquire15771577+#endif15781578+15791579+#ifndef atomic64_dec_return_release15801580+static inline s6415811581+atomic64_dec_return_release(atomic64_t *v)15821582+{15831583+ return atomic64_sub_return_release(1, v);15841584+}15851585+#define atomic64_dec_return_release atomic64_dec_return_release15861586+#endif15871587+15881588+#ifndef atomic64_dec_return_relaxed15891589+static inline s6415901590+atomic64_dec_return_relaxed(atomic64_t *v)15911591+{15921592+ return atomic64_sub_return_relaxed(1, v);15931593+}15941594+#define atomic64_dec_return_relaxed atomic64_dec_return_relaxed15951595+#endif15961596+15971597+#else /* atomic64_dec_return_relaxed */15981598+15991599+#ifndef atomic64_dec_return_acquire16001600+static inline s6416011601+atomic64_dec_return_acquire(atomic64_t *v)16021602+{16031603+ s64 ret = atomic64_dec_return_relaxed(v);16041604+ __atomic_acquire_fence();16051605+ return ret;16061606+}16071607+#define atomic64_dec_return_acquire atomic64_dec_return_acquire16081608+#endif16091609+16101610+#ifndef atomic64_dec_return_release16111611+static inline s6416121612+atomic64_dec_return_release(atomic64_t *v)16131613+{16141614+ __atomic_release_fence();16151615+ return atomic64_dec_return_relaxed(v);16161616+}16171617+#define atomic64_dec_return_release atomic64_dec_return_release16181618+#endif16191619+16201620+#ifndef atomic64_dec_return16211621+static inline s6416221622+atomic64_dec_return(atomic64_t *v)16231623+{16241624+ s64 ret;16251625+ __atomic_pre_full_fence();16261626+ ret = atomic64_dec_return_relaxed(v);16271627+ __atomic_post_full_fence();16281628+ return ret;16291629+}16301630+#define atomic64_dec_return atomic64_dec_return16311631+#endif16321632+16331633+#endif /* atomic64_dec_return_relaxed */16341634+16351635+#ifndef atomic64_fetch_dec_relaxed16361636+#ifdef atomic64_fetch_dec16371637+#define atomic64_fetch_dec_acquire atomic64_fetch_dec16381638+#define atomic64_fetch_dec_release atomic64_fetch_dec16391639+#define atomic64_fetch_dec_relaxed atomic64_fetch_dec16401640+#endif /* atomic64_fetch_dec */16411641+16421642+#ifndef atomic64_fetch_dec16431643+static inline s6416441644+atomic64_fetch_dec(atomic64_t *v)16451645+{16461646+ return atomic64_fetch_sub(1, v);16471647+}16481648+#define atomic64_fetch_dec atomic64_fetch_dec16491649+#endif16501650+16511651+#ifndef atomic64_fetch_dec_acquire16521652+static inline s6416531653+atomic64_fetch_dec_acquire(atomic64_t *v)16541654+{16551655+ return atomic64_fetch_sub_acquire(1, v);16561656+}16571657+#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire16581658+#endif16591659+16601660+#ifndef atomic64_fetch_dec_release16611661+static inline s6416621662+atomic64_fetch_dec_release(atomic64_t *v)16631663+{16641664+ return atomic64_fetch_sub_release(1, v);16651665+}16661666+#define atomic64_fetch_dec_release atomic64_fetch_dec_release16671667+#endif16681668+16691669+#ifndef atomic64_fetch_dec_relaxed16701670+static inline s6416711671+atomic64_fetch_dec_relaxed(atomic64_t *v)16721672+{16731673+ return atomic64_fetch_sub_relaxed(1, v);16741674+}16751675+#define atomic64_fetch_dec_relaxed atomic64_fetch_dec_relaxed16761676+#endif16771677+16781678+#else /* atomic64_fetch_dec_relaxed */16791679+16801680+#ifndef atomic64_fetch_dec_acquire16811681+static inline s6416821682+atomic64_fetch_dec_acquire(atomic64_t *v)16831683+{16841684+ s64 ret = atomic64_fetch_dec_relaxed(v);16851685+ __atomic_acquire_fence();16861686+ return ret;16871687+}16881688+#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire16891689+#endif16901690+16911691+#ifndef atomic64_fetch_dec_release16921692+static inline s6416931693+atomic64_fetch_dec_release(atomic64_t *v)16941694+{16951695+ __atomic_release_fence();16961696+ return atomic64_fetch_dec_relaxed(v);16971697+}16981698+#define atomic64_fetch_dec_release atomic64_fetch_dec_release16991699+#endif17001700+17011701+#ifndef atomic64_fetch_dec17021702+static inline s6417031703+atomic64_fetch_dec(atomic64_t *v)17041704+{17051705+ s64 ret;17061706+ __atomic_pre_full_fence();17071707+ ret = atomic64_fetch_dec_relaxed(v);17081708+ __atomic_post_full_fence();17091709+ return ret;17101710+}17111711+#define atomic64_fetch_dec atomic64_fetch_dec17121712+#endif17131713+17141714+#endif /* atomic64_fetch_dec_relaxed */17151715+17161716+#ifndef atomic64_fetch_and_relaxed17171717+#define atomic64_fetch_and_acquire atomic64_fetch_and17181718+#define atomic64_fetch_and_release atomic64_fetch_and17191719+#define atomic64_fetch_and_relaxed atomic64_fetch_and17201720+#else /* atomic64_fetch_and_relaxed */17211721+17221722+#ifndef atomic64_fetch_and_acquire17231723+static inline s6417241724+atomic64_fetch_and_acquire(s64 i, atomic64_t *v)17251725+{17261726+ s64 ret = atomic64_fetch_and_relaxed(i, v);17271727+ __atomic_acquire_fence();17281728+ return ret;17291729+}17301730+#define atomic64_fetch_and_acquire atomic64_fetch_and_acquire17311731+#endif17321732+17331733+#ifndef atomic64_fetch_and_release17341734+static inline s6417351735+atomic64_fetch_and_release(s64 i, atomic64_t *v)17361736+{17371737+ __atomic_release_fence();17381738+ return atomic64_fetch_and_relaxed(i, v);17391739+}17401740+#define atomic64_fetch_and_release atomic64_fetch_and_release17411741+#endif17421742+17431743+#ifndef atomic64_fetch_and17441744+static inline s6417451745+atomic64_fetch_and(s64 i, atomic64_t *v)17461746+{17471747+ s64 ret;17481748+ __atomic_pre_full_fence();17491749+ ret = atomic64_fetch_and_relaxed(i, v);17501750+ __atomic_post_full_fence();17511751+ return ret;17521752+}17531753+#define atomic64_fetch_and atomic64_fetch_and17541754+#endif17551755+17561756+#endif /* atomic64_fetch_and_relaxed */17571757+17581758+#ifndef atomic64_andnot17591759+static inline void17601760+atomic64_andnot(s64 i, atomic64_t *v)17611761+{17621762+ atomic64_and(~i, v);17631763+}17641764+#define atomic64_andnot atomic64_andnot17651765+#endif17661766+17671767+#ifndef atomic64_fetch_andnot_relaxed17681768+#ifdef atomic64_fetch_andnot17691769+#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot17701770+#define atomic64_fetch_andnot_release atomic64_fetch_andnot17711771+#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot17721772+#endif /* atomic64_fetch_andnot */17731773+17741774+#ifndef atomic64_fetch_andnot17751775+static inline s6417761776+atomic64_fetch_andnot(s64 i, atomic64_t *v)17771777+{17781778+ return atomic64_fetch_and(~i, v);17791779+}17801780+#define atomic64_fetch_andnot atomic64_fetch_andnot17811781+#endif17821782+17831783+#ifndef atomic64_fetch_andnot_acquire17841784+static inline s6417851785+atomic64_fetch_andnot_acquire(s64 i, atomic64_t *v)17861786+{17871787+ return atomic64_fetch_and_acquire(~i, v);17881788+}17891789+#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire17901790+#endif17911791+17921792+#ifndef atomic64_fetch_andnot_release17931793+static inline s6417941794+atomic64_fetch_andnot_release(s64 i, atomic64_t *v)17951795+{17961796+ return atomic64_fetch_and_release(~i, v);17971797+}17981798+#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release17991799+#endif18001800+18011801+#ifndef atomic64_fetch_andnot_relaxed18021802+static inline s6418031803+atomic64_fetch_andnot_relaxed(s64 i, atomic64_t *v)18041804+{18051805+ return atomic64_fetch_and_relaxed(~i, v);18061806+}18071807+#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot_relaxed18081808+#endif18091809+18101810+#else /* atomic64_fetch_andnot_relaxed */18111811+18121812+#ifndef atomic64_fetch_andnot_acquire18131813+static inline s6418141814+atomic64_fetch_andnot_acquire(s64 i, atomic64_t *v)18151815+{18161816+ s64 ret = atomic64_fetch_andnot_relaxed(i, v);18171817+ __atomic_acquire_fence();18181818+ return ret;18191819+}18201820+#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire18211821+#endif18221822+18231823+#ifndef atomic64_fetch_andnot_release18241824+static inline s6418251825+atomic64_fetch_andnot_release(s64 i, atomic64_t *v)18261826+{18271827+ __atomic_release_fence();18281828+ return atomic64_fetch_andnot_relaxed(i, v);18291829+}18301830+#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release18311831+#endif18321832+18331833+#ifndef atomic64_fetch_andnot18341834+static inline s6418351835+atomic64_fetch_andnot(s64 i, atomic64_t *v)18361836+{18371837+ s64 ret;18381838+ __atomic_pre_full_fence();18391839+ ret = atomic64_fetch_andnot_relaxed(i, v);18401840+ __atomic_post_full_fence();18411841+ return ret;18421842+}18431843+#define atomic64_fetch_andnot atomic64_fetch_andnot18441844+#endif18451845+18461846+#endif /* atomic64_fetch_andnot_relaxed */18471847+18481848+#ifndef atomic64_fetch_or_relaxed18491849+#define atomic64_fetch_or_acquire atomic64_fetch_or18501850+#define atomic64_fetch_or_release atomic64_fetch_or18511851+#define atomic64_fetch_or_relaxed atomic64_fetch_or18521852+#else /* atomic64_fetch_or_relaxed */18531853+18541854+#ifndef atomic64_fetch_or_acquire18551855+static inline s6418561856+atomic64_fetch_or_acquire(s64 i, atomic64_t *v)18571857+{18581858+ s64 ret = atomic64_fetch_or_relaxed(i, v);18591859+ __atomic_acquire_fence();18601860+ return ret;18611861+}18621862+#define atomic64_fetch_or_acquire atomic64_fetch_or_acquire18631863+#endif18641864+18651865+#ifndef atomic64_fetch_or_release18661866+static inline s6418671867+atomic64_fetch_or_release(s64 i, atomic64_t *v)18681868+{18691869+ __atomic_release_fence();18701870+ return atomic64_fetch_or_relaxed(i, v);18711871+}18721872+#define atomic64_fetch_or_release atomic64_fetch_or_release18731873+#endif18741874+18751875+#ifndef atomic64_fetch_or18761876+static inline s6418771877+atomic64_fetch_or(s64 i, atomic64_t *v)18781878+{18791879+ s64 ret;18801880+ __atomic_pre_full_fence();18811881+ ret = atomic64_fetch_or_relaxed(i, v);18821882+ __atomic_post_full_fence();18831883+ return ret;18841884+}18851885+#define atomic64_fetch_or atomic64_fetch_or18861886+#endif18871887+18881888+#endif /* atomic64_fetch_or_relaxed */18891889+18901890+#ifndef atomic64_fetch_xor_relaxed18911891+#define atomic64_fetch_xor_acquire atomic64_fetch_xor18921892+#define atomic64_fetch_xor_release atomic64_fetch_xor18931893+#define atomic64_fetch_xor_relaxed atomic64_fetch_xor18941894+#else /* atomic64_fetch_xor_relaxed */18951895+18961896+#ifndef atomic64_fetch_xor_acquire18971897+static inline s6418981898+atomic64_fetch_xor_acquire(s64 i, atomic64_t *v)18991899+{19001900+ s64 ret = atomic64_fetch_xor_relaxed(i, v);19011901+ __atomic_acquire_fence();19021902+ return ret;19031903+}19041904+#define atomic64_fetch_xor_acquire atomic64_fetch_xor_acquire19051905+#endif19061906+19071907+#ifndef atomic64_fetch_xor_release19081908+static inline s6419091909+atomic64_fetch_xor_release(s64 i, atomic64_t *v)19101910+{19111911+ __atomic_release_fence();19121912+ return atomic64_fetch_xor_relaxed(i, v);19131913+}19141914+#define atomic64_fetch_xor_release atomic64_fetch_xor_release19151915+#endif19161916+19171917+#ifndef atomic64_fetch_xor19181918+static inline s6419191919+atomic64_fetch_xor(s64 i, atomic64_t *v)19201920+{19211921+ s64 ret;19221922+ __atomic_pre_full_fence();19231923+ ret = atomic64_fetch_xor_relaxed(i, v);19241924+ __atomic_post_full_fence();19251925+ return ret;19261926+}19271927+#define atomic64_fetch_xor atomic64_fetch_xor19281928+#endif19291929+19301930+#endif /* atomic64_fetch_xor_relaxed */19311931+19321932+#ifndef atomic64_xchg_relaxed19331933+#define atomic64_xchg_acquire atomic64_xchg19341934+#define atomic64_xchg_release atomic64_xchg19351935+#define atomic64_xchg_relaxed atomic64_xchg19361936+#else /* atomic64_xchg_relaxed */19371937+19381938+#ifndef atomic64_xchg_acquire19391939+static inline s6419401940+atomic64_xchg_acquire(atomic64_t *v, s64 i)19411941+{19421942+ s64 ret = atomic64_xchg_relaxed(v, i);19431943+ __atomic_acquire_fence();19441944+ return ret;19451945+}19461946+#define atomic64_xchg_acquire atomic64_xchg_acquire19471947+#endif19481948+19491949+#ifndef atomic64_xchg_release19501950+static inline s6419511951+atomic64_xchg_release(atomic64_t *v, s64 i)19521952+{19531953+ __atomic_release_fence();19541954+ return atomic64_xchg_relaxed(v, i);19551955+}19561956+#define atomic64_xchg_release atomic64_xchg_release19571957+#endif19581958+19591959+#ifndef atomic64_xchg19601960+static inline s6419611961+atomic64_xchg(atomic64_t *v, s64 i)19621962+{19631963+ s64 ret;19641964+ __atomic_pre_full_fence();19651965+ ret = atomic64_xchg_relaxed(v, i);19661966+ __atomic_post_full_fence();19671967+ return ret;19681968+}19691969+#define atomic64_xchg atomic64_xchg19701970+#endif19711971+19721972+#endif /* atomic64_xchg_relaxed */19731973+19741974+#ifndef atomic64_cmpxchg_relaxed19751975+#define atomic64_cmpxchg_acquire atomic64_cmpxchg19761976+#define atomic64_cmpxchg_release atomic64_cmpxchg19771977+#define atomic64_cmpxchg_relaxed atomic64_cmpxchg19781978+#else /* atomic64_cmpxchg_relaxed */19791979+19801980+#ifndef atomic64_cmpxchg_acquire19811981+static inline s6419821982+atomic64_cmpxchg_acquire(atomic64_t *v, s64 old, s64 new)19831983+{19841984+ s64 ret = atomic64_cmpxchg_relaxed(v, old, new);19851985+ __atomic_acquire_fence();19861986+ return ret;19871987+}19881988+#define atomic64_cmpxchg_acquire atomic64_cmpxchg_acquire19891989+#endif19901990+19911991+#ifndef atomic64_cmpxchg_release19921992+static inline s6419931993+atomic64_cmpxchg_release(atomic64_t *v, s64 old, s64 new)19941994+{19951995+ __atomic_release_fence();19961996+ return atomic64_cmpxchg_relaxed(v, old, new);19971997+}19981998+#define atomic64_cmpxchg_release atomic64_cmpxchg_release19991999+#endif20002000+20012001+#ifndef atomic64_cmpxchg20022002+static inline s6420032003+atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new)20042004+{20052005+ s64 ret;20062006+ __atomic_pre_full_fence();20072007+ ret = atomic64_cmpxchg_relaxed(v, old, new);20082008+ __atomic_post_full_fence();20092009+ return ret;20102010+}20112011+#define atomic64_cmpxchg atomic64_cmpxchg20122012+#endif20132013+20142014+#endif /* atomic64_cmpxchg_relaxed */20152015+20162016+#ifndef atomic64_try_cmpxchg_relaxed20172017+#ifdef atomic64_try_cmpxchg20182018+#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg20192019+#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg20202020+#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg20212021+#endif /* atomic64_try_cmpxchg */20222022+20232023+#ifndef atomic64_try_cmpxchg20242024+static inline bool20252025+atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new)20262026+{20272027+ s64 r, o = *old;20282028+ r = atomic64_cmpxchg(v, o, new);20292029+ if (unlikely(r != o))20302030+ *old = r;20312031+ return likely(r == o);20322032+}20332033+#define atomic64_try_cmpxchg atomic64_try_cmpxchg20342034+#endif20352035+20362036+#ifndef atomic64_try_cmpxchg_acquire20372037+static inline bool20382038+atomic64_try_cmpxchg_acquire(atomic64_t *v, s64 *old, s64 new)20392039+{20402040+ s64 r, o = *old;20412041+ r = atomic64_cmpxchg_acquire(v, o, new);20422042+ if (unlikely(r != o))20432043+ *old = r;20442044+ return likely(r == o);20452045+}20462046+#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire20472047+#endif20482048+20492049+#ifndef atomic64_try_cmpxchg_release20502050+static inline bool20512051+atomic64_try_cmpxchg_release(atomic64_t *v, s64 *old, s64 new)20522052+{20532053+ s64 r, o = *old;20542054+ r = atomic64_cmpxchg_release(v, o, new);20552055+ if (unlikely(r != o))20562056+ *old = r;20572057+ return likely(r == o);20582058+}20592059+#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release20602060+#endif20612061+20622062+#ifndef atomic64_try_cmpxchg_relaxed20632063+static inline bool20642064+atomic64_try_cmpxchg_relaxed(atomic64_t *v, s64 *old, s64 new)20652065+{20662066+ s64 r, o = *old;20672067+ r = atomic64_cmpxchg_relaxed(v, o, new);20682068+ if (unlikely(r != o))20692069+ *old = r;20702070+ return likely(r == o);20712071+}20722072+#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg_relaxed20732073+#endif20742074+20752075+#else /* atomic64_try_cmpxchg_relaxed */20762076+20772077+#ifndef atomic64_try_cmpxchg_acquire20782078+static inline bool20792079+atomic64_try_cmpxchg_acquire(atomic64_t *v, s64 *old, s64 new)20802080+{20812081+ bool ret = atomic64_try_cmpxchg_relaxed(v, old, new);20822082+ __atomic_acquire_fence();20832083+ return ret;20842084+}20852085+#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire20862086+#endif20872087+20882088+#ifndef atomic64_try_cmpxchg_release20892089+static inline bool20902090+atomic64_try_cmpxchg_release(atomic64_t *v, s64 *old, s64 new)20912091+{20922092+ __atomic_release_fence();20932093+ return atomic64_try_cmpxchg_relaxed(v, old, new);20942094+}20952095+#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release20962096+#endif20972097+20982098+#ifndef atomic64_try_cmpxchg20992099+static inline bool21002100+atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new)21012101+{21022102+ bool ret;21032103+ __atomic_pre_full_fence();21042104+ ret = atomic64_try_cmpxchg_relaxed(v, old, new);21052105+ __atomic_post_full_fence();21062106+ return ret;21072107+}21082108+#define atomic64_try_cmpxchg atomic64_try_cmpxchg21092109+#endif21102110+21112111+#endif /* atomic64_try_cmpxchg_relaxed */21122112+21132113+#ifndef atomic64_sub_and_test21142114+/**21152115+ * atomic64_sub_and_test - subtract value from variable and test result21162116+ * @i: integer value to subtract21172117+ * @v: pointer of type atomic64_t21182118+ *21192119+ * Atomically subtracts @i from @v and returns21202120+ * true if the result is zero, or false for all21212121+ * other cases.21222122+ */21232123+static inline bool21242124+atomic64_sub_and_test(s64 i, atomic64_t *v)21252125+{21262126+ return atomic64_sub_return(i, v) == 0;21272127+}21282128+#define atomic64_sub_and_test atomic64_sub_and_test21292129+#endif21302130+21312131+#ifndef atomic64_dec_and_test21322132+/**21332133+ * atomic64_dec_and_test - decrement and test21342134+ * @v: pointer of type atomic64_t21352135+ *21362136+ * Atomically decrements @v by 1 and21372137+ * returns true if the result is 0, or false for all other21382138+ * cases.21392139+ */21402140+static inline bool21412141+atomic64_dec_and_test(atomic64_t *v)21422142+{21432143+ return atomic64_dec_return(v) == 0;21442144+}21452145+#define atomic64_dec_and_test atomic64_dec_and_test21462146+#endif21472147+21482148+#ifndef atomic64_inc_and_test21492149+/**21502150+ * atomic64_inc_and_test - increment and test21512151+ * @v: pointer of type atomic64_t21522152+ *21532153+ * Atomically increments @v by 121542154+ * and returns true if the result is zero, or false for all21552155+ * other cases.21562156+ */21572157+static inline bool21582158+atomic64_inc_and_test(atomic64_t *v)21592159+{21602160+ return atomic64_inc_return(v) == 0;21612161+}21622162+#define atomic64_inc_and_test atomic64_inc_and_test21632163+#endif21642164+21652165+#ifndef atomic64_add_negative21662166+/**21672167+ * atomic64_add_negative - add and test if negative21682168+ * @i: integer value to add21692169+ * @v: pointer of type atomic64_t21702170+ *21712171+ * Atomically adds @i to @v and returns true21722172+ * if the result is negative, or false when21732173+ * result is greater than or equal to zero.21742174+ */21752175+static inline bool21762176+atomic64_add_negative(s64 i, atomic64_t *v)21772177+{21782178+ return atomic64_add_return(i, v) < 0;21792179+}21802180+#define atomic64_add_negative atomic64_add_negative21812181+#endif21822182+21832183+#ifndef atomic64_fetch_add_unless21842184+/**21852185+ * atomic64_fetch_add_unless - add unless the number is already a given value21862186+ * @v: pointer of type atomic64_t21872187+ * @a: the amount to add to v...21882188+ * @u: ...unless v is equal to u.21892189+ *21902190+ * Atomically adds @a to @v, so long as @v was not already @u.21912191+ * Returns original value of @v21922192+ */21932193+static inline s6421942194+atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u)21952195+{21962196+ s64 c = atomic64_read(v);21972197+21982198+ do {21992199+ if (unlikely(c == u))22002200+ break;22012201+ } while (!atomic64_try_cmpxchg(v, &c, c + a));22022202+22032203+ return c;22042204+}22052205+#define atomic64_fetch_add_unless atomic64_fetch_add_unless22062206+#endif22072207+22082208+#ifndef atomic64_add_unless22092209+/**22102210+ * atomic64_add_unless - add unless the number is already a given value22112211+ * @v: pointer of type atomic64_t22122212+ * @a: the amount to add to v...22132213+ * @u: ...unless v is equal to u.22142214+ *22152215+ * Atomically adds @a to @v, if @v was not already @u.22162216+ * Returns true if the addition was done.22172217+ */22182218+static inline bool22192219+atomic64_add_unless(atomic64_t *v, s64 a, s64 u)22202220+{22212221+ return atomic64_fetch_add_unless(v, a, u) != u;22222222+}22232223+#define atomic64_add_unless atomic64_add_unless22242224+#endif22252225+22262226+#ifndef atomic64_inc_not_zero22272227+/**22282228+ * atomic64_inc_not_zero - increment unless the number is zero22292229+ * @v: pointer of type atomic64_t22302230+ *22312231+ * Atomically increments @v by 1, if @v is non-zero.22322232+ * Returns true if the increment was done.22332233+ */22342234+static inline bool22352235+atomic64_inc_not_zero(atomic64_t *v)22362236+{22372237+ return atomic64_add_unless(v, 1, 0);22382238+}22392239+#define atomic64_inc_not_zero atomic64_inc_not_zero22402240+#endif22412241+22422242+#ifndef atomic64_inc_unless_negative22432243+static inline bool22442244+atomic64_inc_unless_negative(atomic64_t *v)22452245+{22462246+ s64 c = atomic64_read(v);22472247+22482248+ do {22492249+ if (unlikely(c < 0))22502250+ return false;22512251+ } while (!atomic64_try_cmpxchg(v, &c, c + 1));22522252+22532253+ return true;22542254+}22552255+#define atomic64_inc_unless_negative atomic64_inc_unless_negative22562256+#endif22572257+22582258+#ifndef atomic64_dec_unless_positive22592259+static inline bool22602260+atomic64_dec_unless_positive(atomic64_t *v)22612261+{22622262+ s64 c = atomic64_read(v);22632263+22642264+ do {22652265+ if (unlikely(c > 0))22662266+ return false;22672267+ } while (!atomic64_try_cmpxchg(v, &c, c - 1));22682268+22692269+ return true;22702270+}22712271+#define atomic64_dec_unless_positive atomic64_dec_unless_positive22722272+#endif22732273+22742274+#ifndef atomic64_dec_if_positive22752275+static inline s6422762276+atomic64_dec_if_positive(atomic64_t *v)22772277+{22782278+ s64 dec, c = atomic64_read(v);22792279+22802280+ do {22812281+ dec = c - 1;22822282+ if (unlikely(dec < 0))22832283+ break;22842284+ } while (!atomic64_try_cmpxchg(v, &c, dec));22852285+22862286+ return dec;22872287+}22882288+#define atomic64_dec_if_positive atomic64_dec_if_positive22892289+#endif22902290+22912291+#define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))22922292+#define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))22932293+22942294+#endif /* _LINUX_ATOMIC_FALLBACK_H */
+1-1240
include/linux/atomic.h
···2525 * See Documentation/memory-barriers.txt for ACQUIRE/RELEASE definitions.2626 */27272828-#ifndef atomic_read_acquire2929-#define atomic_read_acquire(v) smp_load_acquire(&(v)->counter)3030-#endif3131-3232-#ifndef atomic_set_release3333-#define atomic_set_release(v, i) smp_store_release(&(v)->counter, (i))3434-#endif3535-3628/*3729 * The idea here is to build acquire/release variants by adding explicit3830 * barriers on top of the relaxed variant. In the case where the relaxed···7179 __ret; \7280})73817474-/* atomic_add_return_relaxed */7575-#ifndef atomic_add_return_relaxed7676-#define atomic_add_return_relaxed atomic_add_return7777-#define atomic_add_return_acquire atomic_add_return7878-#define atomic_add_return_release atomic_add_return7979-8080-#else /* atomic_add_return_relaxed */8181-8282-#ifndef atomic_add_return_acquire8383-#define atomic_add_return_acquire(...) \8484- __atomic_op_acquire(atomic_add_return, __VA_ARGS__)8585-#endif8686-8787-#ifndef atomic_add_return_release8888-#define atomic_add_return_release(...) \8989- __atomic_op_release(atomic_add_return, __VA_ARGS__)9090-#endif9191-9292-#ifndef atomic_add_return9393-#define atomic_add_return(...) \9494- __atomic_op_fence(atomic_add_return, __VA_ARGS__)9595-#endif9696-#endif /* atomic_add_return_relaxed */9797-9898-#ifndef atomic_inc9999-#define atomic_inc(v) atomic_add(1, (v))100100-#endif101101-102102-/* atomic_inc_return_relaxed */103103-#ifndef atomic_inc_return_relaxed104104-105105-#ifndef atomic_inc_return106106-#define atomic_inc_return(v) atomic_add_return(1, (v))107107-#define atomic_inc_return_relaxed(v) atomic_add_return_relaxed(1, (v))108108-#define atomic_inc_return_acquire(v) atomic_add_return_acquire(1, (v))109109-#define atomic_inc_return_release(v) atomic_add_return_release(1, (v))110110-#else /* atomic_inc_return */111111-#define atomic_inc_return_relaxed atomic_inc_return112112-#define atomic_inc_return_acquire atomic_inc_return113113-#define atomic_inc_return_release atomic_inc_return114114-#endif /* atomic_inc_return */115115-116116-#else /* atomic_inc_return_relaxed */117117-118118-#ifndef atomic_inc_return_acquire119119-#define atomic_inc_return_acquire(...) \120120- __atomic_op_acquire(atomic_inc_return, __VA_ARGS__)121121-#endif122122-123123-#ifndef atomic_inc_return_release124124-#define atomic_inc_return_release(...) \125125- __atomic_op_release(atomic_inc_return, __VA_ARGS__)126126-#endif127127-128128-#ifndef atomic_inc_return129129-#define atomic_inc_return(...) \130130- __atomic_op_fence(atomic_inc_return, __VA_ARGS__)131131-#endif132132-#endif /* atomic_inc_return_relaxed */133133-134134-/* atomic_sub_return_relaxed */135135-#ifndef atomic_sub_return_relaxed136136-#define atomic_sub_return_relaxed atomic_sub_return137137-#define atomic_sub_return_acquire atomic_sub_return138138-#define atomic_sub_return_release atomic_sub_return139139-140140-#else /* atomic_sub_return_relaxed */141141-142142-#ifndef atomic_sub_return_acquire143143-#define atomic_sub_return_acquire(...) \144144- __atomic_op_acquire(atomic_sub_return, __VA_ARGS__)145145-#endif146146-147147-#ifndef atomic_sub_return_release148148-#define atomic_sub_return_release(...) \149149- __atomic_op_release(atomic_sub_return, __VA_ARGS__)150150-#endif151151-152152-#ifndef atomic_sub_return153153-#define atomic_sub_return(...) \154154- __atomic_op_fence(atomic_sub_return, __VA_ARGS__)155155-#endif156156-#endif /* atomic_sub_return_relaxed */157157-158158-#ifndef atomic_dec159159-#define atomic_dec(v) atomic_sub(1, (v))160160-#endif161161-162162-/* atomic_dec_return_relaxed */163163-#ifndef atomic_dec_return_relaxed164164-165165-#ifndef atomic_dec_return166166-#define atomic_dec_return(v) atomic_sub_return(1, (v))167167-#define atomic_dec_return_relaxed(v) atomic_sub_return_relaxed(1, (v))168168-#define atomic_dec_return_acquire(v) atomic_sub_return_acquire(1, (v))169169-#define atomic_dec_return_release(v) atomic_sub_return_release(1, (v))170170-#else /* atomic_dec_return */171171-#define atomic_dec_return_relaxed atomic_dec_return172172-#define atomic_dec_return_acquire atomic_dec_return173173-#define atomic_dec_return_release atomic_dec_return174174-#endif /* atomic_dec_return */175175-176176-#else /* atomic_dec_return_relaxed */177177-178178-#ifndef atomic_dec_return_acquire179179-#define atomic_dec_return_acquire(...) \180180- __atomic_op_acquire(atomic_dec_return, __VA_ARGS__)181181-#endif182182-183183-#ifndef atomic_dec_return_release184184-#define atomic_dec_return_release(...) \185185- __atomic_op_release(atomic_dec_return, __VA_ARGS__)186186-#endif187187-188188-#ifndef atomic_dec_return189189-#define atomic_dec_return(...) \190190- __atomic_op_fence(atomic_dec_return, __VA_ARGS__)191191-#endif192192-#endif /* atomic_dec_return_relaxed */193193-194194-195195-/* atomic_fetch_add_relaxed */196196-#ifndef atomic_fetch_add_relaxed197197-#define atomic_fetch_add_relaxed atomic_fetch_add198198-#define atomic_fetch_add_acquire atomic_fetch_add199199-#define atomic_fetch_add_release atomic_fetch_add200200-201201-#else /* atomic_fetch_add_relaxed */202202-203203-#ifndef atomic_fetch_add_acquire204204-#define atomic_fetch_add_acquire(...) \205205- __atomic_op_acquire(atomic_fetch_add, __VA_ARGS__)206206-#endif207207-208208-#ifndef atomic_fetch_add_release209209-#define atomic_fetch_add_release(...) \210210- __atomic_op_release(atomic_fetch_add, __VA_ARGS__)211211-#endif212212-213213-#ifndef atomic_fetch_add214214-#define atomic_fetch_add(...) \215215- __atomic_op_fence(atomic_fetch_add, __VA_ARGS__)216216-#endif217217-#endif /* atomic_fetch_add_relaxed */218218-219219-/* atomic_fetch_inc_relaxed */220220-#ifndef atomic_fetch_inc_relaxed221221-222222-#ifndef atomic_fetch_inc223223-#define atomic_fetch_inc(v) atomic_fetch_add(1, (v))224224-#define atomic_fetch_inc_relaxed(v) atomic_fetch_add_relaxed(1, (v))225225-#define atomic_fetch_inc_acquire(v) atomic_fetch_add_acquire(1, (v))226226-#define atomic_fetch_inc_release(v) atomic_fetch_add_release(1, (v))227227-#else /* atomic_fetch_inc */228228-#define atomic_fetch_inc_relaxed atomic_fetch_inc229229-#define atomic_fetch_inc_acquire atomic_fetch_inc230230-#define atomic_fetch_inc_release atomic_fetch_inc231231-#endif /* atomic_fetch_inc */232232-233233-#else /* atomic_fetch_inc_relaxed */234234-235235-#ifndef atomic_fetch_inc_acquire236236-#define atomic_fetch_inc_acquire(...) \237237- __atomic_op_acquire(atomic_fetch_inc, __VA_ARGS__)238238-#endif239239-240240-#ifndef atomic_fetch_inc_release241241-#define atomic_fetch_inc_release(...) \242242- __atomic_op_release(atomic_fetch_inc, __VA_ARGS__)243243-#endif244244-245245-#ifndef atomic_fetch_inc246246-#define atomic_fetch_inc(...) \247247- __atomic_op_fence(atomic_fetch_inc, __VA_ARGS__)248248-#endif249249-#endif /* atomic_fetch_inc_relaxed */250250-251251-/* atomic_fetch_sub_relaxed */252252-#ifndef atomic_fetch_sub_relaxed253253-#define atomic_fetch_sub_relaxed atomic_fetch_sub254254-#define atomic_fetch_sub_acquire atomic_fetch_sub255255-#define atomic_fetch_sub_release atomic_fetch_sub256256-257257-#else /* atomic_fetch_sub_relaxed */258258-259259-#ifndef atomic_fetch_sub_acquire260260-#define atomic_fetch_sub_acquire(...) \261261- __atomic_op_acquire(atomic_fetch_sub, __VA_ARGS__)262262-#endif263263-264264-#ifndef atomic_fetch_sub_release265265-#define atomic_fetch_sub_release(...) \266266- __atomic_op_release(atomic_fetch_sub, __VA_ARGS__)267267-#endif268268-269269-#ifndef atomic_fetch_sub270270-#define atomic_fetch_sub(...) \271271- __atomic_op_fence(atomic_fetch_sub, __VA_ARGS__)272272-#endif273273-#endif /* atomic_fetch_sub_relaxed */274274-275275-/* atomic_fetch_dec_relaxed */276276-#ifndef atomic_fetch_dec_relaxed277277-278278-#ifndef atomic_fetch_dec279279-#define atomic_fetch_dec(v) atomic_fetch_sub(1, (v))280280-#define atomic_fetch_dec_relaxed(v) atomic_fetch_sub_relaxed(1, (v))281281-#define atomic_fetch_dec_acquire(v) atomic_fetch_sub_acquire(1, (v))282282-#define atomic_fetch_dec_release(v) atomic_fetch_sub_release(1, (v))283283-#else /* atomic_fetch_dec */284284-#define atomic_fetch_dec_relaxed atomic_fetch_dec285285-#define atomic_fetch_dec_acquire atomic_fetch_dec286286-#define atomic_fetch_dec_release atomic_fetch_dec287287-#endif /* atomic_fetch_dec */288288-289289-#else /* atomic_fetch_dec_relaxed */290290-291291-#ifndef atomic_fetch_dec_acquire292292-#define atomic_fetch_dec_acquire(...) \293293- __atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)294294-#endif295295-296296-#ifndef atomic_fetch_dec_release297297-#define atomic_fetch_dec_release(...) \298298- __atomic_op_release(atomic_fetch_dec, __VA_ARGS__)299299-#endif300300-301301-#ifndef atomic_fetch_dec302302-#define atomic_fetch_dec(...) \303303- __atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)304304-#endif305305-#endif /* atomic_fetch_dec_relaxed */306306-307307-/* atomic_fetch_or_relaxed */308308-#ifndef atomic_fetch_or_relaxed309309-#define atomic_fetch_or_relaxed atomic_fetch_or310310-#define atomic_fetch_or_acquire atomic_fetch_or311311-#define atomic_fetch_or_release atomic_fetch_or312312-313313-#else /* atomic_fetch_or_relaxed */314314-315315-#ifndef atomic_fetch_or_acquire316316-#define atomic_fetch_or_acquire(...) \317317- __atomic_op_acquire(atomic_fetch_or, __VA_ARGS__)318318-#endif319319-320320-#ifndef atomic_fetch_or_release321321-#define atomic_fetch_or_release(...) \322322- __atomic_op_release(atomic_fetch_or, __VA_ARGS__)323323-#endif324324-325325-#ifndef atomic_fetch_or326326-#define atomic_fetch_or(...) \327327- __atomic_op_fence(atomic_fetch_or, __VA_ARGS__)328328-#endif329329-#endif /* atomic_fetch_or_relaxed */330330-331331-/* atomic_fetch_and_relaxed */332332-#ifndef atomic_fetch_and_relaxed333333-#define atomic_fetch_and_relaxed atomic_fetch_and334334-#define atomic_fetch_and_acquire atomic_fetch_and335335-#define atomic_fetch_and_release atomic_fetch_and336336-337337-#else /* atomic_fetch_and_relaxed */338338-339339-#ifndef atomic_fetch_and_acquire340340-#define atomic_fetch_and_acquire(...) \341341- __atomic_op_acquire(atomic_fetch_and, __VA_ARGS__)342342-#endif343343-344344-#ifndef atomic_fetch_and_release345345-#define atomic_fetch_and_release(...) \346346- __atomic_op_release(atomic_fetch_and, __VA_ARGS__)347347-#endif348348-349349-#ifndef atomic_fetch_and350350-#define atomic_fetch_and(...) \351351- __atomic_op_fence(atomic_fetch_and, __VA_ARGS__)352352-#endif353353-#endif /* atomic_fetch_and_relaxed */354354-355355-#ifndef atomic_andnot356356-#define atomic_andnot(i, v) atomic_and(~(int)(i), (v))357357-#endif358358-359359-#ifndef atomic_fetch_andnot_relaxed360360-361361-#ifndef atomic_fetch_andnot362362-#define atomic_fetch_andnot(i, v) atomic_fetch_and(~(int)(i), (v))363363-#define atomic_fetch_andnot_relaxed(i, v) atomic_fetch_and_relaxed(~(int)(i), (v))364364-#define atomic_fetch_andnot_acquire(i, v) atomic_fetch_and_acquire(~(int)(i), (v))365365-#define atomic_fetch_andnot_release(i, v) atomic_fetch_and_release(~(int)(i), (v))366366-#else /* atomic_fetch_andnot */367367-#define atomic_fetch_andnot_relaxed atomic_fetch_andnot368368-#define atomic_fetch_andnot_acquire atomic_fetch_andnot369369-#define atomic_fetch_andnot_release atomic_fetch_andnot370370-#endif /* atomic_fetch_andnot */371371-372372-#else /* atomic_fetch_andnot_relaxed */373373-374374-#ifndef atomic_fetch_andnot_acquire375375-#define atomic_fetch_andnot_acquire(...) \376376- __atomic_op_acquire(atomic_fetch_andnot, __VA_ARGS__)377377-#endif378378-379379-#ifndef atomic_fetch_andnot_release380380-#define atomic_fetch_andnot_release(...) \381381- __atomic_op_release(atomic_fetch_andnot, __VA_ARGS__)382382-#endif383383-384384-#ifndef atomic_fetch_andnot385385-#define atomic_fetch_andnot(...) \386386- __atomic_op_fence(atomic_fetch_andnot, __VA_ARGS__)387387-#endif388388-#endif /* atomic_fetch_andnot_relaxed */389389-390390-/* atomic_fetch_xor_relaxed */391391-#ifndef atomic_fetch_xor_relaxed392392-#define atomic_fetch_xor_relaxed atomic_fetch_xor393393-#define atomic_fetch_xor_acquire atomic_fetch_xor394394-#define atomic_fetch_xor_release atomic_fetch_xor395395-396396-#else /* atomic_fetch_xor_relaxed */397397-398398-#ifndef atomic_fetch_xor_acquire399399-#define atomic_fetch_xor_acquire(...) \400400- __atomic_op_acquire(atomic_fetch_xor, __VA_ARGS__)401401-#endif402402-403403-#ifndef atomic_fetch_xor_release404404-#define atomic_fetch_xor_release(...) \405405- __atomic_op_release(atomic_fetch_xor, __VA_ARGS__)406406-#endif407407-408408-#ifndef atomic_fetch_xor409409-#define atomic_fetch_xor(...) \410410- __atomic_op_fence(atomic_fetch_xor, __VA_ARGS__)411411-#endif412412-#endif /* atomic_fetch_xor_relaxed */413413-414414-415415-/* atomic_xchg_relaxed */416416-#ifndef atomic_xchg_relaxed417417-#define atomic_xchg_relaxed atomic_xchg418418-#define atomic_xchg_acquire atomic_xchg419419-#define atomic_xchg_release atomic_xchg420420-421421-#else /* atomic_xchg_relaxed */422422-423423-#ifndef atomic_xchg_acquire424424-#define atomic_xchg_acquire(...) \425425- __atomic_op_acquire(atomic_xchg, __VA_ARGS__)426426-#endif427427-428428-#ifndef atomic_xchg_release429429-#define atomic_xchg_release(...) \430430- __atomic_op_release(atomic_xchg, __VA_ARGS__)431431-#endif432432-433433-#ifndef atomic_xchg434434-#define atomic_xchg(...) \435435- __atomic_op_fence(atomic_xchg, __VA_ARGS__)436436-#endif437437-#endif /* atomic_xchg_relaxed */438438-439439-/* atomic_cmpxchg_relaxed */440440-#ifndef atomic_cmpxchg_relaxed441441-#define atomic_cmpxchg_relaxed atomic_cmpxchg442442-#define atomic_cmpxchg_acquire atomic_cmpxchg443443-#define atomic_cmpxchg_release atomic_cmpxchg444444-445445-#else /* atomic_cmpxchg_relaxed */446446-447447-#ifndef atomic_cmpxchg_acquire448448-#define atomic_cmpxchg_acquire(...) \449449- __atomic_op_acquire(atomic_cmpxchg, __VA_ARGS__)450450-#endif451451-452452-#ifndef atomic_cmpxchg_release453453-#define atomic_cmpxchg_release(...) \454454- __atomic_op_release(atomic_cmpxchg, __VA_ARGS__)455455-#endif456456-457457-#ifndef atomic_cmpxchg458458-#define atomic_cmpxchg(...) \459459- __atomic_op_fence(atomic_cmpxchg, __VA_ARGS__)460460-#endif461461-#endif /* atomic_cmpxchg_relaxed */462462-463463-#ifndef atomic_try_cmpxchg464464-465465-#define __atomic_try_cmpxchg(type, _p, _po, _n) \466466-({ \467467- typeof(_po) __po = (_po); \468468- typeof(*(_po)) __r, __o = *__po; \469469- __r = atomic_cmpxchg##type((_p), __o, (_n)); \470470- if (unlikely(__r != __o)) \471471- *__po = __r; \472472- likely(__r == __o); \473473-})474474-475475-#define atomic_try_cmpxchg(_p, _po, _n) __atomic_try_cmpxchg(, _p, _po, _n)476476-#define atomic_try_cmpxchg_relaxed(_p, _po, _n) __atomic_try_cmpxchg(_relaxed, _p, _po, _n)477477-#define atomic_try_cmpxchg_acquire(_p, _po, _n) __atomic_try_cmpxchg(_acquire, _p, _po, _n)478478-#define atomic_try_cmpxchg_release(_p, _po, _n) __atomic_try_cmpxchg(_release, _p, _po, _n)479479-480480-#else /* atomic_try_cmpxchg */481481-#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg482482-#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg483483-#define atomic_try_cmpxchg_release atomic_try_cmpxchg484484-#endif /* atomic_try_cmpxchg */485485-486486-/* cmpxchg_relaxed */487487-#ifndef cmpxchg_relaxed488488-#define cmpxchg_relaxed cmpxchg489489-#define cmpxchg_acquire cmpxchg490490-#define cmpxchg_release cmpxchg491491-492492-#else /* cmpxchg_relaxed */493493-494494-#ifndef cmpxchg_acquire495495-#define cmpxchg_acquire(...) \496496- __atomic_op_acquire(cmpxchg, __VA_ARGS__)497497-#endif498498-499499-#ifndef cmpxchg_release500500-#define cmpxchg_release(...) \501501- __atomic_op_release(cmpxchg, __VA_ARGS__)502502-#endif503503-504504-#ifndef cmpxchg505505-#define cmpxchg(...) \506506- __atomic_op_fence(cmpxchg, __VA_ARGS__)507507-#endif508508-#endif /* cmpxchg_relaxed */509509-510510-/* cmpxchg64_relaxed */511511-#ifndef cmpxchg64_relaxed512512-#define cmpxchg64_relaxed cmpxchg64513513-#define cmpxchg64_acquire cmpxchg64514514-#define cmpxchg64_release cmpxchg64515515-516516-#else /* cmpxchg64_relaxed */517517-518518-#ifndef cmpxchg64_acquire519519-#define cmpxchg64_acquire(...) \520520- __atomic_op_acquire(cmpxchg64, __VA_ARGS__)521521-#endif522522-523523-#ifndef cmpxchg64_release524524-#define cmpxchg64_release(...) \525525- __atomic_op_release(cmpxchg64, __VA_ARGS__)526526-#endif527527-528528-#ifndef cmpxchg64529529-#define cmpxchg64(...) \530530- __atomic_op_fence(cmpxchg64, __VA_ARGS__)531531-#endif532532-#endif /* cmpxchg64_relaxed */533533-534534-/* xchg_relaxed */535535-#ifndef xchg_relaxed536536-#define xchg_relaxed xchg537537-#define xchg_acquire xchg538538-#define xchg_release xchg539539-540540-#else /* xchg_relaxed */541541-542542-#ifndef xchg_acquire543543-#define xchg_acquire(...) __atomic_op_acquire(xchg, __VA_ARGS__)544544-#endif545545-546546-#ifndef xchg_release547547-#define xchg_release(...) __atomic_op_release(xchg, __VA_ARGS__)548548-#endif549549-550550-#ifndef xchg551551-#define xchg(...) __atomic_op_fence(xchg, __VA_ARGS__)552552-#endif553553-#endif /* xchg_relaxed */554554-555555-/**556556- * atomic_fetch_add_unless - add unless the number is already a given value557557- * @v: pointer of type atomic_t558558- * @a: the amount to add to v...559559- * @u: ...unless v is equal to u.560560- *561561- * Atomically adds @a to @v, if @v was not already @u.562562- * Returns the original value of @v.563563- */564564-#ifndef atomic_fetch_add_unless565565-static inline int atomic_fetch_add_unless(atomic_t *v, int a, int u)566566-{567567- int c = atomic_read(v);568568-569569- do {570570- if (unlikely(c == u))571571- break;572572- } while (!atomic_try_cmpxchg(v, &c, c + a));573573-574574- return c;575575-}576576-#endif577577-578578-/**579579- * atomic_add_unless - add unless the number is already a given value580580- * @v: pointer of type atomic_t581581- * @a: the amount to add to v...582582- * @u: ...unless v is equal to u.583583- *584584- * Atomically adds @a to @v, if @v was not already @u.585585- * Returns true if the addition was done.586586- */587587-static inline bool atomic_add_unless(atomic_t *v, int a, int u)588588-{589589- return atomic_fetch_add_unless(v, a, u) != u;590590-}591591-592592-/**593593- * atomic_inc_not_zero - increment unless the number is zero594594- * @v: pointer of type atomic_t595595- *596596- * Atomically increments @v by 1, if @v is non-zero.597597- * Returns true if the increment was done.598598- */599599-#ifndef atomic_inc_not_zero600600-#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)601601-#endif602602-603603-/**604604- * atomic_inc_and_test - increment and test605605- * @v: pointer of type atomic_t606606- *607607- * Atomically increments @v by 1608608- * and returns true if the result is zero, or false for all609609- * other cases.610610- */611611-#ifndef atomic_inc_and_test612612-static inline bool atomic_inc_and_test(atomic_t *v)613613-{614614- return atomic_inc_return(v) == 0;615615-}616616-#endif617617-618618-/**619619- * atomic_dec_and_test - decrement and test620620- * @v: pointer of type atomic_t621621- *622622- * Atomically decrements @v by 1 and623623- * returns true if the result is 0, or false for all other624624- * cases.625625- */626626-#ifndef atomic_dec_and_test627627-static inline bool atomic_dec_and_test(atomic_t *v)628628-{629629- return atomic_dec_return(v) == 0;630630-}631631-#endif632632-633633-/**634634- * atomic_sub_and_test - subtract value from variable and test result635635- * @i: integer value to subtract636636- * @v: pointer of type atomic_t637637- *638638- * Atomically subtracts @i from @v and returns639639- * true if the result is zero, or false for all640640- * other cases.641641- */642642-#ifndef atomic_sub_and_test643643-static inline bool atomic_sub_and_test(int i, atomic_t *v)644644-{645645- return atomic_sub_return(i, v) == 0;646646-}647647-#endif648648-649649-/**650650- * atomic_add_negative - add and test if negative651651- * @i: integer value to add652652- * @v: pointer of type atomic_t653653- *654654- * Atomically adds @i to @v and returns true655655- * if the result is negative, or false when656656- * result is greater than or equal to zero.657657- */658658-#ifndef atomic_add_negative659659-static inline bool atomic_add_negative(int i, atomic_t *v)660660-{661661- return atomic_add_return(i, v) < 0;662662-}663663-#endif664664-665665-#ifndef atomic_inc_unless_negative666666-static inline bool atomic_inc_unless_negative(atomic_t *v)667667-{668668- int c = atomic_read(v);669669-670670- do {671671- if (unlikely(c < 0))672672- return false;673673- } while (!atomic_try_cmpxchg(v, &c, c + 1));674674-675675- return true;676676-}677677-#endif678678-679679-#ifndef atomic_dec_unless_positive680680-static inline bool atomic_dec_unless_positive(atomic_t *v)681681-{682682- int c = atomic_read(v);683683-684684- do {685685- if (unlikely(c > 0))686686- return false;687687- } while (!atomic_try_cmpxchg(v, &c, c - 1));688688-689689- return true;690690-}691691-#endif692692-693693-/*694694- * atomic_dec_if_positive - decrement by 1 if old value positive695695- * @v: pointer of type atomic_t696696- *697697- * The function returns the old value of *v minus 1, even if698698- * the atomic variable, v, was not decremented.699699- */700700-#ifndef atomic_dec_if_positive701701-static inline int atomic_dec_if_positive(atomic_t *v)702702-{703703- int dec, c = atomic_read(v);704704-705705- do {706706- dec = c - 1;707707- if (unlikely(dec < 0))708708- break;709709- } while (!atomic_try_cmpxchg(v, &c, dec));710710-711711- return dec;712712-}713713-#endif714714-715715-#define atomic_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))716716-#define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))717717-718718-#ifdef CONFIG_GENERIC_ATOMIC64719719-#include <asm-generic/atomic64.h>720720-#endif721721-722722-#ifndef atomic64_read_acquire723723-#define atomic64_read_acquire(v) smp_load_acquire(&(v)->counter)724724-#endif725725-726726-#ifndef atomic64_set_release727727-#define atomic64_set_release(v, i) smp_store_release(&(v)->counter, (i))728728-#endif729729-730730-/* atomic64_add_return_relaxed */731731-#ifndef atomic64_add_return_relaxed732732-#define atomic64_add_return_relaxed atomic64_add_return733733-#define atomic64_add_return_acquire atomic64_add_return734734-#define atomic64_add_return_release atomic64_add_return735735-736736-#else /* atomic64_add_return_relaxed */737737-738738-#ifndef atomic64_add_return_acquire739739-#define atomic64_add_return_acquire(...) \740740- __atomic_op_acquire(atomic64_add_return, __VA_ARGS__)741741-#endif742742-743743-#ifndef atomic64_add_return_release744744-#define atomic64_add_return_release(...) \745745- __atomic_op_release(atomic64_add_return, __VA_ARGS__)746746-#endif747747-748748-#ifndef atomic64_add_return749749-#define atomic64_add_return(...) \750750- __atomic_op_fence(atomic64_add_return, __VA_ARGS__)751751-#endif752752-#endif /* atomic64_add_return_relaxed */753753-754754-#ifndef atomic64_inc755755-#define atomic64_inc(v) atomic64_add(1, (v))756756-#endif757757-758758-/* atomic64_inc_return_relaxed */759759-#ifndef atomic64_inc_return_relaxed760760-761761-#ifndef atomic64_inc_return762762-#define atomic64_inc_return(v) atomic64_add_return(1, (v))763763-#define atomic64_inc_return_relaxed(v) atomic64_add_return_relaxed(1, (v))764764-#define atomic64_inc_return_acquire(v) atomic64_add_return_acquire(1, (v))765765-#define atomic64_inc_return_release(v) atomic64_add_return_release(1, (v))766766-#else /* atomic64_inc_return */767767-#define atomic64_inc_return_relaxed atomic64_inc_return768768-#define atomic64_inc_return_acquire atomic64_inc_return769769-#define atomic64_inc_return_release atomic64_inc_return770770-#endif /* atomic64_inc_return */771771-772772-#else /* atomic64_inc_return_relaxed */773773-774774-#ifndef atomic64_inc_return_acquire775775-#define atomic64_inc_return_acquire(...) \776776- __atomic_op_acquire(atomic64_inc_return, __VA_ARGS__)777777-#endif778778-779779-#ifndef atomic64_inc_return_release780780-#define atomic64_inc_return_release(...) \781781- __atomic_op_release(atomic64_inc_return, __VA_ARGS__)782782-#endif783783-784784-#ifndef atomic64_inc_return785785-#define atomic64_inc_return(...) \786786- __atomic_op_fence(atomic64_inc_return, __VA_ARGS__)787787-#endif788788-#endif /* atomic64_inc_return_relaxed */789789-790790-791791-/* atomic64_sub_return_relaxed */792792-#ifndef atomic64_sub_return_relaxed793793-#define atomic64_sub_return_relaxed atomic64_sub_return794794-#define atomic64_sub_return_acquire atomic64_sub_return795795-#define atomic64_sub_return_release atomic64_sub_return796796-797797-#else /* atomic64_sub_return_relaxed */798798-799799-#ifndef atomic64_sub_return_acquire800800-#define atomic64_sub_return_acquire(...) \801801- __atomic_op_acquire(atomic64_sub_return, __VA_ARGS__)802802-#endif803803-804804-#ifndef atomic64_sub_return_release805805-#define atomic64_sub_return_release(...) \806806- __atomic_op_release(atomic64_sub_return, __VA_ARGS__)807807-#endif808808-809809-#ifndef atomic64_sub_return810810-#define atomic64_sub_return(...) \811811- __atomic_op_fence(atomic64_sub_return, __VA_ARGS__)812812-#endif813813-#endif /* atomic64_sub_return_relaxed */814814-815815-#ifndef atomic64_dec816816-#define atomic64_dec(v) atomic64_sub(1, (v))817817-#endif818818-819819-/* atomic64_dec_return_relaxed */820820-#ifndef atomic64_dec_return_relaxed821821-822822-#ifndef atomic64_dec_return823823-#define atomic64_dec_return(v) atomic64_sub_return(1, (v))824824-#define atomic64_dec_return_relaxed(v) atomic64_sub_return_relaxed(1, (v))825825-#define atomic64_dec_return_acquire(v) atomic64_sub_return_acquire(1, (v))826826-#define atomic64_dec_return_release(v) atomic64_sub_return_release(1, (v))827827-#else /* atomic64_dec_return */828828-#define atomic64_dec_return_relaxed atomic64_dec_return829829-#define atomic64_dec_return_acquire atomic64_dec_return830830-#define atomic64_dec_return_release atomic64_dec_return831831-#endif /* atomic64_dec_return */832832-833833-#else /* atomic64_dec_return_relaxed */834834-835835-#ifndef atomic64_dec_return_acquire836836-#define atomic64_dec_return_acquire(...) \837837- __atomic_op_acquire(atomic64_dec_return, __VA_ARGS__)838838-#endif839839-840840-#ifndef atomic64_dec_return_release841841-#define atomic64_dec_return_release(...) \842842- __atomic_op_release(atomic64_dec_return, __VA_ARGS__)843843-#endif844844-845845-#ifndef atomic64_dec_return846846-#define atomic64_dec_return(...) \847847- __atomic_op_fence(atomic64_dec_return, __VA_ARGS__)848848-#endif849849-#endif /* atomic64_dec_return_relaxed */850850-851851-852852-/* atomic64_fetch_add_relaxed */853853-#ifndef atomic64_fetch_add_relaxed854854-#define atomic64_fetch_add_relaxed atomic64_fetch_add855855-#define atomic64_fetch_add_acquire atomic64_fetch_add856856-#define atomic64_fetch_add_release atomic64_fetch_add857857-858858-#else /* atomic64_fetch_add_relaxed */859859-860860-#ifndef atomic64_fetch_add_acquire861861-#define atomic64_fetch_add_acquire(...) \862862- __atomic_op_acquire(atomic64_fetch_add, __VA_ARGS__)863863-#endif864864-865865-#ifndef atomic64_fetch_add_release866866-#define atomic64_fetch_add_release(...) \867867- __atomic_op_release(atomic64_fetch_add, __VA_ARGS__)868868-#endif869869-870870-#ifndef atomic64_fetch_add871871-#define atomic64_fetch_add(...) \872872- __atomic_op_fence(atomic64_fetch_add, __VA_ARGS__)873873-#endif874874-#endif /* atomic64_fetch_add_relaxed */875875-876876-/* atomic64_fetch_inc_relaxed */877877-#ifndef atomic64_fetch_inc_relaxed878878-879879-#ifndef atomic64_fetch_inc880880-#define atomic64_fetch_inc(v) atomic64_fetch_add(1, (v))881881-#define atomic64_fetch_inc_relaxed(v) atomic64_fetch_add_relaxed(1, (v))882882-#define atomic64_fetch_inc_acquire(v) atomic64_fetch_add_acquire(1, (v))883883-#define atomic64_fetch_inc_release(v) atomic64_fetch_add_release(1, (v))884884-#else /* atomic64_fetch_inc */885885-#define atomic64_fetch_inc_relaxed atomic64_fetch_inc886886-#define atomic64_fetch_inc_acquire atomic64_fetch_inc887887-#define atomic64_fetch_inc_release atomic64_fetch_inc888888-#endif /* atomic64_fetch_inc */889889-890890-#else /* atomic64_fetch_inc_relaxed */891891-892892-#ifndef atomic64_fetch_inc_acquire893893-#define atomic64_fetch_inc_acquire(...) \894894- __atomic_op_acquire(atomic64_fetch_inc, __VA_ARGS__)895895-#endif896896-897897-#ifndef atomic64_fetch_inc_release898898-#define atomic64_fetch_inc_release(...) \899899- __atomic_op_release(atomic64_fetch_inc, __VA_ARGS__)900900-#endif901901-902902-#ifndef atomic64_fetch_inc903903-#define atomic64_fetch_inc(...) \904904- __atomic_op_fence(atomic64_fetch_inc, __VA_ARGS__)905905-#endif906906-#endif /* atomic64_fetch_inc_relaxed */907907-908908-/* atomic64_fetch_sub_relaxed */909909-#ifndef atomic64_fetch_sub_relaxed910910-#define atomic64_fetch_sub_relaxed atomic64_fetch_sub911911-#define atomic64_fetch_sub_acquire atomic64_fetch_sub912912-#define atomic64_fetch_sub_release atomic64_fetch_sub913913-914914-#else /* atomic64_fetch_sub_relaxed */915915-916916-#ifndef atomic64_fetch_sub_acquire917917-#define atomic64_fetch_sub_acquire(...) \918918- __atomic_op_acquire(atomic64_fetch_sub, __VA_ARGS__)919919-#endif920920-921921-#ifndef atomic64_fetch_sub_release922922-#define atomic64_fetch_sub_release(...) \923923- __atomic_op_release(atomic64_fetch_sub, __VA_ARGS__)924924-#endif925925-926926-#ifndef atomic64_fetch_sub927927-#define atomic64_fetch_sub(...) \928928- __atomic_op_fence(atomic64_fetch_sub, __VA_ARGS__)929929-#endif930930-#endif /* atomic64_fetch_sub_relaxed */931931-932932-/* atomic64_fetch_dec_relaxed */933933-#ifndef atomic64_fetch_dec_relaxed934934-935935-#ifndef atomic64_fetch_dec936936-#define atomic64_fetch_dec(v) atomic64_fetch_sub(1, (v))937937-#define atomic64_fetch_dec_relaxed(v) atomic64_fetch_sub_relaxed(1, (v))938938-#define atomic64_fetch_dec_acquire(v) atomic64_fetch_sub_acquire(1, (v))939939-#define atomic64_fetch_dec_release(v) atomic64_fetch_sub_release(1, (v))940940-#else /* atomic64_fetch_dec */941941-#define atomic64_fetch_dec_relaxed atomic64_fetch_dec942942-#define atomic64_fetch_dec_acquire atomic64_fetch_dec943943-#define atomic64_fetch_dec_release atomic64_fetch_dec944944-#endif /* atomic64_fetch_dec */945945-946946-#else /* atomic64_fetch_dec_relaxed */947947-948948-#ifndef atomic64_fetch_dec_acquire949949-#define atomic64_fetch_dec_acquire(...) \950950- __atomic_op_acquire(atomic64_fetch_dec, __VA_ARGS__)951951-#endif952952-953953-#ifndef atomic64_fetch_dec_release954954-#define atomic64_fetch_dec_release(...) \955955- __atomic_op_release(atomic64_fetch_dec, __VA_ARGS__)956956-#endif957957-958958-#ifndef atomic64_fetch_dec959959-#define atomic64_fetch_dec(...) \960960- __atomic_op_fence(atomic64_fetch_dec, __VA_ARGS__)961961-#endif962962-#endif /* atomic64_fetch_dec_relaxed */963963-964964-/* atomic64_fetch_or_relaxed */965965-#ifndef atomic64_fetch_or_relaxed966966-#define atomic64_fetch_or_relaxed atomic64_fetch_or967967-#define atomic64_fetch_or_acquire atomic64_fetch_or968968-#define atomic64_fetch_or_release atomic64_fetch_or969969-970970-#else /* atomic64_fetch_or_relaxed */971971-972972-#ifndef atomic64_fetch_or_acquire973973-#define atomic64_fetch_or_acquire(...) \974974- __atomic_op_acquire(atomic64_fetch_or, __VA_ARGS__)975975-#endif976976-977977-#ifndef atomic64_fetch_or_release978978-#define atomic64_fetch_or_release(...) \979979- __atomic_op_release(atomic64_fetch_or, __VA_ARGS__)980980-#endif981981-982982-#ifndef atomic64_fetch_or983983-#define atomic64_fetch_or(...) \984984- __atomic_op_fence(atomic64_fetch_or, __VA_ARGS__)985985-#endif986986-#endif /* atomic64_fetch_or_relaxed */987987-988988-/* atomic64_fetch_and_relaxed */989989-#ifndef atomic64_fetch_and_relaxed990990-#define atomic64_fetch_and_relaxed atomic64_fetch_and991991-#define atomic64_fetch_and_acquire atomic64_fetch_and992992-#define atomic64_fetch_and_release atomic64_fetch_and993993-994994-#else /* atomic64_fetch_and_relaxed */995995-996996-#ifndef atomic64_fetch_and_acquire997997-#define atomic64_fetch_and_acquire(...) \998998- __atomic_op_acquire(atomic64_fetch_and, __VA_ARGS__)999999-#endif10001000-10011001-#ifndef atomic64_fetch_and_release10021002-#define atomic64_fetch_and_release(...) \10031003- __atomic_op_release(atomic64_fetch_and, __VA_ARGS__)10041004-#endif10051005-10061006-#ifndef atomic64_fetch_and10071007-#define atomic64_fetch_and(...) \10081008- __atomic_op_fence(atomic64_fetch_and, __VA_ARGS__)10091009-#endif10101010-#endif /* atomic64_fetch_and_relaxed */10111011-10121012-#ifndef atomic64_andnot10131013-#define atomic64_andnot(i, v) atomic64_and(~(long long)(i), (v))10141014-#endif10151015-10161016-#ifndef atomic64_fetch_andnot_relaxed10171017-10181018-#ifndef atomic64_fetch_andnot10191019-#define atomic64_fetch_andnot(i, v) atomic64_fetch_and(~(long long)(i), (v))10201020-#define atomic64_fetch_andnot_relaxed(i, v) atomic64_fetch_and_relaxed(~(long long)(i), (v))10211021-#define atomic64_fetch_andnot_acquire(i, v) atomic64_fetch_and_acquire(~(long long)(i), (v))10221022-#define atomic64_fetch_andnot_release(i, v) atomic64_fetch_and_release(~(long long)(i), (v))10231023-#else /* atomic64_fetch_andnot */10241024-#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot10251025-#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot10261026-#define atomic64_fetch_andnot_release atomic64_fetch_andnot10271027-#endif /* atomic64_fetch_andnot */10281028-10291029-#else /* atomic64_fetch_andnot_relaxed */10301030-10311031-#ifndef atomic64_fetch_andnot_acquire10321032-#define atomic64_fetch_andnot_acquire(...) \10331033- __atomic_op_acquire(atomic64_fetch_andnot, __VA_ARGS__)10341034-#endif10351035-10361036-#ifndef atomic64_fetch_andnot_release10371037-#define atomic64_fetch_andnot_release(...) \10381038- __atomic_op_release(atomic64_fetch_andnot, __VA_ARGS__)10391039-#endif10401040-10411041-#ifndef atomic64_fetch_andnot10421042-#define atomic64_fetch_andnot(...) \10431043- __atomic_op_fence(atomic64_fetch_andnot, __VA_ARGS__)10441044-#endif10451045-#endif /* atomic64_fetch_andnot_relaxed */10461046-10471047-/* atomic64_fetch_xor_relaxed */10481048-#ifndef atomic64_fetch_xor_relaxed10491049-#define atomic64_fetch_xor_relaxed atomic64_fetch_xor10501050-#define atomic64_fetch_xor_acquire atomic64_fetch_xor10511051-#define atomic64_fetch_xor_release atomic64_fetch_xor10521052-10531053-#else /* atomic64_fetch_xor_relaxed */10541054-10551055-#ifndef atomic64_fetch_xor_acquire10561056-#define atomic64_fetch_xor_acquire(...) \10571057- __atomic_op_acquire(atomic64_fetch_xor, __VA_ARGS__)10581058-#endif10591059-10601060-#ifndef atomic64_fetch_xor_release10611061-#define atomic64_fetch_xor_release(...) \10621062- __atomic_op_release(atomic64_fetch_xor, __VA_ARGS__)10631063-#endif10641064-10651065-#ifndef atomic64_fetch_xor10661066-#define atomic64_fetch_xor(...) \10671067- __atomic_op_fence(atomic64_fetch_xor, __VA_ARGS__)10681068-#endif10691069-#endif /* atomic64_fetch_xor_relaxed */10701070-10711071-10721072-/* atomic64_xchg_relaxed */10731073-#ifndef atomic64_xchg_relaxed10741074-#define atomic64_xchg_relaxed atomic64_xchg10751075-#define atomic64_xchg_acquire atomic64_xchg10761076-#define atomic64_xchg_release atomic64_xchg10771077-10781078-#else /* atomic64_xchg_relaxed */10791079-10801080-#ifndef atomic64_xchg_acquire10811081-#define atomic64_xchg_acquire(...) \10821082- __atomic_op_acquire(atomic64_xchg, __VA_ARGS__)10831083-#endif10841084-10851085-#ifndef atomic64_xchg_release10861086-#define atomic64_xchg_release(...) \10871087- __atomic_op_release(atomic64_xchg, __VA_ARGS__)10881088-#endif10891089-10901090-#ifndef atomic64_xchg10911091-#define atomic64_xchg(...) \10921092- __atomic_op_fence(atomic64_xchg, __VA_ARGS__)10931093-#endif10941094-#endif /* atomic64_xchg_relaxed */10951095-10961096-/* atomic64_cmpxchg_relaxed */10971097-#ifndef atomic64_cmpxchg_relaxed10981098-#define atomic64_cmpxchg_relaxed atomic64_cmpxchg10991099-#define atomic64_cmpxchg_acquire atomic64_cmpxchg11001100-#define atomic64_cmpxchg_release atomic64_cmpxchg11011101-11021102-#else /* atomic64_cmpxchg_relaxed */11031103-11041104-#ifndef atomic64_cmpxchg_acquire11051105-#define atomic64_cmpxchg_acquire(...) \11061106- __atomic_op_acquire(atomic64_cmpxchg, __VA_ARGS__)11071107-#endif11081108-11091109-#ifndef atomic64_cmpxchg_release11101110-#define atomic64_cmpxchg_release(...) \11111111- __atomic_op_release(atomic64_cmpxchg, __VA_ARGS__)11121112-#endif11131113-11141114-#ifndef atomic64_cmpxchg11151115-#define atomic64_cmpxchg(...) \11161116- __atomic_op_fence(atomic64_cmpxchg, __VA_ARGS__)11171117-#endif11181118-#endif /* atomic64_cmpxchg_relaxed */11191119-11201120-#ifndef atomic64_try_cmpxchg11211121-11221122-#define __atomic64_try_cmpxchg(type, _p, _po, _n) \11231123-({ \11241124- typeof(_po) __po = (_po); \11251125- typeof(*(_po)) __r, __o = *__po; \11261126- __r = atomic64_cmpxchg##type((_p), __o, (_n)); \11271127- if (unlikely(__r != __o)) \11281128- *__po = __r; \11291129- likely(__r == __o); \11301130-})11311131-11321132-#define atomic64_try_cmpxchg(_p, _po, _n) __atomic64_try_cmpxchg(, _p, _po, _n)11331133-#define atomic64_try_cmpxchg_relaxed(_p, _po, _n) __atomic64_try_cmpxchg(_relaxed, _p, _po, _n)11341134-#define atomic64_try_cmpxchg_acquire(_p, _po, _n) __atomic64_try_cmpxchg(_acquire, _p, _po, _n)11351135-#define atomic64_try_cmpxchg_release(_p, _po, _n) __atomic64_try_cmpxchg(_release, _p, _po, _n)11361136-11371137-#else /* atomic64_try_cmpxchg */11381138-#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg11391139-#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg11401140-#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg11411141-#endif /* atomic64_try_cmpxchg */11421142-11431143-/**11441144- * atomic64_fetch_add_unless - add unless the number is already a given value11451145- * @v: pointer of type atomic64_t11461146- * @a: the amount to add to v...11471147- * @u: ...unless v is equal to u.11481148- *11491149- * Atomically adds @a to @v, if @v was not already @u.11501150- * Returns the original value of @v.11511151- */11521152-#ifndef atomic64_fetch_add_unless11531153-static inline long long atomic64_fetch_add_unless(atomic64_t *v, long long a,11541154- long long u)11551155-{11561156- long long c = atomic64_read(v);11571157-11581158- do {11591159- if (unlikely(c == u))11601160- break;11611161- } while (!atomic64_try_cmpxchg(v, &c, c + a));11621162-11631163- return c;11641164-}11651165-#endif11661166-11671167-/**11681168- * atomic64_add_unless - add unless the number is already a given value11691169- * @v: pointer of type atomic_t11701170- * @a: the amount to add to v...11711171- * @u: ...unless v is equal to u.11721172- *11731173- * Atomically adds @a to @v, if @v was not already @u.11741174- * Returns true if the addition was done.11751175- */11761176-static inline bool atomic64_add_unless(atomic64_t *v, long long a, long long u)11771177-{11781178- return atomic64_fetch_add_unless(v, a, u) != u;11791179-}11801180-11811181-/**11821182- * atomic64_inc_not_zero - increment unless the number is zero11831183- * @v: pointer of type atomic64_t11841184- *11851185- * Atomically increments @v by 1, if @v is non-zero.11861186- * Returns true if the increment was done.11871187- */11881188-#ifndef atomic64_inc_not_zero11891189-#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)11901190-#endif11911191-11921192-/**11931193- * atomic64_inc_and_test - increment and test11941194- * @v: pointer of type atomic64_t11951195- *11961196- * Atomically increments @v by 111971197- * and returns true if the result is zero, or false for all11981198- * other cases.11991199- */12001200-#ifndef atomic64_inc_and_test12011201-static inline bool atomic64_inc_and_test(atomic64_t *v)12021202-{12031203- return atomic64_inc_return(v) == 0;12041204-}12051205-#endif12061206-12071207-/**12081208- * atomic64_dec_and_test - decrement and test12091209- * @v: pointer of type atomic64_t12101210- *12111211- * Atomically decrements @v by 1 and12121212- * returns true if the result is 0, or false for all other12131213- * cases.12141214- */12151215-#ifndef atomic64_dec_and_test12161216-static inline bool atomic64_dec_and_test(atomic64_t *v)12171217-{12181218- return atomic64_dec_return(v) == 0;12191219-}12201220-#endif12211221-12221222-/**12231223- * atomic64_sub_and_test - subtract value from variable and test result12241224- * @i: integer value to subtract12251225- * @v: pointer of type atomic64_t12261226- *12271227- * Atomically subtracts @i from @v and returns12281228- * true if the result is zero, or false for all12291229- * other cases.12301230- */12311231-#ifndef atomic64_sub_and_test12321232-static inline bool atomic64_sub_and_test(long long i, atomic64_t *v)12331233-{12341234- return atomic64_sub_return(i, v) == 0;12351235-}12361236-#endif12371237-12381238-/**12391239- * atomic64_add_negative - add and test if negative12401240- * @i: integer value to add12411241- * @v: pointer of type atomic64_t12421242- *12431243- * Atomically adds @i to @v and returns true12441244- * if the result is negative, or false when12451245- * result is greater than or equal to zero.12461246- */12471247-#ifndef atomic64_add_negative12481248-static inline bool atomic64_add_negative(long long i, atomic64_t *v)12491249-{12501250- return atomic64_add_return(i, v) < 0;12511251-}12521252-#endif12531253-12541254-#ifndef atomic64_inc_unless_negative12551255-static inline bool atomic64_inc_unless_negative(atomic64_t *v)12561256-{12571257- long long c = atomic64_read(v);12581258-12591259- do {12601260- if (unlikely(c < 0))12611261- return false;12621262- } while (!atomic64_try_cmpxchg(v, &c, c + 1));12631263-12641264- return true;12651265-}12661266-#endif12671267-12681268-#ifndef atomic64_dec_unless_positive12691269-static inline bool atomic64_dec_unless_positive(atomic64_t *v)12701270-{12711271- long long c = atomic64_read(v);12721272-12731273- do {12741274- if (unlikely(c > 0))12751275- return false;12761276- } while (!atomic64_try_cmpxchg(v, &c, c - 1));12771277-12781278- return true;12791279-}12801280-#endif12811281-12821282-/*12831283- * atomic64_dec_if_positive - decrement by 1 if old value positive12841284- * @v: pointer of type atomic64_t12851285- *12861286- * The function returns the old value of *v minus 1, even if12871287- * the atomic64 variable, v, was not decremented.12881288- */12891289-#ifndef atomic64_dec_if_positive12901290-static inline long long atomic64_dec_if_positive(atomic64_t *v)12911291-{12921292- long long dec, c = atomic64_read(v);12931293-12941294- do {12951295- dec = c - 1;12961296- if (unlikely(dec < 0))12971297- break;12981298- } while (!atomic64_try_cmpxchg(v, &c, dec));12991299-13001300- return dec;13011301-}13021302-#endif13031303-13041304-#define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))13051305-#define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))8282+#include <linux/atomic-fallback.h>130683130784#include <asm-generic/atomic-long.h>130885
+186
scripts/atomic/atomic-tbl.sh
···11+#!/bin/sh22+# SPDX-License-Identifier: GPL-2.033+# helpers for dealing with atomics.tbl44+55+#meta_in(meta, match)66+meta_in()77+{88+ case "$1" in99+ [$2]) return 0;;1010+ esac1111+1212+ return 11313+}1414+1515+#meta_has_ret(meta)1616+meta_has_ret()1717+{1818+ meta_in "$1" "bBiIfFlR"1919+}2020+2121+#meta_has_acquire(meta)2222+meta_has_acquire()2323+{2424+ meta_in "$1" "BFIlR"2525+}2626+2727+#meta_has_release(meta)2828+meta_has_release()2929+{3030+ meta_in "$1" "BFIRs"3131+}3232+3333+#meta_has_relaxed(meta)3434+meta_has_relaxed()3535+{3636+ meta_in "$1" "BFIR"3737+}3838+3939+#find_fallback_template(pfx, name, sfx, order)4040+find_fallback_template()4141+{4242+ local pfx="$1"; shift4343+ local name="$1"; shift4444+ local sfx="$1"; shift4545+ local order="$1"; shift4646+4747+ local base=""4848+ local file=""4949+5050+ # We may have fallbacks for a specific case (e.g. read_acquire()), or5151+ # an entire class, e.g. *inc*().5252+ #5353+ # Start at the most specific, and fall back to the most general. Once5454+ # we find a specific fallback, don't bother looking for more.5555+ for base in "${pfx}${name}${sfx}${order}" "${name}"; do5656+ file="${ATOMICDIR}/fallbacks/${base}"5757+5858+ if [ -f "${file}" ]; then5959+ printf "${file}"6060+ break6161+ fi6262+ done6363+}6464+6565+#gen_ret_type(meta, int)6666+gen_ret_type() {6767+ local meta="$1"; shift6868+ local int="$1"; shift6969+7070+ case "${meta}" in7171+ [sv]) printf "void";;7272+ [bB]) printf "bool";;7373+ [aiIfFlR]) printf "${int}";;7474+ esac7575+}7676+7777+#gen_ret_stmt(meta)7878+gen_ret_stmt()7979+{8080+ if meta_has_ret "${meta}"; then8181+ printf "return ";8282+ fi8383+}8484+8585+# gen_param_name(arg)8686+gen_param_name()8787+{8888+ # strip off the leading 'c' for 'cv'8989+ local name="${1#c}"9090+ printf "${name#*:}"9191+}9292+9393+# gen_param_type(arg, int, atomic)9494+gen_param_type()9595+{9696+ local type="${1%%:*}"; shift9797+ local int="$1"; shift9898+ local atomic="$1"; shift9999+100100+ case "${type}" in101101+ i) type="${int} ";;102102+ p) type="${int} *";;103103+ v) type="${atomic}_t *";;104104+ cv) type="const ${atomic}_t *";;105105+ esac106106+107107+ printf "${type}"108108+}109109+110110+#gen_param(arg, int, atomic)111111+gen_param()112112+{113113+ local arg="$1"; shift114114+ local int="$1"; shift115115+ local atomic="$1"; shift116116+ local name="$(gen_param_name "${arg}")"117117+ local type="$(gen_param_type "${arg}" "${int}" "${atomic}")"118118+119119+ printf "${type}${name}"120120+}121121+122122+#gen_params(int, atomic, arg...)123123+gen_params()124124+{125125+ local int="$1"; shift126126+ local atomic="$1"; shift127127+128128+ while [ "$#" -gt 0 ]; do129129+ gen_param "$1" "${int}" "${atomic}"130130+ [ "$#" -gt 1 ] && printf ", "131131+ shift;132132+ done133133+}134134+135135+#gen_args(arg...)136136+gen_args()137137+{138138+ while [ "$#" -gt 0 ]; do139139+ printf "$(gen_param_name "$1")"140140+ [ "$#" -gt 1 ] && printf ", "141141+ shift;142142+ done143143+}144144+145145+#gen_proto_order_variants(meta, pfx, name, sfx, ...)146146+gen_proto_order_variants()147147+{148148+ local meta="$1"; shift149149+ local pfx="$1"; shift150150+ local name="$1"; shift151151+ local sfx="$1"; shift152152+153153+ gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"154154+155155+ if meta_has_acquire "${meta}"; then156156+ gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"157157+ fi158158+ if meta_has_release "${meta}"; then159159+ gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"160160+ fi161161+ if meta_has_relaxed "${meta}"; then162162+ gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"163163+ fi164164+}165165+166166+#gen_proto_variants(meta, name, ...)167167+gen_proto_variants()168168+{169169+ local meta="$1"; shift170170+ local name="$1"; shift171171+ local pfx=""172172+ local sfx=""173173+174174+ meta_in "${meta}" "fF" && pfx="fetch_"175175+ meta_in "${meta}" "R" && sfx="_return"176176+177177+ gen_proto_order_variants "${meta}" "${pfx}" "${name}" "${sfx}" "$@"178178+}179179+180180+#gen_proto(meta, ...)181181+gen_proto() {182182+ local meta="$1"; shift183183+ for m in $(echo "${meta}" | fold -w1); do184184+ gen_proto_variants "${m}" "$@"185185+ done186186+}
+41
scripts/atomic/atomics.tbl
···11+# name meta args...22+#33+# Where meta contains a string of variants to generate.44+# Upper-case implies _{acquire,release,relaxed} variants.55+# Valid meta values are:66+# * B/b - bool: returns bool77+# * v - void: returns void88+# * I/i - int: returns base type99+# * R - return: returns base type (has _return variants)1010+# * F/f - fetch: returns base type (has fetch_ variants)1111+# * l - load: returns base type (has _acquire order variant)1212+# * s - store: returns void (has _release order variant)1313+#1414+# Where args contains list of type[:name], where type is:1515+# * cv - const pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t)1616+# * v - pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t)1717+# * i - base type (int/s64/long)1818+# * p - pointer to base type (int/s64/long)1919+#2020+read l cv2121+set s v i2222+add vRF i v2323+sub vRF i v2424+inc vRF v2525+dec vRF v2626+and vF i v2727+andnot vF i v2828+or vF i v2929+xor vF i v3030+xchg I v i3131+cmpxchg I v i:old i:new3232+try_cmpxchg B v p:old i:new3333+sub_and_test b i v3434+dec_and_test b v3535+inc_and_test b v3636+add_negative b i v3737+add_unless fb v i:a i:u3838+inc_not_zero b v3939+inc_unless_negative b v4040+dec_unless_positive b v4141+dec_if_positive i v
+19
scripts/atomic/check-atomics.sh
···11+#!/bin/sh22+# SPDX-License-Identifier: GPL-2.033+#44+# Check if atomic headers are up-to-date55+66+ATOMICDIR=$(dirname $0)77+ATOMICTBL=${ATOMICDIR}/atomics.tbl88+LINUXDIR=${ATOMICDIR}/../..99+1010+cat <<EOF |1111+gen-atomic-instrumented.sh asm-generic/atomic-instrumented.h1212+gen-atomic-long.sh asm-generic/atomic-long.h1313+gen-atomic-fallback.sh linux/atomic-fallback.h1414+EOF1515+while read script header; do1616+ if ! (${ATOMICDIR}/${script} ${ATOMICTBL} | diff - ${LINUXDIR}/include/${header} > /dev/null); then1717+ printf "warning: include/${header} is out-of-date.\n"1818+ fi1919+done
···11+cat <<EOF22+/**33+ * ${atomic}_add_negative - add and test if negative44+ * @i: integer value to add55+ * @v: pointer of type ${atomic}_t66+ *77+ * Atomically adds @i to @v and returns true88+ * if the result is negative, or false when99+ * result is greater than or equal to zero.1010+ */1111+static inline bool1212+${atomic}_add_negative(${int} i, ${atomic}_t *v)1313+{1414+ return ${atomic}_add_return(i, v) < 0;1515+}1616+EOF
+16
scripts/atomic/fallbacks/add_unless
···11+cat << EOF22+/**33+ * ${atomic}_add_unless - add unless the number is already a given value44+ * @v: pointer of type ${atomic}_t55+ * @a: the amount to add to v...66+ * @u: ...unless v is equal to u.77+ *88+ * Atomically adds @a to @v, if @v was not already @u.99+ * Returns true if the addition was done.1010+ */1111+static inline bool1212+${atomic}_add_unless(${atomic}_t *v, ${int} a, ${int} u)1313+{1414+ return ${atomic}_fetch_add_unless(v, a, u) != u;1515+}1616+EOF
+7
scripts/atomic/fallbacks/andnot
···11+cat <<EOF22+static inline ${ret}33+${atomic}_${pfx}andnot${sfx}${order}(${int} i, ${atomic}_t *v)44+{55+ ${retstmt}${atomic}_${pfx}and${sfx}${order}(~i, v);66+}77+EOF
···11+cat <<EOF22+/**33+ * ${atomic}_dec_and_test - decrement and test44+ * @v: pointer of type ${atomic}_t55+ *66+ * Atomically decrements @v by 1 and77+ * returns true if the result is 0, or false for all other88+ * cases.99+ */1010+static inline bool1111+${atomic}_dec_and_test(${atomic}_t *v)1212+{1313+ return ${atomic}_dec_return(v) == 0;1414+}1515+EOF
+15
scripts/atomic/fallbacks/dec_if_positive
···11+cat <<EOF22+static inline ${ret}33+${atomic}_dec_if_positive(${atomic}_t *v)44+{55+ ${int} dec, c = ${atomic}_read(v);66+77+ do {88+ dec = c - 1;99+ if (unlikely(dec < 0))1010+ break;1111+ } while (!${atomic}_try_cmpxchg(v, &c, dec));1212+1313+ return dec;1414+}1515+EOF
+14
scripts/atomic/fallbacks/dec_unless_positive
···11+cat <<EOF22+static inline bool33+${atomic}_dec_unless_positive(${atomic}_t *v)44+{55+ ${int} c = ${atomic}_read(v);66+77+ do {88+ if (unlikely(c > 0))99+ return false;1010+ } while (!${atomic}_try_cmpxchg(v, &c, c - 1));1111+1212+ return true;1313+}1414+EOF
···11+cat << EOF22+/**33+ * ${atomic}_fetch_add_unless - add unless the number is already a given value44+ * @v: pointer of type ${atomic}_t55+ * @a: the amount to add to v...66+ * @u: ...unless v is equal to u.77+ *88+ * Atomically adds @a to @v, so long as @v was not already @u.99+ * Returns original value of @v1010+ */1111+static inline ${int}1212+${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)1313+{1414+ ${int} c = ${atomic}_read(v);1515+1616+ do {1717+ if (unlikely(c == u))1818+ break;1919+ } while (!${atomic}_try_cmpxchg(v, &c, c + a));2020+2121+ return c;2222+}2323+EOF
···11+cat <<EOF22+/**33+ * ${atomic}_inc_and_test - increment and test44+ * @v: pointer of type ${atomic}_t55+ *66+ * Atomically increments @v by 177+ * and returns true if the result is zero, or false for all88+ * other cases.99+ */1010+static inline bool1111+${atomic}_inc_and_test(${atomic}_t *v)1212+{1313+ return ${atomic}_inc_return(v) == 0;1414+}1515+EOF
+14
scripts/atomic/fallbacks/inc_not_zero
···11+cat <<EOF22+/**33+ * ${atomic}_inc_not_zero - increment unless the number is zero44+ * @v: pointer of type ${atomic}_t55+ *66+ * Atomically increments @v by 1, if @v is non-zero.77+ * Returns true if the increment was done.88+ */99+static inline bool1010+${atomic}_inc_not_zero(${atomic}_t *v)1111+{1212+ return ${atomic}_add_unless(v, 1, 0);1313+}1414+EOF
+14
scripts/atomic/fallbacks/inc_unless_negative
···11+cat <<EOF22+static inline bool33+${atomic}_inc_unless_negative(${atomic}_t *v)44+{55+ ${int} c = ${atomic}_read(v);66+77+ do {88+ if (unlikely(c < 0))99+ return false;1010+ } while (!${atomic}_try_cmpxchg(v, &c, c + 1));1111+1212+ return true;1313+}1414+EOF
···11+cat <<EOF22+/**33+ * ${atomic}_sub_and_test - subtract value from variable and test result44+ * @i: integer value to subtract55+ * @v: pointer of type ${atomic}_t66+ *77+ * Atomically subtracts @i from @v and returns88+ * true if the result is zero, or false for all99+ * other cases.1010+ */1111+static inline bool1212+${atomic}_sub_and_test(${int} i, ${atomic}_t *v)1313+{1414+ return ${atomic}_sub_return(i, v) == 0;1515+}1616+EOF
+11
scripts/atomic/fallbacks/try_cmpxchg
···11+cat <<EOF22+static inline bool33+${atomic}_try_cmpxchg${order}(${atomic}_t *v, ${int} *old, ${int} new)44+{55+ ${int} r, o = *old;66+ r = ${atomic}_cmpxchg${order}(v, o, new);77+ if (unlikely(r != o))88+ *old = r;99+ return likely(r == o);1010+}1111+EOF
+181
scripts/atomic/gen-atomic-fallback.sh
···11+#!/bin/sh22+# SPDX-License-Identifier: GPL-2.033+44+ATOMICDIR=$(dirname $0)55+66+. ${ATOMICDIR}/atomic-tbl.sh77+88+#gen_template_fallback(template, meta, pfx, name, sfx, order, atomic, int, args...)99+gen_template_fallback()1010+{1111+ local template="$1"; shift1212+ local meta="$1"; shift1313+ local pfx="$1"; shift1414+ local name="$1"; shift1515+ local sfx="$1"; shift1616+ local order="$1"; shift1717+ local atomic="$1"; shift1818+ local int="$1"; shift1919+2020+ local atomicname="${atomic}_${pfx}${name}${sfx}${order}"2121+2222+ local ret="$(gen_ret_type "${meta}" "${int}")"2323+ local retstmt="$(gen_ret_stmt "${meta}")"2424+ local params="$(gen_params "${int}" "${atomic}" "$@")"2525+ local args="$(gen_args "$@")"2626+2727+ if [ ! -z "${template}" ]; then2828+ printf "#ifndef ${atomicname}\n"2929+ . ${template}3030+ printf "#define ${atomicname} ${atomicname}\n"3131+ printf "#endif\n\n"3232+ fi3333+}3434+3535+#gen_proto_fallback(meta, pfx, name, sfx, order, atomic, int, args...)3636+gen_proto_fallback()3737+{3838+ local meta="$1"; shift3939+ local pfx="$1"; shift4040+ local name="$1"; shift4141+ local sfx="$1"; shift4242+ local order="$1"; shift4343+4444+ local tmpl="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"4545+ gen_template_fallback "${tmpl}" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "$@"4646+}4747+4848+#gen_basic_fallbacks(basename)4949+gen_basic_fallbacks()5050+{5151+ local basename="$1"; shift5252+cat << EOF5353+#define ${basename}_acquire ${basename}5454+#define ${basename}_release ${basename}5555+#define ${basename}_relaxed ${basename}5656+EOF5757+}5858+5959+#gen_proto_order_variants(meta, pfx, name, sfx, atomic, int, args...)6060+gen_proto_order_variants()6161+{6262+ local meta="$1"; shift6363+ local pfx="$1"; shift6464+ local name="$1"; shift6565+ local sfx="$1"; shift6666+ local atomic="$1"6767+6868+ local basename="${atomic}_${pfx}${name}${sfx}"6969+7070+ local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"7171+7272+ # If we don't have relaxed atomics, then we don't bother with ordering fallbacks7373+ # read_acquire and set_release need to be templated, though7474+ if ! meta_has_relaxed "${meta}"; then7575+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"7676+7777+ if meta_has_acquire "${meta}"; then7878+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"7979+ fi8080+8181+ if meta_has_release "${meta}"; then8282+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"8383+ fi8484+8585+ return8686+ fi8787+8888+ printf "#ifndef ${basename}_relaxed\n"8989+9090+ if [ ! -z "${template}" ]; then9191+ printf "#ifdef ${basename}\n"9292+ fi9393+9494+ gen_basic_fallbacks "${basename}"9595+9696+ if [ ! -z "${template}" ]; then9797+ printf "#endif /* ${atomic}_${pfx}${name}${sfx} */\n\n"9898+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"9999+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"100100+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"101101+ gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"102102+ fi103103+104104+ printf "#else /* ${basename}_relaxed */\n\n"105105+106106+ gen_template_fallback "${ATOMICDIR}/fallbacks/acquire" "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"107107+ gen_template_fallback "${ATOMICDIR}/fallbacks/release" "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"108108+ gen_template_fallback "${ATOMICDIR}/fallbacks/fence" "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"109109+110110+ printf "#endif /* ${basename}_relaxed */\n\n"111111+}112112+113113+gen_xchg_fallbacks()114114+{115115+ local xchg="$1"; shift116116+cat <<EOF117117+#ifndef ${xchg}_relaxed118118+#define ${xchg}_relaxed ${xchg}119119+#define ${xchg}_acquire ${xchg}120120+#define ${xchg}_release ${xchg}121121+#else /* ${xchg}_relaxed */122122+123123+#ifndef ${xchg}_acquire124124+#define ${xchg}_acquire(...) \\125125+ __atomic_op_acquire(${xchg}, __VA_ARGS__)126126+#endif127127+128128+#ifndef ${xchg}_release129129+#define ${xchg}_release(...) \\130130+ __atomic_op_release(${xchg}, __VA_ARGS__)131131+#endif132132+133133+#ifndef ${xchg}134134+#define ${xchg}(...) \\135135+ __atomic_op_fence(${xchg}, __VA_ARGS__)136136+#endif137137+138138+#endif /* ${xchg}_relaxed */139139+140140+EOF141141+}142142+143143+cat << EOF144144+// SPDX-License-Identifier: GPL-2.0145145+146146+// Generated by $0147147+// DO NOT MODIFY THIS FILE DIRECTLY148148+149149+#ifndef _LINUX_ATOMIC_FALLBACK_H150150+#define _LINUX_ATOMIC_FALLBACK_H151151+152152+EOF153153+154154+for xchg in "xchg" "cmpxchg" "cmpxchg64"; do155155+ gen_xchg_fallbacks "${xchg}"156156+done157157+158158+grep '^[a-z]' "$1" | while read name meta args; do159159+ gen_proto "${meta}" "${name}" "atomic" "int" ${args}160160+done161161+162162+cat <<EOF163163+#define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))164164+#define atomic_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))165165+166166+#ifdef CONFIG_GENERIC_ATOMIC64167167+#include <asm-generic/atomic64.h>168168+#endif169169+170170+EOF171171+172172+grep '^[a-z]' "$1" | while read name meta args; do173173+ gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}174174+done175175+176176+cat <<EOF177177+#define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))178178+#define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))179179+180180+#endif /* _LINUX_ATOMIC_FALLBACK_H */181181+EOF
+182
scripts/atomic/gen-atomic-instrumented.sh
···11+#!/bin/sh22+# SPDX-License-Identifier: GPL-2.033+44+ATOMICDIR=$(dirname $0)55+66+. ${ATOMICDIR}/atomic-tbl.sh77+88+#gen_param_check(arg)99+gen_param_check()1010+{1111+ local arg="$1"; shift1212+ local type="${arg%%:*}"1313+ local name="$(gen_param_name "${arg}")"1414+ local rw="write"1515+1616+ case "${type#c}" in1717+ i) return;;1818+ esac1919+2020+ # We don't write to constant parameters2121+ [ ${type#c} != ${type} ] && rw="read"2222+2323+ printf "\tkasan_check_${rw}(${name}, sizeof(*${name}));\n"2424+}2525+2626+#gen_param_check(arg...)2727+gen_params_checks()2828+{2929+ while [ "$#" -gt 0 ]; do3030+ gen_param_check "$1"3131+ shift;3232+ done3333+}3434+3535+# gen_guard(meta, atomic, pfx, name, sfx, order)3636+gen_guard()3737+{3838+ local meta="$1"; shift3939+ local atomic="$1"; shift4040+ local pfx="$1"; shift4141+ local name="$1"; shift4242+ local sfx="$1"; shift4343+ local order="$1"; shift4444+4545+ local atomicname="arch_${atomic}_${pfx}${name}${sfx}${order}"4646+4747+ local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"4848+4949+ # We definitely need a preprocessor symbol for this atomic if it is an5050+ # ordering variant, or if there's a generic fallback.5151+ if [ ! -z "${order}" ] || [ ! -z "${template}" ]; then5252+ printf "defined(${atomicname})"5353+ return5454+ fi5555+5656+ # If this is a base variant, but a relaxed variant *may* exist, then we5757+ # only have a preprocessor symbol if the relaxed variant isn't defined5858+ if meta_has_relaxed "${meta}"; then5959+ printf "!defined(${atomicname}_relaxed) || defined(${atomicname})"6060+ fi6161+}6262+6363+#gen_proto_order_variant(meta, pfx, name, sfx, order, atomic, int, arg...)6464+gen_proto_order_variant()6565+{6666+ local meta="$1"; shift6767+ local pfx="$1"; shift6868+ local name="$1"; shift6969+ local sfx="$1"; shift7070+ local order="$1"; shift7171+ local atomic="$1"; shift7272+ local int="$1"; shift7373+7474+ local atomicname="${atomic}_${pfx}${name}${sfx}${order}"7575+7676+ local guard="$(gen_guard "${meta}" "${atomic}" "${pfx}" "${name}" "${sfx}" "${order}")"7777+7878+ local ret="$(gen_ret_type "${meta}" "${int}")"7979+ local params="$(gen_params "${int}" "${atomic}" "$@")"8080+ local checks="$(gen_params_checks "$@")"8181+ local args="$(gen_args "$@")"8282+ local retstmt="$(gen_ret_stmt "${meta}")"8383+8484+ [ ! -z "${guard}" ] && printf "#if ${guard}\n"8585+8686+cat <<EOF8787+static inline ${ret}8888+${atomicname}(${params})8989+{9090+${checks}9191+ ${retstmt}arch_${atomicname}(${args});9292+}9393+#define ${atomicname} ${atomicname}9494+EOF9595+9696+ [ ! -z "${guard}" ] && printf "#endif\n"9797+9898+ printf "\n"9999+}100100+101101+gen_xchg()102102+{103103+ local xchg="$1"; shift104104+ local mult="$1"; shift105105+106106+cat <<EOF107107+#define ${xchg}(ptr, ...) \\108108+({ \\109109+ typeof(ptr) __ai_ptr = (ptr); \\110110+ kasan_check_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\111111+ arch_${xchg}(__ai_ptr, __VA_ARGS__); \\112112+})113113+EOF114114+}115115+116116+gen_optional_xchg()117117+{118118+ local name="$1"; shift119119+ local sfx="$1"; shift120120+ local guard="defined(arch_${name}${sfx})"121121+122122+ [ -z "${sfx}" ] && guard="!defined(arch_${name}_relaxed) || defined(arch_${name})"123123+124124+ printf "#if ${guard}\n"125125+ gen_xchg "${name}${sfx}" ""126126+ printf "#endif\n\n"127127+}128128+129129+cat << EOF130130+// SPDX-License-Identifier: GPL-2.0131131+132132+// Generated by $0133133+// DO NOT MODIFY THIS FILE DIRECTLY134134+135135+/*136136+ * This file provides wrappers with KASAN instrumentation for atomic operations.137137+ * To use this functionality an arch's atomic.h file needs to define all138138+ * atomic operations with arch_ prefix (e.g. arch_atomic_read()) and include139139+ * this file at the end. This file provides atomic_read() that forwards to140140+ * arch_atomic_read() for actual atomic operation.141141+ * Note: if an arch atomic operation is implemented by means of other atomic142142+ * operations (e.g. atomic_read()/atomic_cmpxchg() loop), then it needs to use143143+ * arch_ variants (i.e. arch_atomic_read()/arch_atomic_cmpxchg()) to avoid144144+ * double instrumentation.145145+ */146146+#ifndef _ASM_GENERIC_ATOMIC_INSTRUMENTED_H147147+#define _ASM_GENERIC_ATOMIC_INSTRUMENTED_H148148+149149+#include <linux/build_bug.h>150150+#include <linux/kasan-checks.h>151151+152152+EOF153153+154154+grep '^[a-z]' "$1" | while read name meta args; do155155+ gen_proto "${meta}" "${name}" "atomic" "int" ${args}156156+done157157+158158+grep '^[a-z]' "$1" | while read name meta args; do159159+ gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}160160+done161161+162162+for xchg in "xchg" "cmpxchg" "cmpxchg64"; do163163+ for order in "" "_acquire" "_release" "_relaxed"; do164164+ gen_optional_xchg "${xchg}" "${order}"165165+ done166166+done167167+168168+for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg"; do169169+ gen_xchg "${xchg}" ""170170+ printf "\n"171171+done172172+173173+gen_xchg "cmpxchg_double" "2 * "174174+175175+printf "\n\n"176176+177177+gen_xchg "cmpxchg_double_local" "2 * "178178+179179+cat <<EOF180180+181181+#endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_H */182182+EOF
+101
scripts/atomic/gen-atomic-long.sh
···11+#!/bin/sh22+# SPDX-License-Identifier: GPL-2.033+44+ATOMICDIR=$(dirname $0)55+66+. ${ATOMICDIR}/atomic-tbl.sh77+88+#gen_cast(arg, int, atomic)99+gen_cast()1010+{1111+ local arg="$1"; shift1212+ local int="$1"; shift1313+ local atomic="$1"; shift1414+1515+ [ "${arg%%:*}" = "p" ] || return1616+1717+ printf "($(gen_param_type "${arg}" "${int}" "${atomic}"))"1818+}1919+2020+#gen_args_cast(int, atomic, arg...)2121+gen_args_cast()2222+{2323+ local int="$1"; shift2424+ local atomic="$1"; shift2525+2626+ while [ "$#" -gt 0 ]; do2727+ local cast="$(gen_cast "$1" "${int}" "${atomic}")"2828+ local arg="$(gen_param_name "$1")"2929+ printf "${cast}${arg}"3030+ [ "$#" -gt 1 ] && printf ", "3131+ shift;3232+ done3333+}3434+3535+#gen_proto_order_variant(meta, pfx, name, sfx, order, atomic, int, arg...)3636+gen_proto_order_variant()3737+{3838+ local meta="$1"; shift3939+ local name="$1$2$3$4"; shift; shift; shift; shift4040+ local atomic="$1"; shift4141+ local int="$1"; shift4242+4343+ local ret="$(gen_ret_type "${meta}" "long")"4444+ local params="$(gen_params "long" "atomic_long" "$@")"4545+ local argscast="$(gen_args_cast "${int}" "${atomic}" "$@")"4646+ local retstmt="$(gen_ret_stmt "${meta}")"4747+4848+cat <<EOF4949+static inline ${ret}5050+atomic_long_${name}(${params})5151+{5252+ ${retstmt}${atomic}_${name}(${argscast});5353+}5454+5555+EOF5656+}5757+5858+cat << EOF5959+// SPDX-License-Identifier: GPL-2.06060+6161+// Generated by $06262+// DO NOT MODIFY THIS FILE DIRECTLY6363+6464+#ifndef _ASM_GENERIC_ATOMIC_LONG_H6565+#define _ASM_GENERIC_ATOMIC_LONG_H6666+6767+#include <asm/types.h>6868+6969+#ifdef CONFIG_64BIT7070+typedef atomic64_t atomic_long_t;7171+#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)7272+#define atomic_long_cond_read_acquire atomic64_cond_read_acquire7373+#define atomic_long_cond_read_relaxed atomic64_cond_read_relaxed7474+#else7575+typedef atomic_t atomic_long_t;7676+#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)7777+#define atomic_long_cond_read_acquire atomic_cond_read_acquire7878+#define atomic_long_cond_read_relaxed atomic_cond_read_relaxed7979+#endif8080+8181+#ifdef CONFIG_64BIT8282+8383+EOF8484+8585+grep '^[a-z]' "$1" | while read name meta args; do8686+ gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}8787+done8888+8989+cat <<EOF9090+#else /* CONFIG_64BIT */9191+9292+EOF9393+9494+grep '^[a-z]' "$1" | while read name meta args; do9595+ gen_proto "${meta}" "${name}" "atomic" "int" ${args}9696+done9797+9898+cat <<EOF9999+#endif /* CONFIG_64BIT */100100+#endif /* _ASM_GENERIC_ATOMIC_LONG_H */101101+EOF