thread_id spawn_thread(thread_func entry, const char *name, int32 priority, void *data) { struct thread_creation_attributes attributes; pthread_thread* thread; thread_id id; thread = __allocate_pthread(NULL, data); if (thread == NULL) return B_NO_MEMORY; _single_threaded = false; // used for I/O locking - BeOS compatibility issue __pthread_init_creation_attributes(NULL, thread, &thread_entry, entry, thread, name, &attributes); attributes.priority = priority; id = _kern_spawn_thread(&attributes); if (id < 0) free(thread); else { thread->id = id; __set_stack_protection(); } return id; }
int pthread_create(pthread_t* _thread, const pthread_attr_t* attr, void* (*startRoutine)(void*), void* arg) { if (_thread == NULL) return EINVAL; pthread_thread* thread = __allocate_pthread(startRoutine, arg); if (thread == NULL) return EAGAIN; thread_creation_attributes attributes; status_t error = __pthread_init_creation_attributes(attr, thread, &pthread_thread_entry, NULL, thread, "pthread func", &attributes); if (error != B_OK) { free(thread); return error; } thread->id = _kern_spawn_thread(&attributes); if (thread->id < 0) { // stupid error code but demanded by POSIX free(thread); return EAGAIN; } __set_stack_protection(); *_thread = thread; resume_thread(thread->id); return 0; }
void initialize_before(image_id imageID) { system_info info; char *programPath = __gRuntimeLoader->program_args->args[0]; __gCommPageAddress = __gRuntimeLoader->commpage_address; __gABIVersion = __gRuntimeLoader->abi_version; if (programPath) { if ((__progname = strrchr(programPath, '/')) == NULL) __progname = programPath; else __progname++; } __libc_argc = __gRuntimeLoader->program_args->arg_count; __libc_argv = __gRuntimeLoader->program_args->args; __gRuntimeLoader->call_atexit_hooks_for_range = _call_atexit_hooks_for_range; if (__gRuntimeLoader->program_args->umask != (mode_t)-1) umask(__gRuntimeLoader->program_args->umask); pthread_self()->id = find_thread(NULL); get_system_info(&info); __gCPUCount = info.cpu_count; __init_time((addr_t)__gCommPageAddress); __init_heap(); __init_env(__gRuntimeLoader->program_args); __init_heap_post_env(); __init_pwd_backend(); __set_stack_protection(); }