26 |
#include <errno.h> |
#include <errno.h> |
27 |
#include <pthread.h> |
#include <pthread.h> |
28 |
|
|
29 |
|
/* FIXME: This is not a public header file! So we may have to ship |
30 |
|
a <hurd/atomic.h>. */ |
31 |
|
#include <atomic.h> |
32 |
|
|
33 |
#include <hurd/slab.h> |
#include <hurd/slab.h> |
34 |
#include <hurd/types.h> |
#include <hurd/types.h> |
35 |
|
|
217 |
pthread_mutex_t lock; |
pthread_mutex_t lock; |
218 |
|
|
219 |
/* The reference counter for this object. */ |
/* The reference counter for this object. */ |
220 |
unsigned int refs; |
uatomic32_t refs; |
221 |
|
|
222 |
/* The state of this object. If this is _HURD_CAP_STATE_GREEN, you |
/* The state of this object. If this is _HURD_CAP_STATE_GREEN, you |
223 |
can use the capability object. Otherwise, you should refrain |
can use the capability object. Otherwise, you should refrain |
355 |
static inline void |
static inline void |
356 |
hurd_cap_obj_ref (hurd_cap_obj_t obj) |
hurd_cap_obj_ref (hurd_cap_obj_t obj) |
357 |
{ |
{ |
358 |
assert (obj->refs < UINT_MAX); |
atomic_increment (&obj->refs); |
|
|
|
|
obj->refs++; |
|
359 |
} |
} |
360 |
|
|
361 |
|
|
362 |
/* Remove one reference for the capability object OBJ, which must be |
/* Remove one reference for the capability object OBJ. Note that the |
363 |
locked. Note that the caller must have at least two references for |
caller must have at least two references for this capability object |
364 |
this capability object when using this function. To release the |
when using this function. To release the last reference, |
365 |
last reference, hurd_cap_obj_drop must be used instead. */ |
hurd_cap_obj_drop must be used instead. */ |
366 |
static inline void |
static inline void |
367 |
hurd_cap_obj_rele (hurd_cap_obj_t obj) |
hurd_cap_obj_rele (hurd_cap_obj_t obj) |
368 |
{ |
{ |
369 |
assert (obj->refs > 1); |
atomic_decrement (&obj->refs); |
|
|
|
|
obj->refs--; |
|
370 |
} |
} |
371 |
|
|
372 |
|
|