|
45 | 45 | /* semcount, flags, waitlist, hhead */
|
46 | 46 |
|
47 | 47 | # define NXSEM_INITIALIZER(c, f) \
|
48 |
| - {(c), (f), SEM_WAITLIST_INITIALIZER, NULL} |
| 48 | + {{c}, (f), SEM_WAITLIST_INITIALIZER, NULL} |
49 | 49 | # else
|
50 | 50 | /* semcount, flags, waitlist, holder[2] */
|
51 | 51 |
|
52 | 52 | # define NXSEM_INITIALIZER(c, f) \
|
53 |
| - {(c), (f), SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER} |
| 53 | + {{(c)}, (f), SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER} |
54 | 54 | # endif
|
55 | 55 | #else /* CONFIG_PRIORITY_INHERITANCE */
|
56 | 56 | /* semcount, flags, waitlist */
|
57 | 57 |
|
58 | 58 | # define NXSEM_INITIALIZER(c, f) \
|
59 |
| - {(c), (f), SEM_WAITLIST_INITIALIZER} |
| 59 | + {{(c)}, (f), SEM_WAITLIST_INITIALIZER} |
60 | 60 | #endif /* CONFIG_PRIORITY_INHERITANCE */
|
61 | 61 |
|
62 |
| -/* Macro to retrieve sem count */ |
| 62 | +/* Macros to retrieve sem count and to check if nxsem is mutex */ |
63 | 63 |
|
64 |
| -#define NXSEM_COUNT(s) ((FAR atomic_t *)&(s)->semcount) |
| 64 | +#define NXSEM_COUNT(s) ((FAR atomic_t *)&(s)->val.semcount) |
| 65 | +#define NXSEM_IS_MUTEX(s) (((s)->flags & SEM_TYPE_MUTEX) != 0) |
| 66 | + |
| 67 | +/* Mutex related helper macros */ |
| 68 | + |
| 69 | +#define NXSEM_MBLOCKS_BIT (((uint32_t)1) << 31) |
| 70 | +#define NXSEM_NO_MHOLDER ((uint32_t)0x7ffffffe) |
| 71 | +#define NXSEM_MRESET ((uint32_t)0x7fffffff) |
| 72 | + |
| 73 | +/* Macro to retrieve mutex's atomic holder's ptr */ |
| 74 | + |
| 75 | +#define NXSEM_MHOLDER(s) ((FAR atomic_t *)&(s)->val.mholder) |
| 76 | + |
| 77 | +/* Check if holder value (TID) is not NO_HOLDER or RESET */ |
| 78 | + |
| 79 | +#define NXSEM_MACQUIRED(h) (!(((h) & NXSEM_NO_MHOLDER) == NXSEM_NO_MHOLDER)) |
| 80 | + |
| 81 | +/* Check if mutex is acquired and blocks some other task */ |
| 82 | + |
| 83 | +#define NXSEM_MBLOCKS(h) (((h) & NXSEM_MBLOCKS_BIT) != 0) |
65 | 84 |
|
66 | 85 | /****************************************************************************
|
67 | 86 | * Public Type Definitions
|
@@ -128,7 +147,7 @@ extern "C"
|
128 | 147 | *
|
129 | 148 | ****************************************************************************/
|
130 | 149 |
|
131 |
| -int nxsem_init(FAR sem_t *sem, int pshared, unsigned int value); |
| 150 | +int nxsem_init(FAR sem_t *sem, int pshared, int32_t value); |
132 | 151 |
|
133 | 152 | /****************************************************************************
|
134 | 153 | * Name: nxsem_destroy
|
|
0 commit comments