aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-10-02 23:31:00 -0400
committerTest_User <hax@andrewyu.org>2024-10-02 23:31:00 -0400
commitbe08289b27feacec70aa9c0e006498458e481515 (patch)
tree823a4ed0c91dbfaed785d8cfcad84d55cc1284d5
parentNickname enforcement improvement (diff)
downloadraxircd-runxiyu.tar.gz
raxircd-runxiyu.zip
Avoid needless locking when attempting to unlock, instead check the value directlyHEADrunxiyu
-rw-r--r--mutex.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/mutex.h b/mutex.h
index 4bb23df..5dbbbb9 100644
--- a/mutex.h
+++ b/mutex.h
@@ -99,8 +99,10 @@ inline void mutex_lock(sem_t *mutex) {
}
inline void mutex_unlock(sem_t *mutex) {
- while (sem_trywait(mutex) == -1 && errno == EINTR);
- sem_post(mutex);
+ int available;
+ sem_getvalue(mutex, &available);
+ if (available <= 0)
+ sem_post(mutex);
}
inline void mutex_destroy(sem_t *mutex) {