minor fix

This commit is contained in:
TXuian
2024-12-24 16:48:52 +08:00
parent 74da96e1f1
commit 6b636dfde0
4 changed files with 11 additions and 49 deletions
@@ -106,7 +106,8 @@ bool ksemaphore_wait(struct XiziSemaphorePool* sem_pool, struct Thread* thd, sem
// waiting at the sem
sem->val--;
THREAD_TRANS_STATE(thd, BLOCKED);
assert(RBTTREE_INSERT_SECC == rbt_insert(&sem->wait_thd_tree, thd->tid, thd));
int rbt_insert_res = rbt_insert(&sem->wait_thd_tree, thd->tid, thd);
assert(RBTTREE_INSERT_SECC == rbt_insert_res || RBTTREE_INSERT_EXISTED == rbt_insert_res);
return true;
}
@@ -119,7 +120,7 @@ bool ksemaphore_signal(struct XiziSemaphorePool* sem_pool, sem_id_t sem_id)
return false;
}
if (sem->val < 0) {
if (sem->val < 0 && !rbt_is_empty(&sem->wait_thd_tree)) {
assert(!rbt_is_empty(&sem->wait_thd_tree));
RbtNode* root = sem->wait_thd_tree.root;
struct Thread* thd = (struct Thread*)root->data;