int Thread::fork_attached(STATE) { pthread_attr_t attrs; pthread_attr_init(&attrs); pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE); return start_new_thread(state, attrs); }
Object* Thread::fork(STATE) { pthread_attr_t attrs; pthread_attr_init(&attrs); pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE); pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); int error = start_new_thread(state, attrs); if(error) { Exception::thread_error(state, strerror(error)); } return cNil; }
static int fmaster_thr_new_main(struct thread *td, struct fmaster_thr_new_args *uap) { uint64_t token_size; int error; char *token; error = order_slave(td, &token, &token_size); if (error != 0) return (error); error = start_new_thread(td, uap, token, token_size); if (error != 0) return (error); return (0); }
Object* Thread::fork(STATE) { // If the thread is already alive or already ran, // we can't use it anymore. if(CBOOL(alive()) || !vm_) { return Primitives::failure(); } pthread_attr_t attrs; pthread_attr_init(&attrs); pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE); pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); int error = start_new_thread(state, attrs); if(error) { Exception::thread_error(state, strerror(error)); } return cNil; }
int init_hw(int i) { char name[100]; adapter *ad; if (i < 0 || i >= MAX_ADAPTERS) return 1; if (a[i] && a[i]->enabled) return 1; if (!a[i]) return 1; ad = a[i]; mutex_init(&ad->mutex); mutex_lock(&ad->mutex); if (ad->force_disable) goto NOK; if (ad->enabled) goto NOK; ad->sock = -1; ad->id = i; ad->fe_sock = -1; ad->sock = -1; if (ad->enabled) { goto NOK; } if (ad->open(ad)) { init_complete = 0; goto NOK; } ad->enabled = 1; if (!ad->buf) ad->buf = malloc1(opts.adapter_buffer + 10); if (!ad->buf) { LOG( "memory allocation failed for %d bytes failed, adapter %d, trying %d bytes", opts.adapter_buffer, i, ADAPTER_BUFFER); opts.adapter_buffer = ADAPTER_BUFFER; ad->buf = malloc1(opts.adapter_buffer + 10); if (!ad->buf) { LOG("memory allocation failed for %d bytes failed, adapter %d", opts.adapter_buffer, i); close_adapter(i); } goto NOK; } memset(ad->buf, 0, opts.adapter_buffer + 1); init_dvb_parameters(&ad->tp); mark_pids_deleted(i, -1, NULL); update_pids(i); ad->delsys(i, ad->fe, ad->sys); ad->master_sid = -1; ad->sid_cnt = 0; ad->pid_err = ad->dec_err = 0; ad->new_gs = 0; ad->force_close = 0; ad->ca_mask = 0; ad->rtime = getTick(); ad->sock = sockets_add(ad->dvr, NULL, i, TYPE_DVR, (socket_action) read_dmx, (socket_action) close_adapter_for_socket, (socket_action) adapter_timeout); memset(ad->buf, 0, opts.adapter_buffer + 1); set_socket_buffer(ad->sock, (unsigned char*) ad->buf, opts.adapter_buffer); sockets_timeout(ad->sock, ADAPTER_TIMEOUT); snprintf(ad->name, sizeof(ad->name), "AD%d", i); set_socket_thread(ad->sock, start_new_thread(ad->name)); tables_init_device(ad); if (ad->post_init) ad->post_init(ad); // set_sock_lock(ad->sock, &ad->mutex); // locks automatically the adapter on reading from the DVR LOG("done opening adapter %i fe_sys %d %d %d %d", i, ad->sys[0], ad->sys[1], ad->sys[2], ad->sys[3]); OK: mutex_unlock(&ad->mutex); return 0; NOK: mutex_unlock(&ad->mutex); return 1; }