use pthread_cleanup to acquire and release lock

In chunk_prepare(), if multiple threads wait for acquiring f->lock,
and then pthread_cancel() is called, the waiting threads are never
canceled because pthread_mutex_lock() is not a cancellation point.
So, use pthread_cleanup_push/pop to release the lock.
This commit is contained in:
Ryo Nakamura
2022-12-11 13:23:41 +09:00
parent 45cde99a85
commit d27db01d8d
3 changed files with 17 additions and 4 deletions

View File

@@ -55,4 +55,17 @@ static inline void lock_release(lock *l)
}
}
static inline void lock_release_via_cleanup(void *l)
{
lock_release(l);
}
#define LOCK_ACQUIRE_THREAD(l) \
lock_acquire(l); \
pthread_cleanup_push(lock_release_via_cleanup, l)
#define LOCK_RELEASE_THREAD(l) \
pthread_cleanup_pop(1)
#endif /* _ATOMIC_H_ */