void _cgo_sys_thread_start(ThreadStart *ts) { pthread_attr_t attr; sigset_t ign, oset; pthread_t p; size_t size; int err; sigfillset(&ign); pthread_sigmask(SIG_SETMASK, &ign, &oset); pthread_attr_init(&attr); pthread_attr_getstacksize(&attr, &size); // Leave stacklo=0 and set stackhi=size; mstack will do the rest. ts->g->stackhi = size; err = sys_pthread_create(&p, &attr, threadentry, ts); pthread_sigmask(SIG_SETMASK, &oset, nil); if (err != 0) { fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); abort(); } }
//----------------------------------------------------------------------------------------------------// // @func - kb_pthread_init //! @desc //! Create the statically specified pthreads that do not have an ELF file associated with it. //! Threads in kernel space. Stack allocated from BSS memory pool. //! @return //! - 0 on success //! - error code from sys_pthread_create //! @note //! - None //----------------------------------------------------------------------------------------------------// int kb_pthread_init(void) { struct _elf_pthread_init *pinit ; unsigned int i = 0 ; pthread_t tid; pthread_attr_t attr = default_attr; int ret; // Load the system processes to run during init. pinit = kb_pthread_table; for( i=0; i<N_INIT_SELF_PTHREADS; i++) { #if SCHED_TYPE == SCHED_PRIO attr.schedparam.sched_priority = pinit->priority; #endif ret = sys_pthread_create (&tid, &attr, (void*)pinit->start_func, NULL); if (ret != 0) { DBG_PRINT("XMK: kb_pthread_init: sys_pthread_create failed.\r\n"); return -1; } pinit++; } return 0; }
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) { void *stack = malloc(8192); memset(stack, 0, 8192); /* XXX */ *thread = sys_pthread_create(stack + 8192, start_routine, arg, attr); return 0; }
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { struct thread_args *p; p = malloc(sizeof(*p)); if(p == NULL) { errno = ENOMEM; return -1; } p->func = start_routine; p->arg = arg; return sys_pthread_create(thread, attr, thread_start_wrapper, p); }
int xmk_add_static_thread(void* (*start_routine)(void *), int sched_priority) { pthread_t tid; pthread_attr_t attr = default_attr; int ret; #if SCHED_TYPE == SCHED_PRIO attr.schedparam.sched_priority = sched_priority; #endif sched_priority = 0; /* Dummy to remove compilation issues */ ret = sys_pthread_create (&tid, &attr, start_routine, NULL); if (ret != 0) { DBG_PRINT("XMK: xmk_add_static_thread: sys_pthread_create failed.\r\n"); return -1; } return 0; }
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { struct thread_args *p; // we must initialize our wrapper in pthread_create, because it is valid to call // pthread_create in a static constructor, and in fact, our test for issue 9456 // does just that. if(pthread_once(&init_pthread_wrapper_once, init_pthread_wrapper) != 0) { fprintf(stderr, "runtime/cgo: failed to initialize pthread_create wrapper\n"); abort(); } p = malloc(sizeof(*p)); if(p == NULL) { errno = ENOMEM; return -1; } p->func = start_routine; p->arg = arg; return sys_pthread_create(thread, attr, thread_start_wrapper, p); }