STATIC_INLINE StgPtr thread_AP_STACK (StgAP_STACK *ap) { thread(&ap->fun); thread_stack((P_)ap->payload, (P_)ap->payload + ap->size); return (P_)ap + sizeofW(StgAP_STACK) + ap->size; }
static StgPtr thread_TSO (StgTSO *tso) { thread_(&tso->link); if (tso->why_blocked == BlockedOnBlackHole) { thread_(&tso->block_info.closure); } thread_stack(tso->sp, &(tso->stack[tso->stack_size])); return (StgPtr)tso + tso_sizeW(tso); }
void threads_init(void) { int i; if (threads_initialized) return; threads[0].thread = mach_thread_self(); threads[0].stack = thread_stack(&i); set_thread_self(&threads[0]); threads_initialized = TRUE; }
static vm_offset_t stack_alloc(vm_size_t size) { vm_offset_t addr; vm_offset_t stack; vm_size_t unused; kern_return_t rc; if((rc = vm_allocate(mach_task_self(), &addr, 2*STACK_SIZE, TRUE)) != KERN_SUCCESS) { printf("stack_alloc: vm_allocate failed\n"); return 0; } stack = thread_stack(addr+size-1); if ((unused = stack - addr)) { if((rc = vm_deallocate(mach_task_self(), addr, unused)) != KERN_SUCCESS) { printf("stack_alloc: vm_allocate failed\n"); return 0; } } if ((unused = addr + size - stack)) { if((rc = vm_deallocate(mach_task_self(), stack + size, unused)) != KERN_SUCCESS) { printf("stack_alloc: vm_allocate failed\n"); return 0; } } return(stack); }
/** * Destroy all thread_stack_nodes. */ void thread_stack_destroy_all() { while(thread_stack() != NULL) thread_stack_destroy(); }