diff options
author | Sam Sortais | 2016-08-08 13:40:53 -0500 |
---|---|---|
committer | Wendy Liang | 2016-08-13 01:36:44 -0500 |
commit | 20ff69684a32c6a45e2ed11743b2b22d7474d955 (patch) | |
tree | 8fa36a7ce427809ba8b85d4cd19d3566d280a6d4 | |
parent | 6a9567c188dac383408f566f6f42eb56b7df9d08 (diff) | |
download | libmetal-20ff69684a32c6a45e2ed11743b2b22d7474d955.tar.gz libmetal-20ff69684a32c6a45e2ed11743b2b22d7474d955.tar.xz libmetal-20ff69684a32c6a45e2ed11743b2b22d7474d955.zip |
linux: mutex deinit and typedef
Signed-off-by: Sam Sortais <sam.sortais@xilinx.com>
-rw-r--r-- | lib/system/linux/mutex.h | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/system/linux/mutex.h b/lib/system/linux/mutex.h index 8aa1bab..7bdc341 100644 --- a/lib/system/linux/mutex.h +++ b/lib/system/linux/mutex.h | |||
@@ -50,31 +50,36 @@ | |||
50 | extern "C" { | 50 | extern "C" { |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | struct metal_mutex { | 53 | typedef struct { |
54 | atomic_int v; | 54 | atomic_int v; |
55 | }; | 55 | } metal_mutex_t; |
56 | 56 | ||
57 | #define METAL_MUTEX_INIT { ATOMIC_VAR_INIT(0) } | 57 | #define METAL_MUTEX_INIT { ATOMIC_VAR_INIT(0) } |
58 | 58 | ||
59 | static inline int __metal_mutex_cmpxchg(struct metal_mutex *mutex, | 59 | static inline int __metal_mutex_cmpxchg(metal_mutex_t *mutex, |
60 | int exp, int val) | 60 | int exp, int val) |
61 | { | 61 | { |
62 | atomic_compare_exchange_strong(&mutex->v, (int *)&exp, val); | 62 | atomic_compare_exchange_strong(&mutex->v, (int *)&exp, val); |
63 | return exp; | 63 | return exp; |
64 | } | 64 | } |
65 | 65 | ||
66 | static inline void metal_mutex_init(struct metal_mutex *mutex) | 66 | static inline void metal_mutex_init(metal_mutex_t *mutex) |
67 | { | 67 | { |
68 | atomic_store(&mutex->v, 0); | 68 | atomic_store(&mutex->v, 0); |
69 | } | 69 | } |
70 | 70 | ||
71 | static inline int metal_mutex_try_acquire(struct metal_mutex *mutex) | 71 | static inline void metal_mutex_deinit(metal_mutex_t *mutex) |
72 | { | ||
73 | (void)mutex; | ||
74 | } | ||
75 | |||
76 | static inline int metal_mutex_try_acquire(metal_mutex_t *mutex) | ||
72 | { | 77 | { |
73 | int val = 0; | 78 | int val = 0; |
74 | return atomic_compare_exchange_strong(&mutex->v, &val, 1); | 79 | return atomic_compare_exchange_strong(&mutex->v, &val, 1); |
75 | } | 80 | } |
76 | 81 | ||
77 | static inline void metal_mutex_acquire(struct metal_mutex *mutex) | 82 | static inline void metal_mutex_acquire(metal_mutex_t *mutex) |
78 | { | 83 | { |
79 | int c = 0; | 84 | int c = 0; |
80 | 85 | ||
@@ -88,7 +93,7 @@ static inline void metal_mutex_acquire(struct metal_mutex *mutex) | |||
88 | } | 93 | } |
89 | } | 94 | } |
90 | 95 | ||
91 | static inline void metal_mutex_release(struct metal_mutex *mutex) | 96 | static inline void metal_mutex_release(metal_mutex_t *mutex) |
92 | { | 97 | { |
93 | if (atomic_fetch_sub(&mutex->v, 1) != 1) { | 98 | if (atomic_fetch_sub(&mutex->v, 1) != 1) { |
94 | atomic_store(&mutex->v, 0); | 99 | atomic_store(&mutex->v, 0); |
@@ -96,7 +101,7 @@ static inline void metal_mutex_release(struct metal_mutex *mutex) | |||
96 | } | 101 | } |
97 | } | 102 | } |
98 | 103 | ||
99 | static inline int metal_mutex_is_acquired(struct metal_mutex *mutex) | 104 | static inline int metal_mutex_is_acquired(metal_mutex_t *mutex) |
100 | { | 105 | { |
101 | return atomic_load(&mutex->v); | 106 | return atomic_load(&mutex->v); |
102 | } | 107 | } |