atomic.h 16 KB

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