Created
August 16, 2018 06:52
-
-
Save liuliu/a77b5649088ef6c919d499fc251c1dd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void deltask(schd_t* const schd, task_t* const t) | |
{ | |
if (t->prev) | |
t->prev->next = t->next; | |
else | |
schd->head = t->next; | |
if (t->next) | |
t->next->prev = t->prev; | |
else | |
schd->tail = t->prev; | |
} | |
static void* schdmain(void* userdata) | |
{ | |
schd_t* const schd = (schd_t*)userdata; | |
for (;;) { | |
pthread_mutex_lock(&schd->mutex); | |
// No one is waiting, and no more tasks. exit. | |
if (schd->head == 0 && schd->count.suspend == 0) | |
{ | |
pthread_mutex_unlock(&schd->mutex); | |
break; | |
} | |
if (schd->head == 0) | |
{ | |
pthread_cond_wait(&schd->cv, &schd->mutex); | |
pthread_mutex_unlock(&schd->mutex); | |
continue; | |
} | |
task_t* const t = schd->head; | |
deltask(schd, t); | |
pthread_mutex_unlock(&schd->mutex); | |
swapcontext(&schd->caller, &t->context); | |
t->context = schd->callee; | |
if (t->done) | |
taskfree(t); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment