Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cmpxchg.h
Go to the documentation of this file.
1 /*
2  * Port on Texas Instruments TMS320C6x architecture
3  *
4  * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5  * Author: Aurelien Jacquiot ([email protected])
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #ifndef _ASM_C6X_CMPXCHG_H
12 #define _ASM_C6X_CMPXCHG_H
13 
14 #include <linux/irqflags.h>
15 
16 /*
17  * Misc. functions
18  */
19 static inline unsigned int __xchg(unsigned int x, volatile void *ptr, int size)
20 {
21  unsigned int tmp;
22  unsigned long flags;
23 
24  local_irq_save(flags);
25 
26  switch (size) {
27  case 1:
28  tmp = 0;
29  tmp = *((unsigned char *) ptr);
30  *((unsigned char *) ptr) = (unsigned char) x;
31  break;
32  case 2:
33  tmp = 0;
34  tmp = *((unsigned short *) ptr);
35  *((unsigned short *) ptr) = x;
36  break;
37  case 4:
38  tmp = 0;
39  tmp = *((unsigned int *) ptr);
40  *((unsigned int *) ptr) = x;
41  break;
42  }
43  local_irq_restore(flags);
44  return tmp;
45 }
46 
47 #define xchg(ptr, x) \
48  ((__typeof__(*(ptr)))__xchg((unsigned int)(x), (void *) (ptr), \
49  sizeof(*(ptr))))
50 #define tas(ptr) xchg((ptr), 1)
51 
52 
54 
55 /*
56  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
57  * them available.
58  */
59 #define cmpxchg_local(ptr, o, n) \
60  ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
61  (unsigned long)(o), \
62  (unsigned long)(n), \
63  sizeof(*(ptr))))
64 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
65 
66 #include <asm-generic/cmpxchg.h>
67 
68 #endif /* _ASM_C6X_CMPXCHG_H */