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 _task_entry_point(uint32_t part0, uint32_t part1) | |
{ | |
union ptr_splitter p; | |
p.part[0] = part0; | |
p.part[1] = part1; | |
task_t *task = (task_t*)p.ptr; | |
task->fn(task); | |
task->done = 1; | |
swapcontext(&task->schd->callee, &task->schd->caller); | |
} |
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 taskyield(task_t* const task) | |
{ | |
addtask(task->schd, task); | |
swapcontext(&task->schd->callee, &task->schd->caller); | |
} | |
static void taskresume(task_t* const task) | |
{ | |
ucontext_t old_context = task->schd->caller; | |
swapcontext(&task->schd->caller, &task->context); |
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 g(task_t* const task) | |
{ | |
printf("start task %p\n", task); | |
taskyield(task); | |
printf("back to task %p to finish\n", task); | |
} | |
static void f(task_t* const task) | |
{ | |
printf("create a new task to resume %p\n", task); |
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 taskcudaresume(cudaStream_t stream, cudaError_t status, void* userdata) | |
{ | |
task_t* const task = (task_t*)userdata; | |
pthread_mutex_lock(&task->schd->mutex); | |
addtask(task->schd, task); | |
--task->schd->count.suspend; | |
pthread_cond_signal(&task->schd->cv); | |
pthread_mutex_unlock(&task->schd->mutex); | |
} |
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
create a new task to resume 0x288d010 | |
start task 0x289d410 | |
done task 0x288d010 | |
back to task 0x289d410 to finish |
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 co_decl_task(ab_t, _coroutine_a, (const int a, const int b), private( | |
int i; | |
)) { | |
printf("param a %d\n", CO_P(a)); | |
printf("param b %d\n", CO_P(b)); | |
CO_V(i) = 2; | |
printf("%d\n", CO_V(i)); | |
co_yield((ab_t){ | |
.a = CO_V(i) | |
}); |
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 co_decl_task(ab_t, _coroutine_a, (const int a, const int b), |
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 atomic_int executed_count; | |
void my_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) { | |
dispatch_async(queue, ^{ | |
++executed_count; | |
block(); | |
}); | |
} |
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
dispatch_block_t block = dispatch_block_create_with_qos_class(DISPATCH_BLOCK_ENFORCE_QOS_CLASS, QOS_USER_INITIATED, 0, old_block); |
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
// ... | |
struct Block_descriptor_1 { | |
unsigned long int reserved; | |
unsigned long int size; | |
}; | |
// ... | |
struct Block_layout { | |
void *isa; | |
volatile int32_t flags; // contains ref count | |
int32_t reserved; |