reflock: make assert in reflock_unref() more strict, improve comments
This commit is contained in:
parent
b55b10a934
commit
b7289278e1
@ -46,22 +46,20 @@ static void reflock__await_event(void* address) {
|
||||
|
||||
void reflock_ref(reflock_t* reflock) {
|
||||
long state = InterlockedAdd(&reflock->state, REFLOCK__REF);
|
||||
|
||||
/* Verify that the counter didn't overflow and the lock isn't destroyed. */
|
||||
assert((state & REFLOCK__DESTROY_MASK) == 0);
|
||||
unused_var(state);
|
||||
assert((state & REFLOCK__DESTROY_MASK) == 0); /* Overflow or destroyed. */
|
||||
}
|
||||
|
||||
void reflock_unref(reflock_t* reflock) {
|
||||
long state = InterlockedAdd(&reflock->state, -REFLOCK__REF);
|
||||
long ref_count = state & REFLOCK__REF_MASK;
|
||||
long destroy = state & REFLOCK__DESTROY_MASK;
|
||||
|
||||
unused_var(ref_count);
|
||||
unused_var(destroy);
|
||||
/* Verify that the lock was referenced and not already destroyed. */
|
||||
assert((state & REFLOCK__DESTROY_MASK & ~REFLOCK__DESTROY) == 0);
|
||||
|
||||
if (state == REFLOCK__DESTROY)
|
||||
reflock__signal_event(reflock);
|
||||
else
|
||||
assert(destroy == 0 || ref_count > 0);
|
||||
}
|
||||
|
||||
void reflock_unref_and_destroy(reflock_t* reflock) {
|
||||
@ -69,8 +67,8 @@ void reflock_unref_and_destroy(reflock_t* reflock) {
|
||||
InterlockedAdd(&reflock->state, REFLOCK__DESTROY - REFLOCK__REF);
|
||||
long ref_count = state & REFLOCK__REF_MASK;
|
||||
|
||||
assert((state & REFLOCK__DESTROY_MASK) ==
|
||||
REFLOCK__DESTROY); /* Underflow or already destroyed. */
|
||||
/* Verify that the lock was referenced and not already destroyed. */
|
||||
assert((state & REFLOCK__DESTROY_MASK) == REFLOCK__DESTROY);
|
||||
|
||||
if (ref_count != 0)
|
||||
reflock__await_event(reflock);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user