summaryrefslogtreecommitdiffstats
path: root/include/linux/atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/atomic.h')
-rw-r--r--include/linux/atomic.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 530562ac7909..3ee8da9023cd 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -569,6 +569,68 @@ static inline bool atomic_add_unless(atomic_t *v, int a, int u)
569#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) 569#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
570#endif 570#endif
571 571
572/**
573 * atomic_inc_and_test - increment and test
574 * @v: pointer of type atomic_t
575 *
576 * Atomically increments @v by 1
577 * and returns true if the result is zero, or false for all
578 * other cases.
579 */
580#ifndef atomic_inc_and_test
581static inline bool atomic_inc_and_test(atomic_t *v)
582{
583 return atomic_inc_return(v) == 0;
584}
585#endif
586
587/**
588 * atomic_dec_and_test - decrement and test
589 * @v: pointer of type atomic_t
590 *
591 * Atomically decrements @v by 1 and
592 * returns true if the result is 0, or false for all other
593 * cases.
594 */
595#ifndef atomic_dec_and_test
596static inline bool atomic_dec_and_test(atomic_t *v)
597{
598 return atomic_dec_return(v) == 0;
599}
600#endif
601
602/**
603 * atomic_sub_and_test - subtract value from variable and test result
604 * @i: integer value to subtract
605 * @v: pointer of type atomic_t
606 *
607 * Atomically subtracts @i from @v and returns
608 * true if the result is zero, or false for all
609 * other cases.
610 */
611#ifndef atomic_sub_and_test
612static inline bool atomic_sub_and_test(int i, atomic_t *v)
613{
614 return atomic_sub_return(i, v) == 0;
615}
616#endif
617
618/**
619 * atomic_add_negative - add and test if negative
620 * @i: integer value to add
621 * @v: pointer of type atomic_t
622 *
623 * Atomically adds @i to @v and returns true
624 * if the result is negative, or false when
625 * result is greater than or equal to zero.
626 */
627#ifndef atomic_add_negative
628static inline bool atomic_add_negative(int i, atomic_t *v)
629{
630 return atomic_add_return(i, v) < 0;
631}
632#endif
633
572#ifndef atomic_andnot 634#ifndef atomic_andnot
573static inline void atomic_andnot(int i, atomic_t *v) 635static inline void atomic_andnot(int i, atomic_t *v)
574{ 636{
@@ -1091,6 +1153,68 @@ static inline bool atomic64_add_unless(atomic64_t *v, long long a, long long u)
1091#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) 1153#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
1092#endif 1154#endif
1093 1155
1156/**
1157 * atomic64_inc_and_test - increment and test
1158 * @v: pointer of type atomic64_t
1159 *
1160 * Atomically increments @v by 1
1161 * and returns true if the result is zero, or false for all
1162 * other cases.
1163 */
1164#ifndef atomic64_inc_and_test
1165static inline bool atomic64_inc_and_test(atomic64_t *v)
1166{
1167 return atomic64_inc_return(v) == 0;
1168}
1169#endif
1170
1171/**
1172 * atomic64_dec_and_test - decrement and test
1173 * @v: pointer of type atomic64_t
1174 *
1175 * Atomically decrements @v by 1 and
1176 * returns true if the result is 0, or false for all other
1177 * cases.
1178 */
1179#ifndef atomic64_dec_and_test
1180static inline bool atomic64_dec_and_test(atomic64_t *v)
1181{
1182 return atomic64_dec_return(v) == 0;
1183}
1184#endif
1185
1186/**
1187 * atomic64_sub_and_test - subtract value from variable and test result
1188 * @i: integer value to subtract
1189 * @v: pointer of type atomic64_t
1190 *
1191 * Atomically subtracts @i from @v and returns
1192 * true if the result is zero, or false for all
1193 * other cases.
1194 */
1195#ifndef atomic64_sub_and_test
1196static inline bool atomic64_sub_and_test(long long i, atomic64_t *v)
1197{
1198 return atomic64_sub_return(i, v) == 0;
1199}
1200#endif
1201
1202/**
1203 * atomic64_add_negative - add and test if negative
1204 * @i: integer value to add
1205 * @v: pointer of type atomic64_t
1206 *
1207 * Atomically adds @i to @v and returns true
1208 * if the result is negative, or false when
1209 * result is greater than or equal to zero.
1210 */
1211#ifndef atomic64_add_negative
1212static inline bool atomic64_add_negative(long long i, atomic64_t *v)
1213{
1214 return atomic64_add_return(i, v) < 0;
1215}
1216#endif
1217
1094#ifndef atomic64_andnot 1218#ifndef atomic64_andnot
1095static inline void atomic64_andnot(long long i, atomic64_t *v) 1219static inline void atomic64_andnot(long long i, atomic64_t *v)
1096{ 1220{