feat: introduced stream to separate actual io and other tasks

This commit is contained in:
2021-03-02 21:56:37 +01:00
parent 76792dd6fd
commit c9102fbc65
6 changed files with 234 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ semaphore_t *semaphore_create(int32_t start) {
}
void semaphore_wait(semaphore_t *semaphore) {
if (__sync_sub_and_fetch(&semaphore->value, 1) == 0) {
if (__sync_sub_and_fetch(&semaphore->value, 1) >= 0) {
return; // first to lock
}
task_lock_acquire();
@@ -54,14 +54,17 @@ void semaphore_wait(semaphore_t *semaphore) {
}
void semaphore_signal(semaphore_t *semaphore) {
if (__sync_add_and_fetch(&semaphore->value, 1) >= 1) {
return; // last in queue
}
semaphore->value++;
task_lock_acquire();
task_signal(semaphore->first_wait->tid);
lock_fifo_entry_t *first_entry = semaphore->first_wait;
semaphore->first_wait = first_entry->next;
free(first_entry);
if (semaphore->first_wait != NULL) {
task_signal(semaphore->first_wait->tid);
lock_fifo_entry_t *first_entry = semaphore->first_wait;
semaphore->first_wait = first_entry->next;
if (semaphore->first_wait == NULL) {
semaphore->last_wait = NULL;
}
free(first_entry);
}
task_lock_free();
}