Rev 4363 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4363 | Rev 6110 | ||
---|---|---|---|
Line 46... | Line 46... | ||
46 | } atomic_t; |
46 | } atomic_t; |
Line 47... | Line 47... | ||
47 | 47 | ||
48 | # define atomic_read(x) ((x)->atomic) |
48 | # define atomic_read(x) ((x)->atomic) |
49 | # define atomic_set(x, val) ((x)->atomic = (val)) |
49 | # define atomic_set(x, val) ((x)->atomic = (val)) |
- | 50 | # define atomic_inc(x) ((void) __sync_fetch_and_add (&(x)->atomic, 1)) |
|
50 | # define atomic_inc(x) ((void) __sync_fetch_and_add (&(x)->atomic, 1)) |
51 | # define atomic_inc_return(x) (__sync_add_and_fetch (&(x)->atomic, 1)) |
51 | # define atomic_dec_and_test(x) (__sync_fetch_and_add (&(x)->atomic, -1) == 1) |
52 | # define atomic_dec_and_test(x) (__sync_add_and_fetch (&(x)->atomic, -1) == 0) |
52 | # define atomic_add(x, v) ((void) __sync_add_and_fetch(&(x)->atomic, (v))) |
53 | # define atomic_add(x, v) ((void) __sync_add_and_fetch(&(x)->atomic, (v))) |
53 | # define atomic_dec(x, v) ((void) __sync_sub_and_fetch(&(x)->atomic, (v))) |
54 | # define atomic_dec(x, v) ((void) __sync_sub_and_fetch(&(x)->atomic, (v))) |
Line 64... | Line 65... | ||
64 | } atomic_t; |
65 | } atomic_t; |
Line 65... | Line 66... | ||
65 | 66 | ||
66 | # define atomic_read(x) AO_load_full(&(x)->atomic) |
67 | # define atomic_read(x) AO_load_full(&(x)->atomic) |
67 | # define atomic_set(x, val) AO_store_full(&(x)->atomic, (val)) |
68 | # define atomic_set(x, val) AO_store_full(&(x)->atomic, (val)) |
- | 69 | # define atomic_inc(x) ((void) AO_fetch_and_add1_full(&(x)->atomic)) |
|
68 | # define atomic_inc(x) ((void) AO_fetch_and_add1_full(&(x)->atomic)) |
70 | # define atomic_inc_return(x) (AO_fetch_and_add1_full(&(x)->atomic) + 1) |
69 | # define atomic_add(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, (v))) |
71 | # define atomic_add(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, (v))) |
70 | # define atomic_dec(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, -(v))) |
72 | # define atomic_dec(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, -(v))) |
71 | # define atomic_dec_and_test(x) (AO_fetch_and_sub1_full(&(x)->atomic) == 1) |
73 | # define atomic_dec_and_test(x) (AO_fetch_and_sub1_full(&(x)->atomic) == 1) |
Line 72... | Line 74... | ||
72 | # define atomic_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(&(x)->atomic, oldv, newv) |
74 | # define atomic_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(&(x)->atomic, oldv, newv) |
Line 73... | Line 75... | ||
73 | 75 | ||
Line 74... | Line 76... | ||
74 | #endif |
76 | #endif |
75 | 77 | ||
Line -... | Line 78... | ||
- | 78 | #if (defined(__sun) || defined(__NetBSD__)) && !defined(HAS_ATOMIC_OPS) /* Solaris & OpenSolaris & NetBSD */ |
|
- | 79 | ||
- | 80 | #include |
|
- | 81 | #define HAS_ATOMIC_OPS 1 |
|
- | 82 | ||
- | 83 | #if defined(__NetBSD__) |
|
76 | #if defined(__sun) && !defined(HAS_ATOMIC_OPS) /* Solaris & OpenSolaris */ |
84 | #define LIBDRM_ATOMIC_TYPE int |
Line 77... | Line 85... | ||
77 | 85 | #else |
|
78 | #include |
86 | #define LIBDRM_ATOMIC_TYPE uint_t |
79 | #define HAS_ATOMIC_OPS 1 |
87 | #endif |
- | 88 | ||
80 | 89 | typedef struct { LIBDRM_ATOMIC_TYPE atomic; } atomic_t; |
|
81 | typedef struct { uint_t atomic; } atomic_t; |
90 | |
82 | 91 | # define atomic_read(x) (int) ((x)->atomic) |
|
83 | # define atomic_read(x) (int) ((x)->atomic) |
92 | # define atomic_set(x, val) ((x)->atomic = (LIBDRM_ATOMIC_TYPE)(val)) |
Line 84... | Line 93... | ||
84 | # define atomic_set(x, val) ((x)->atomic = (uint_t)(val)) |
93 | # define atomic_inc(x) (atomic_inc_uint (&(x)->atomic)) |
Line 85... | Line 94... | ||
85 | # define atomic_inc(x) (atomic_inc_uint (&(x)->atomic)) |
94 | # define atomic_inc_return(x) (atomic_inc_uint_nv(&(x)->atomic)) |
86 | # define atomic_dec_and_test(x) (atomic_dec_uint_nv(&(x)->atomic) == 1) |
95 | # define atomic_dec_and_test(x) (atomic_dec_uint_nv(&(x)->atomic) == 0) |
87 | # define atomic_add(x, v) (atomic_add_int(&(x)->atomic, (v))) |
96 | # define atomic_add(x, v) (atomic_add_int(&(x)->atomic, (v))) |
Line -... | Line 97... | ||
- | 97 | # define atomic_dec(x, v) (atomic_add_int(&(x)->atomic, -(v))) |
|
- | 98 | # define atomic_cmpxchg(x, oldv, newv) atomic_cas_uint (&(x)->atomic, oldv, newv) |
|
- | 99 | ||
- | 100 | #endif |
|
- | 101 | ||
- | 102 | #if ! HAS_ATOMIC_OPS |
|
- | 103 | #error libdrm requires atomic operations, please define them for your CPU/compiler. |
|
- | 104 | #endif |
|
- | 105 | ||
88 | # define atomic_dec(x, v) (atomic_add_int(&(x)->atomic, -(v))) |
106 | static inline int atomic_add_unless(atomic_t *v, int add, int unless) |