atomic.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Atomic operations that C can't guarantee us. Useful for
  3. * resource counting etc..
  4. *
  5. * But use these as seldom as possible since they are much more slower
  6. * than regular operations.
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. *
  12. * Copyright (C) 1996, 97, 99, 2000, 03, 04 by Ralf Baechle
  13. */
  14. /*
  15. * As workaround for the ATOMIC_DEC_AND_LOCK / atomic_dec_and_lock mess in
  16. * <linux/spinlock.h> we have to include <linux/spinlock.h> outside the
  17. * main big wrapper ...
  18. */
  19. #include <linux/config.h>
  20. #include <linux/spinlock.h>
  21. #ifndef _ASM_ATOMIC_H
  22. #define _ASM_ATOMIC_H
  23. #include <asm/cpu-features.h>
  24. #include <asm/war.h>
  25. extern spinlock_t atomic_lock;
  26. typedef struct { volatile int counter; } atomic_t;
  27. #define ATOMIC_INIT(i) { (i) }
  28. /*
  29. * atomic_read - read atomic variable
  30. * @v: pointer of type atomic_t
  31. *
  32. * Atomically reads the value of @v.
  33. */
  34. #define atomic_read(v) ((v)->counter)
  35. /*
  36. * atomic_set - set atomic variable
  37. * @v: pointer of type atomic_t
  38. * @i: required value
  39. *
  40. * Atomically sets the value of @v to @i.
  41. */
  42. #define atomic_set(v,i) ((v)->counter = (i))
  43. /*
  44. * atomic_add - add integer to atomic variable
  45. * @i: integer value to add
  46. * @v: pointer of type atomic_t
  47. *
  48. * Atomically adds @i to @v.
  49. */
  50. static __inline__ void atomic_add(int i, atomic_t * v)
  51. {
  52. if (cpu_has_llsc && R10000_LLSC_WAR) {
  53. unsigned long temp;
  54. __asm__ __volatile__(
  55. " .set mips3 \n"
  56. "1: ll %0, %1 # atomic_add \n"
  57. " addu %0, %2 \n"
  58. " sc %0, %1 \n"
  59. " beqzl %0, 1b \n"
  60. " .set mips0 \n"
  61. : "=&r" (temp), "=m" (v->counter)
  62. : "Ir" (i), "m" (v->counter));
  63. } else if (cpu_has_llsc) {
  64. unsigned long temp;
  65. __asm__ __volatile__(
  66. " .set mips3 \n"
  67. "1: ll %0, %1 # atomic_add \n"
  68. " addu %0, %2 \n"
  69. " sc %0, %1 \n"
  70. " beqz %0, 1b \n"
  71. " .set mips0 \n"
  72. : "=&r" (temp), "=m" (v->counter)
  73. : "Ir" (i), "m" (v->counter));
  74. } else {
  75. unsigned long flags;
  76. spin_lock_irqsave(&atomic_lock, flags);
  77. v->counter += i;
  78. spin_unlock_irqrestore(&atomic_lock, flags);
  79. }
  80. }
  81. /*
  82. * atomic_sub - subtract the atomic variable
  83. * @i: integer value to subtract
  84. * @v: pointer of type atomic_t
  85. *
  86. * Atomically subtracts @i from @v.
  87. */
  88. static __inline__ void atomic_sub(int i, atomic_t * v)
  89. {
  90. if (cpu_has_llsc && R10000_LLSC_WAR) {
  91. unsigned long temp;
  92. __asm__ __volatile__(
  93. " .set mips3 \n"
  94. "1: ll %0, %1 # atomic_sub \n"
  95. " subu %0, %2 \n"
  96. " sc %0, %1 \n"
  97. " beqzl %0, 1b \n"
  98. " .set mips0 \n"
  99. : "=&r" (temp), "=m" (v->counter)
  100. : "Ir" (i), "m" (v->counter));
  101. } else if (cpu_has_llsc) {
  102. unsigned long temp;
  103. __asm__ __volatile__(
  104. " .set mips3 \n"
  105. "1: ll %0, %1 # atomic_sub \n"
  106. " subu %0, %2 \n"
  107. " sc %0, %1 \n"
  108. " beqz %0, 1b \n"
  109. " .set mips0 \n"
  110. : "=&r" (temp), "=m" (v->counter)
  111. : "Ir" (i), "m" (v->counter));
  112. } else {
  113. unsigned long flags;
  114. spin_lock_irqsave(&atomic_lock, flags);
  115. v->counter -= i;
  116. spin_unlock_irqrestore(&atomic_lock, flags);
  117. }
  118. }
  119. /*
  120. * Same as above, but return the result value
  121. */
  122. static __inline__ int atomic_add_return(int i, atomic_t * v)
  123. {
  124. unsigned long result;
  125. if (cpu_has_llsc && R10000_LLSC_WAR) {
  126. unsigned long temp;
  127. __asm__ __volatile__(
  128. " .set mips3 \n"
  129. "1: ll %1, %2 # atomic_add_return \n"
  130. " addu %0, %1, %3 \n"
  131. " sc %0, %2 \n"
  132. " beqzl %0, 1b \n"
  133. " addu %0, %1, %3 \n"
  134. " sync \n"
  135. " .set mips0 \n"
  136. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  137. : "Ir" (i), "m" (v->counter)
  138. : "memory");
  139. } else if (cpu_has_llsc) {
  140. unsigned long temp;
  141. __asm__ __volatile__(
  142. " .set mips3 \n"
  143. "1: ll %1, %2 # atomic_add_return \n"
  144. " addu %0, %1, %3 \n"
  145. " sc %0, %2 \n"
  146. " beqz %0, 1b \n"
  147. " addu %0, %1, %3 \n"
  148. " sync \n"
  149. " .set mips0 \n"
  150. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  151. : "Ir" (i), "m" (v->counter)
  152. : "memory");
  153. } else {
  154. unsigned long flags;
  155. spin_lock_irqsave(&atomic_lock, flags);
  156. result = v->counter;
  157. result += i;
  158. v->counter = result;
  159. spin_unlock_irqrestore(&atomic_lock, flags);
  160. }
  161. return result;
  162. }
  163. static __inline__ int atomic_sub_return(int i, atomic_t * v)
  164. {
  165. unsigned long result;
  166. if (cpu_has_llsc && R10000_LLSC_WAR) {
  167. unsigned long temp;
  168. __asm__ __volatile__(
  169. " .set mips3 \n"
  170. "1: ll %1, %2 # atomic_sub_return \n"
  171. " subu %0, %1, %3 \n"
  172. " sc %0, %2 \n"
  173. " beqzl %0, 1b \n"
  174. " subu %0, %1, %3 \n"
  175. " sync \n"
  176. " .set mips0 \n"
  177. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  178. : "Ir" (i), "m" (v->counter)
  179. : "memory");
  180. } else if (cpu_has_llsc) {
  181. unsigned long temp;
  182. __asm__ __volatile__(
  183. " .set mips3 \n"
  184. "1: ll %1, %2 # atomic_sub_return \n"
  185. " subu %0, %1, %3 \n"
  186. " sc %0, %2 \n"
  187. " beqz %0, 1b \n"
  188. " subu %0, %1, %3 \n"
  189. " sync \n"
  190. " .set mips0 \n"
  191. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  192. : "Ir" (i), "m" (v->counter)
  193. : "memory");
  194. } else {
  195. unsigned long flags;
  196. spin_lock_irqsave(&atomic_lock, flags);
  197. result = v->counter;
  198. result -= i;
  199. v->counter = result;
  200. spin_unlock_irqrestore(&atomic_lock, flags);
  201. }
  202. return result;
  203. }
  204. /*
  205. * atomic_sub_if_positive - add integer to atomic variable
  206. * @v: pointer of type atomic_t
  207. *
  208. * Atomically test @v and decrement if it is greater than 0.
  209. * The function returns the old value of @v minus 1.
  210. */
  211. static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
  212. {
  213. unsigned long result;
  214. if (cpu_has_llsc && R10000_LLSC_WAR) {
  215. unsigned long temp;
  216. __asm__ __volatile__(
  217. " .set mips3 \n"
  218. "1: ll %1, %2 # atomic_sub_if_positive\n"
  219. " subu %0, %1, %3 \n"
  220. " bltz %0, 1f \n"
  221. " sc %0, %2 \n"
  222. " beqzl %0, 1b \n"
  223. " sync \n"
  224. "1: \n"
  225. " .set mips0 \n"
  226. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  227. : "Ir" (i), "m" (v->counter)
  228. : "memory");
  229. } else if (cpu_has_llsc) {
  230. unsigned long temp;
  231. __asm__ __volatile__(
  232. " .set mips3 \n"
  233. "1: ll %1, %2 # atomic_sub_if_positive\n"
  234. " subu %0, %1, %3 \n"
  235. " bltz %0, 1f \n"
  236. " sc %0, %2 \n"
  237. " beqz %0, 1b \n"
  238. " sync \n"
  239. "1: \n"
  240. " .set mips0 \n"
  241. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  242. : "Ir" (i), "m" (v->counter)
  243. : "memory");
  244. } else {
  245. unsigned long flags;
  246. spin_lock_irqsave(&atomic_lock, flags);
  247. result = v->counter;
  248. result -= i;
  249. if (result >= 0)
  250. v->counter = result;
  251. spin_unlock_irqrestore(&atomic_lock, flags);
  252. }
  253. return result;
  254. }
  255. #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
  256. /**
  257. * atomic_add_unless - add unless the number is a given value
  258. * @v: pointer of type atomic_t
  259. * @a: the amount to add to v...
  260. * @u: ...unless v is equal to u.
  261. *
  262. * Atomically adds @a to @v, so long as it was not @u.
  263. * Returns non-zero if @v was not @u, and zero otherwise.
  264. */
  265. #define atomic_add_unless(v, a, u) \
  266. ({ \
  267. int c, old; \
  268. c = atomic_read(v); \
  269. while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
  270. c = old; \
  271. c != (u); \
  272. })
  273. #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
  274. #define atomic_dec_return(v) atomic_sub_return(1,(v))
  275. #define atomic_inc_return(v) atomic_add_return(1,(v))
  276. /*
  277. * atomic_sub_and_test - subtract value from variable and test result
  278. * @i: integer value to subtract
  279. * @v: pointer of type atomic_t
  280. *
  281. * Atomically subtracts @i from @v and returns
  282. * true if the result is zero, or false for all
  283. * other cases.
  284. */
  285. #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
  286. /*
  287. * atomic_inc_and_test - increment and test
  288. * @v: pointer of type atomic_t
  289. *
  290. * Atomically increments @v by 1
  291. * and returns true if the result is zero, or false for all
  292. * other cases.
  293. */
  294. #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
  295. /*
  296. * atomic_dec_and_test - decrement by 1 and test
  297. * @v: pointer of type atomic_t
  298. *
  299. * Atomically decrements @v by 1 and
  300. * returns true if the result is 0, or false for all other
  301. * cases.
  302. */
  303. #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
  304. /*
  305. * atomic_dec_if_positive - decrement by 1 if old value positive
  306. * @v: pointer of type atomic_t
  307. */
  308. #define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v)
  309. /*
  310. * atomic_inc - increment atomic variable
  311. * @v: pointer of type atomic_t
  312. *
  313. * Atomically increments @v by 1.
  314. */
  315. #define atomic_inc(v) atomic_add(1,(v))
  316. /*
  317. * atomic_dec - decrement and test
  318. * @v: pointer of type atomic_t
  319. *
  320. * Atomically decrements @v by 1.
  321. */
  322. #define atomic_dec(v) atomic_sub(1,(v))
  323. /*
  324. * atomic_add_negative - add and test if negative
  325. * @v: pointer of type atomic_t
  326. * @i: integer value to add
  327. *
  328. * Atomically adds @i to @v and returns true
  329. * if the result is negative, or false when
  330. * result is greater than or equal to zero.
  331. */
  332. #define atomic_add_negative(i,v) (atomic_add_return(i, (v)) < 0)
  333. #ifdef CONFIG_64BIT
  334. typedef struct { volatile __s64 counter; } atomic64_t;
  335. #define ATOMIC64_INIT(i) { (i) }
  336. /*
  337. * atomic64_read - read atomic variable
  338. * @v: pointer of type atomic64_t
  339. *
  340. */
  341. #define atomic64_read(v) ((v)->counter)
  342. /*
  343. * atomic64_set - set atomic variable
  344. * @v: pointer of type atomic64_t
  345. * @i: required value
  346. */
  347. #define atomic64_set(v,i) ((v)->counter = (i))
  348. /*
  349. * atomic64_add - add integer to atomic variable
  350. * @i: integer value to add
  351. * @v: pointer of type atomic64_t
  352. *
  353. * Atomically adds @i to @v.
  354. */
  355. static __inline__ void atomic64_add(long i, atomic64_t * v)
  356. {
  357. if (cpu_has_llsc && R10000_LLSC_WAR) {
  358. unsigned long temp;
  359. __asm__ __volatile__(
  360. " .set mips3 \n"
  361. "1: lld %0, %1 # atomic64_add \n"
  362. " addu %0, %2 \n"
  363. " scd %0, %1 \n"
  364. " beqzl %0, 1b \n"
  365. " .set mips0 \n"
  366. : "=&r" (temp), "=m" (v->counter)
  367. : "Ir" (i), "m" (v->counter));
  368. } else if (cpu_has_llsc) {
  369. unsigned long temp;
  370. __asm__ __volatile__(
  371. " .set mips3 \n"
  372. "1: lld %0, %1 # atomic64_add \n"
  373. " addu %0, %2 \n"
  374. " scd %0, %1 \n"
  375. " beqz %0, 1b \n"
  376. " .set mips0 \n"
  377. : "=&r" (temp), "=m" (v->counter)
  378. : "Ir" (i), "m" (v->counter));
  379. } else {
  380. unsigned long flags;
  381. spin_lock_irqsave(&atomic_lock, flags);
  382. v->counter += i;
  383. spin_unlock_irqrestore(&atomic_lock, flags);
  384. }
  385. }
  386. /*
  387. * atomic64_sub - subtract the atomic variable
  388. * @i: integer value to subtract
  389. * @v: pointer of type atomic64_t
  390. *
  391. * Atomically subtracts @i from @v.
  392. */
  393. static __inline__ void atomic64_sub(long i, atomic64_t * v)
  394. {
  395. if (cpu_has_llsc && R10000_LLSC_WAR) {
  396. unsigned long temp;
  397. __asm__ __volatile__(
  398. " .set mips3 \n"
  399. "1: lld %0, %1 # atomic64_sub \n"
  400. " subu %0, %2 \n"
  401. " scd %0, %1 \n"
  402. " beqzl %0, 1b \n"
  403. " .set mips0 \n"
  404. : "=&r" (temp), "=m" (v->counter)
  405. : "Ir" (i), "m" (v->counter));
  406. } else if (cpu_has_llsc) {
  407. unsigned long temp;
  408. __asm__ __volatile__(
  409. " .set mips3 \n"
  410. "1: lld %0, %1 # atomic64_sub \n"
  411. " subu %0, %2 \n"
  412. " scd %0, %1 \n"
  413. " beqz %0, 1b \n"
  414. " .set mips0 \n"
  415. : "=&r" (temp), "=m" (v->counter)
  416. : "Ir" (i), "m" (v->counter));
  417. } else {
  418. unsigned long flags;
  419. spin_lock_irqsave(&atomic_lock, flags);
  420. v->counter -= i;
  421. spin_unlock_irqrestore(&atomic_lock, flags);
  422. }
  423. }
  424. /*
  425. * Same as above, but return the result value
  426. */
  427. static __inline__ long atomic64_add_return(long i, atomic64_t * v)
  428. {
  429. unsigned long result;
  430. if (cpu_has_llsc && R10000_LLSC_WAR) {
  431. unsigned long temp;
  432. __asm__ __volatile__(
  433. " .set mips3 \n"
  434. "1: lld %1, %2 # atomic64_add_return \n"
  435. " addu %0, %1, %3 \n"
  436. " scd %0, %2 \n"
  437. " beqzl %0, 1b \n"
  438. " addu %0, %1, %3 \n"
  439. " sync \n"
  440. " .set mips0 \n"
  441. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  442. : "Ir" (i), "m" (v->counter)
  443. : "memory");
  444. } else if (cpu_has_llsc) {
  445. unsigned long temp;
  446. __asm__ __volatile__(
  447. " .set mips3 \n"
  448. "1: lld %1, %2 # atomic64_add_return \n"
  449. " addu %0, %1, %3 \n"
  450. " scd %0, %2 \n"
  451. " beqz %0, 1b \n"
  452. " addu %0, %1, %3 \n"
  453. " sync \n"
  454. " .set mips0 \n"
  455. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  456. : "Ir" (i), "m" (v->counter)
  457. : "memory");
  458. } else {
  459. unsigned long flags;
  460. spin_lock_irqsave(&atomic_lock, flags);
  461. result = v->counter;
  462. result += i;
  463. v->counter = result;
  464. spin_unlock_irqrestore(&atomic_lock, flags);
  465. }
  466. return result;
  467. }
  468. static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
  469. {
  470. unsigned long result;
  471. if (cpu_has_llsc && R10000_LLSC_WAR) {
  472. unsigned long temp;
  473. __asm__ __volatile__(
  474. " .set mips3 \n"
  475. "1: lld %1, %2 # atomic64_sub_return \n"
  476. " subu %0, %1, %3 \n"
  477. " scd %0, %2 \n"
  478. " beqzl %0, 1b \n"
  479. " subu %0, %1, %3 \n"
  480. " sync \n"
  481. " .set mips0 \n"
  482. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  483. : "Ir" (i), "m" (v->counter)
  484. : "memory");
  485. } else if (cpu_has_llsc) {
  486. unsigned long temp;
  487. __asm__ __volatile__(
  488. " .set mips3 \n"
  489. "1: lld %1, %2 # atomic64_sub_return \n"
  490. " subu %0, %1, %3 \n"
  491. " scd %0, %2 \n"
  492. " beqz %0, 1b \n"
  493. " subu %0, %1, %3 \n"
  494. " sync \n"
  495. " .set mips0 \n"
  496. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  497. : "Ir" (i), "m" (v->counter)
  498. : "memory");
  499. } else {
  500. unsigned long flags;
  501. spin_lock_irqsave(&atomic_lock, flags);
  502. result = v->counter;
  503. result -= i;
  504. v->counter = result;
  505. spin_unlock_irqrestore(&atomic_lock, flags);
  506. }
  507. return result;
  508. }
  509. /*
  510. * atomic64_sub_if_positive - add integer to atomic variable
  511. * @v: pointer of type atomic64_t
  512. *
  513. * Atomically test @v and decrement if it is greater than 0.
  514. * The function returns the old value of @v minus 1.
  515. */
  516. static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
  517. {
  518. unsigned long result;
  519. if (cpu_has_llsc && R10000_LLSC_WAR) {
  520. unsigned long temp;
  521. __asm__ __volatile__(
  522. " .set mips3 \n"
  523. "1: lld %1, %2 # atomic64_sub_if_positive\n"
  524. " dsubu %0, %1, %3 \n"
  525. " bltz %0, 1f \n"
  526. " scd %0, %2 \n"
  527. " beqzl %0, 1b \n"
  528. " sync \n"
  529. "1: \n"
  530. " .set mips0 \n"
  531. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  532. : "Ir" (i), "m" (v->counter)
  533. : "memory");
  534. } else if (cpu_has_llsc) {
  535. unsigned long temp;
  536. __asm__ __volatile__(
  537. " .set mips3 \n"
  538. "1: lld %1, %2 # atomic64_sub_if_positive\n"
  539. " dsubu %0, %1, %3 \n"
  540. " bltz %0, 1f \n"
  541. " scd %0, %2 \n"
  542. " beqz %0, 1b \n"
  543. " sync \n"
  544. "1: \n"
  545. " .set mips0 \n"
  546. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  547. : "Ir" (i), "m" (v->counter)
  548. : "memory");
  549. } else {
  550. unsigned long flags;
  551. spin_lock_irqsave(&atomic_lock, flags);
  552. result = v->counter;
  553. result -= i;
  554. if (result >= 0)
  555. v->counter = result;
  556. spin_unlock_irqrestore(&atomic_lock, flags);
  557. }
  558. return result;
  559. }
  560. #define atomic64_dec_return(v) atomic64_sub_return(1,(v))
  561. #define atomic64_inc_return(v) atomic64_add_return(1,(v))
  562. /*
  563. * atomic64_sub_and_test - subtract value from variable and test result
  564. * @i: integer value to subtract
  565. * @v: pointer of type atomic64_t
  566. *
  567. * Atomically subtracts @i from @v and returns
  568. * true if the result is zero, or false for all
  569. * other cases.
  570. */
  571. #define atomic64_sub_and_test(i,v) (atomic64_sub_return((i), (v)) == 0)
  572. /*
  573. * atomic64_inc_and_test - increment and test
  574. * @v: pointer of type atomic64_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. #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
  581. /*
  582. * atomic64_dec_and_test - decrement by 1 and test
  583. * @v: pointer of type atomic64_t
  584. *
  585. * Atomically decrements @v by 1 and
  586. * returns true if the result is 0, or false for all other
  587. * cases.
  588. */
  589. #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0)
  590. /*
  591. * atomic64_dec_if_positive - decrement by 1 if old value positive
  592. * @v: pointer of type atomic64_t
  593. */
  594. #define atomic64_dec_if_positive(v) atomic64_sub_if_positive(1, v)
  595. /*
  596. * atomic64_inc - increment atomic variable
  597. * @v: pointer of type atomic64_t
  598. *
  599. * Atomically increments @v by 1.
  600. */
  601. #define atomic64_inc(v) atomic64_add(1,(v))
  602. /*
  603. * atomic64_dec - decrement and test
  604. * @v: pointer of type atomic64_t
  605. *
  606. * Atomically decrements @v by 1.
  607. */
  608. #define atomic64_dec(v) atomic64_sub(1,(v))
  609. /*
  610. * atomic64_add_negative - add and test if negative
  611. * @v: pointer of type atomic64_t
  612. * @i: integer value to add
  613. *
  614. * Atomically adds @i to @v and returns true
  615. * if the result is negative, or false when
  616. * result is greater than or equal to zero.
  617. */
  618. #define atomic64_add_negative(i,v) (atomic64_add_return(i, (v)) < 0)
  619. #endif /* CONFIG_64BIT */
  620. /*
  621. * atomic*_return operations are serializing but not the non-*_return
  622. * versions.
  623. */
  624. #define smp_mb__before_atomic_dec() smp_mb()
  625. #define smp_mb__after_atomic_dec() smp_mb()
  626. #define smp_mb__before_atomic_inc() smp_mb()
  627. #define smp_mb__after_atomic_inc() smp_mb()
  628. #endif /* _ASM_ATOMIC_H */