atomic.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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_dec_return(v) atomic_sub_return(1,(v))
  256. #define atomic_inc_return(v) atomic_add_return(1,(v))
  257. /*
  258. * atomic_sub_and_test - subtract value from variable and test result
  259. * @i: integer value to subtract
  260. * @v: pointer of type atomic_t
  261. *
  262. * Atomically subtracts @i from @v and returns
  263. * true if the result is zero, or false for all
  264. * other cases.
  265. */
  266. #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
  267. /*
  268. * atomic_inc_and_test - increment and test
  269. * @v: pointer of type atomic_t
  270. *
  271. * Atomically increments @v by 1
  272. * and returns true if the result is zero, or false for all
  273. * other cases.
  274. */
  275. #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
  276. /*
  277. * atomic_dec_and_test - decrement by 1 and test
  278. * @v: pointer of type atomic_t
  279. *
  280. * Atomically decrements @v by 1 and
  281. * returns true if the result is 0, or false for all other
  282. * cases.
  283. */
  284. #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
  285. /*
  286. * atomic_dec_if_positive - decrement by 1 if old value positive
  287. * @v: pointer of type atomic_t
  288. */
  289. #define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v)
  290. /*
  291. * atomic_inc - increment atomic variable
  292. * @v: pointer of type atomic_t
  293. *
  294. * Atomically increments @v by 1.
  295. */
  296. #define atomic_inc(v) atomic_add(1,(v))
  297. /*
  298. * atomic_dec - decrement and test
  299. * @v: pointer of type atomic_t
  300. *
  301. * Atomically decrements @v by 1.
  302. */
  303. #define atomic_dec(v) atomic_sub(1,(v))
  304. /*
  305. * atomic_add_negative - add and test if negative
  306. * @v: pointer of type atomic_t
  307. * @i: integer value to add
  308. *
  309. * Atomically adds @i to @v and returns true
  310. * if the result is negative, or false when
  311. * result is greater than or equal to zero.
  312. */
  313. #define atomic_add_negative(i,v) (atomic_add_return(i, (v)) < 0)
  314. #ifdef CONFIG_64BIT
  315. typedef struct { volatile __s64 counter; } atomic64_t;
  316. #define ATOMIC64_INIT(i) { (i) }
  317. /*
  318. * atomic64_read - read atomic variable
  319. * @v: pointer of type atomic64_t
  320. *
  321. */
  322. #define atomic64_read(v) ((v)->counter)
  323. /*
  324. * atomic64_set - set atomic variable
  325. * @v: pointer of type atomic64_t
  326. * @i: required value
  327. */
  328. #define atomic64_set(v,i) ((v)->counter = (i))
  329. /*
  330. * atomic64_add - add integer to atomic variable
  331. * @i: integer value to add
  332. * @v: pointer of type atomic64_t
  333. *
  334. * Atomically adds @i to @v.
  335. */
  336. static __inline__ void atomic64_add(long i, atomic64_t * v)
  337. {
  338. if (cpu_has_llsc && R10000_LLSC_WAR) {
  339. unsigned long temp;
  340. __asm__ __volatile__(
  341. " .set mips3 \n"
  342. "1: lld %0, %1 # atomic64_add \n"
  343. " addu %0, %2 \n"
  344. " scd %0, %1 \n"
  345. " beqzl %0, 1b \n"
  346. " .set mips0 \n"
  347. : "=&r" (temp), "=m" (v->counter)
  348. : "Ir" (i), "m" (v->counter));
  349. } else if (cpu_has_llsc) {
  350. unsigned long temp;
  351. __asm__ __volatile__(
  352. " .set mips3 \n"
  353. "1: lld %0, %1 # atomic64_add \n"
  354. " addu %0, %2 \n"
  355. " scd %0, %1 \n"
  356. " beqz %0, 1b \n"
  357. " .set mips0 \n"
  358. : "=&r" (temp), "=m" (v->counter)
  359. : "Ir" (i), "m" (v->counter));
  360. } else {
  361. unsigned long flags;
  362. spin_lock_irqsave(&atomic_lock, flags);
  363. v->counter += i;
  364. spin_unlock_irqrestore(&atomic_lock, flags);
  365. }
  366. }
  367. /*
  368. * atomic64_sub - subtract the atomic variable
  369. * @i: integer value to subtract
  370. * @v: pointer of type atomic64_t
  371. *
  372. * Atomically subtracts @i from @v.
  373. */
  374. static __inline__ void atomic64_sub(long i, atomic64_t * v)
  375. {
  376. if (cpu_has_llsc && R10000_LLSC_WAR) {
  377. unsigned long temp;
  378. __asm__ __volatile__(
  379. " .set mips3 \n"
  380. "1: lld %0, %1 # atomic64_sub \n"
  381. " subu %0, %2 \n"
  382. " scd %0, %1 \n"
  383. " beqzl %0, 1b \n"
  384. " .set mips0 \n"
  385. : "=&r" (temp), "=m" (v->counter)
  386. : "Ir" (i), "m" (v->counter));
  387. } else if (cpu_has_llsc) {
  388. unsigned long temp;
  389. __asm__ __volatile__(
  390. " .set mips3 \n"
  391. "1: lld %0, %1 # atomic64_sub \n"
  392. " subu %0, %2 \n"
  393. " scd %0, %1 \n"
  394. " beqz %0, 1b \n"
  395. " .set mips0 \n"
  396. : "=&r" (temp), "=m" (v->counter)
  397. : "Ir" (i), "m" (v->counter));
  398. } else {
  399. unsigned long flags;
  400. spin_lock_irqsave(&atomic_lock, flags);
  401. v->counter -= i;
  402. spin_unlock_irqrestore(&atomic_lock, flags);
  403. }
  404. }
  405. /*
  406. * Same as above, but return the result value
  407. */
  408. static __inline__ long atomic64_add_return(long i, atomic64_t * v)
  409. {
  410. unsigned long result;
  411. if (cpu_has_llsc && R10000_LLSC_WAR) {
  412. unsigned long temp;
  413. __asm__ __volatile__(
  414. " .set mips3 \n"
  415. "1: lld %1, %2 # atomic64_add_return \n"
  416. " addu %0, %1, %3 \n"
  417. " scd %0, %2 \n"
  418. " beqzl %0, 1b \n"
  419. " addu %0, %1, %3 \n"
  420. " sync \n"
  421. " .set mips0 \n"
  422. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  423. : "Ir" (i), "m" (v->counter)
  424. : "memory");
  425. } else if (cpu_has_llsc) {
  426. unsigned long temp;
  427. __asm__ __volatile__(
  428. " .set mips3 \n"
  429. "1: lld %1, %2 # atomic64_add_return \n"
  430. " addu %0, %1, %3 \n"
  431. " scd %0, %2 \n"
  432. " beqz %0, 1b \n"
  433. " addu %0, %1, %3 \n"
  434. " sync \n"
  435. " .set mips0 \n"
  436. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  437. : "Ir" (i), "m" (v->counter)
  438. : "memory");
  439. } else {
  440. unsigned long flags;
  441. spin_lock_irqsave(&atomic_lock, flags);
  442. result = v->counter;
  443. result += i;
  444. v->counter = result;
  445. spin_unlock_irqrestore(&atomic_lock, flags);
  446. }
  447. return result;
  448. }
  449. static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
  450. {
  451. unsigned long result;
  452. if (cpu_has_llsc && R10000_LLSC_WAR) {
  453. unsigned long temp;
  454. __asm__ __volatile__(
  455. " .set mips3 \n"
  456. "1: lld %1, %2 # atomic64_sub_return \n"
  457. " subu %0, %1, %3 \n"
  458. " scd %0, %2 \n"
  459. " beqzl %0, 1b \n"
  460. " subu %0, %1, %3 \n"
  461. " sync \n"
  462. " .set mips0 \n"
  463. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  464. : "Ir" (i), "m" (v->counter)
  465. : "memory");
  466. } else if (cpu_has_llsc) {
  467. unsigned long temp;
  468. __asm__ __volatile__(
  469. " .set mips3 \n"
  470. "1: lld %1, %2 # atomic64_sub_return \n"
  471. " subu %0, %1, %3 \n"
  472. " scd %0, %2 \n"
  473. " beqz %0, 1b \n"
  474. " subu %0, %1, %3 \n"
  475. " sync \n"
  476. " .set mips0 \n"
  477. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  478. : "Ir" (i), "m" (v->counter)
  479. : "memory");
  480. } else {
  481. unsigned long flags;
  482. spin_lock_irqsave(&atomic_lock, flags);
  483. result = v->counter;
  484. result -= i;
  485. v->counter = result;
  486. spin_unlock_irqrestore(&atomic_lock, flags);
  487. }
  488. return result;
  489. }
  490. /*
  491. * atomic64_sub_if_positive - add integer to atomic variable
  492. * @v: pointer of type atomic64_t
  493. *
  494. * Atomically test @v and decrement if it is greater than 0.
  495. * The function returns the old value of @v minus 1.
  496. */
  497. static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
  498. {
  499. unsigned long result;
  500. if (cpu_has_llsc && R10000_LLSC_WAR) {
  501. unsigned long temp;
  502. __asm__ __volatile__(
  503. " .set mips3 \n"
  504. "1: lld %1, %2 # atomic64_sub_if_positive\n"
  505. " dsubu %0, %1, %3 \n"
  506. " bltz %0, 1f \n"
  507. " scd %0, %2 \n"
  508. " beqzl %0, 1b \n"
  509. " sync \n"
  510. "1: \n"
  511. " .set mips0 \n"
  512. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  513. : "Ir" (i), "m" (v->counter)
  514. : "memory");
  515. } else if (cpu_has_llsc) {
  516. unsigned long temp;
  517. __asm__ __volatile__(
  518. " .set mips3 \n"
  519. "1: lld %1, %2 # atomic64_sub_if_positive\n"
  520. " dsubu %0, %1, %3 \n"
  521. " bltz %0, 1f \n"
  522. " scd %0, %2 \n"
  523. " beqz %0, 1b \n"
  524. " sync \n"
  525. "1: \n"
  526. " .set mips0 \n"
  527. : "=&r" (result), "=&r" (temp), "=m" (v->counter)
  528. : "Ir" (i), "m" (v->counter)
  529. : "memory");
  530. } else {
  531. unsigned long flags;
  532. spin_lock_irqsave(&atomic_lock, flags);
  533. result = v->counter;
  534. result -= i;
  535. if (result >= 0)
  536. v->counter = result;
  537. spin_unlock_irqrestore(&atomic_lock, flags);
  538. }
  539. return result;
  540. }
  541. #define atomic64_dec_return(v) atomic64_sub_return(1,(v))
  542. #define atomic64_inc_return(v) atomic64_add_return(1,(v))
  543. /*
  544. * atomic64_sub_and_test - subtract value from variable and test result
  545. * @i: integer value to subtract
  546. * @v: pointer of type atomic64_t
  547. *
  548. * Atomically subtracts @i from @v and returns
  549. * true if the result is zero, or false for all
  550. * other cases.
  551. */
  552. #define atomic64_sub_and_test(i,v) (atomic64_sub_return((i), (v)) == 0)
  553. /*
  554. * atomic64_inc_and_test - increment and test
  555. * @v: pointer of type atomic64_t
  556. *
  557. * Atomically increments @v by 1
  558. * and returns true if the result is zero, or false for all
  559. * other cases.
  560. */
  561. #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
  562. /*
  563. * atomic64_dec_and_test - decrement by 1 and test
  564. * @v: pointer of type atomic64_t
  565. *
  566. * Atomically decrements @v by 1 and
  567. * returns true if the result is 0, or false for all other
  568. * cases.
  569. */
  570. #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0)
  571. /*
  572. * atomic64_dec_if_positive - decrement by 1 if old value positive
  573. * @v: pointer of type atomic64_t
  574. */
  575. #define atomic64_dec_if_positive(v) atomic64_sub_if_positive(1, v)
  576. /*
  577. * atomic64_inc - increment atomic variable
  578. * @v: pointer of type atomic64_t
  579. *
  580. * Atomically increments @v by 1.
  581. */
  582. #define atomic64_inc(v) atomic64_add(1,(v))
  583. /*
  584. * atomic64_dec - decrement and test
  585. * @v: pointer of type atomic64_t
  586. *
  587. * Atomically decrements @v by 1.
  588. */
  589. #define atomic64_dec(v) atomic64_sub(1,(v))
  590. /*
  591. * atomic64_add_negative - add and test if negative
  592. * @v: pointer of type atomic64_t
  593. * @i: integer value to add
  594. *
  595. * Atomically adds @i to @v and returns true
  596. * if the result is negative, or false when
  597. * result is greater than or equal to zero.
  598. */
  599. #define atomic64_add_negative(i,v) (atomic64_add_return(i, (v)) < 0)
  600. #endif /* CONFIG_64BIT */
  601. /*
  602. * atomic*_return operations are serializing but not the non-*_return
  603. * versions.
  604. */
  605. #define smp_mb__before_atomic_dec() smp_mb()
  606. #define smp_mb__after_atomic_dec() smp_mb()
  607. #define smp_mb__before_atomic_inc() smp_mb()
  608. #define smp_mb__after_atomic_inc() smp_mb()
  609. #endif /* _ASM_ATOMIC_H */