static void init_once(void) { unsigned int i; const char* val; nthreads = ARRAY_SIZE(default_threads); val = getenv("UV_THREADPOOL_SIZE"); if (val != NULL) nthreads = atoi(val); if (nthreads == 0) nthreads = 1; if (nthreads > MAX_THREADPOOL_SIZE) nthreads = MAX_THREADPOOL_SIZE; threads = default_threads; if (nthreads > ARRAY_SIZE(default_threads)) { threads = malloc(nthreads * sizeof(threads[0])); if (threads == NULL) { nthreads = ARRAY_SIZE(default_threads); threads = default_threads; } } if (uv_cond_init(&cond)) abort(); if (uv_mutex_init(&mutex)) abort(); QUEUE_INIT(&wq); for (i = 0; i < nthreads; i++) if (uv_thread_create(threads + i, worker, NULL)) abort(); initialized = 1; }
Graph::Graph() :thread(NULL) ,is_running(false) { uv_mutex_init(&mutex); uv_cond_init(&cv); }
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) { struct _uv_barrier* b; int rc; if (barrier == NULL || count == 0) return UV_EINVAL; b = uv__malloc(sizeof(*b)); if (b == NULL) return UV_ENOMEM; b->in = 0; b->out = 0; b->threshold = count; rc = uv_mutex_init(&b->mutex); if (rc != 0) goto error2; rc = uv_cond_init(&b->cond); if (rc != 0) goto error; barrier->b = b; return 0; error: uv_mutex_destroy(&b->mutex); error2: uv__free(b); return rc; }
static void saturate_threadpool(void) { uv_work_t* req; ASSERT(0 == uv_cond_init(&signal_cond)); ASSERT(0 == uv_mutex_init(&signal_mutex)); ASSERT(0 == uv_mutex_init(&wait_mutex)); uv_mutex_lock(&signal_mutex); uv_mutex_lock(&wait_mutex); for (num_threads = 0; /* empty */; num_threads++) { req = malloc(sizeof(*req)); ASSERT(req != NULL); ASSERT(0 == uv_queue_work(uv_default_loop(), req, work_cb, done_cb)); /* Expect to get signalled within 350 ms, otherwise assume that * the thread pool is saturated. As with any timing dependent test, * this is obviously not ideal. */ if (uv_cond_timedwait(&signal_cond, &signal_mutex, (uint64_t)(350 * 1e6))) { ASSERT(0 == uv_cancel((uv_req_t*) req)); break; } } }
LatencyAwarePolicyTest() : ccm_(new CCM::Bridge("config.txt")) , cluster_(cass_cluster_new()) , thread_() { uv_mutex_init(&lock_); uv_cond_init(&condition_); // Create the cluster if (ccm_->create_cluster(3)) { ccm_->start_cluster(); } // Initialize the cluster for latency aware cass_cluster_set_reconnect_wait_time(cluster_.get(), 1); cass_cluster_set_connect_timeout(cluster_.get(), 240 * test_utils::ONE_SECOND_IN_MICROS); cass_cluster_set_request_timeout(cluster_.get(), 240 * test_utils::ONE_SECOND_IN_MICROS); test_utils::initialize_contact_points(cluster_.get(), ccm_->get_ip_prefix(), 3, 0); cass_cluster_set_latency_aware_routing(cluster_.get(), cass_true); cass_cluster_set_latency_aware_routing_settings(cluster_.get(), 1e6, 1, 1, 1, 1); // Handle deprecated and removed protocol versions [CASSANDRA-10146] // https://issues.apache.org/jira/browse/CASSANDRA-10146 int protocol_version = 1; if (test_utils::get_version() >= "3.0.0") { protocol_version = 3; } cass_cluster_set_protocol_version(cluster_.get(), protocol_version); // Protocol for this test doesn't matter so simply support all C* versions // Connect to the cluster session_ = test_utils::create_session(cluster_.get()); }
int uv_chan_init(uv_chan_t *chan) { int r = uv_mutex_init(&chan->mutex); if (r == -1) return r; QUEUE_INIT(&chan->q); return uv_cond_init(&chan->cond); }
int status_init(Status* status, int initial_count) { int rc; rc = uv_mutex_init(&status->mutex); if (rc != 0) return rc; rc = uv_cond_init(&status->cond); if (rc != 0) return rc; status->count = initial_count; return rc; }
// initialize the threading infrastructure void jl_init_threadinginfra(void) { /* initialize the synchronization trees pool and the multiqueue */ multiq_init(); /* initialize the sleep mechanism */ uv_mutex_init(&sleep_lock); uv_cond_init(&sleep_alarm); }
UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler) { UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData)); rv->ui = ui; rv->bridge.rgb = ui->rgb; rv->bridge.stop = ui_bridge_stop; rv->bridge.resize = ui_bridge_resize; rv->bridge.clear = ui_bridge_clear; rv->bridge.eol_clear = ui_bridge_eol_clear; rv->bridge.cursor_goto = ui_bridge_cursor_goto; rv->bridge.mode_info_set = ui_bridge_mode_info_set; rv->bridge.update_menu = ui_bridge_update_menu; rv->bridge.busy_start = ui_bridge_busy_start; rv->bridge.busy_stop = ui_bridge_busy_stop; rv->bridge.mouse_on = ui_bridge_mouse_on; rv->bridge.mouse_off = ui_bridge_mouse_off; rv->bridge.mode_change = ui_bridge_mode_change; rv->bridge.set_scroll_region = ui_bridge_set_scroll_region; rv->bridge.scroll = ui_bridge_scroll; rv->bridge.highlight_set = ui_bridge_highlight_set; rv->bridge.put = ui_bridge_put; rv->bridge.bell = ui_bridge_bell; rv->bridge.visual_bell = ui_bridge_visual_bell; rv->bridge.update_fg = ui_bridge_update_fg; rv->bridge.update_bg = ui_bridge_update_bg; rv->bridge.update_sp = ui_bridge_update_sp; rv->bridge.flush = ui_bridge_flush; rv->bridge.suspend = ui_bridge_suspend; rv->bridge.set_title = ui_bridge_set_title; rv->bridge.set_icon = ui_bridge_set_icon; rv->scheduler = scheduler; for (UIWidget i = 0; (int)i < UI_WIDGETS; i++) { rv->bridge.ui_ext[i] = ui->ui_ext[i]; } rv->ui_main = ui_main; uv_mutex_init(&rv->mutex); uv_cond_init(&rv->cond); uv_mutex_lock(&rv->mutex); rv->ready = false; if (uv_thread_create(&rv->ui_thread, ui_thread_run, rv)) { abort(); } while (!rv->ready) { uv_cond_wait(&rv->cond, &rv->mutex); } uv_mutex_unlock(&rv->mutex); ui_attach_impl(&rv->bridge); return &rv->bridge; }
void Log::construct(cval<bool>& enabled, cval<std::string>& dir, cval<std::string>& fileName) { this->stop = true; this->logWritterThreadStarted = false; uv_mutex_init(&this->messageListMutex); uv_cond_init(&this->messageListCond); enabled.addListener(this, &updateEnabled); dir.addListener(this, &updateFile); fileName.addListener(this, &updateFile); updateEnabled(this, &enabled); }
int bmon_init(batch_monitor_t* batch, int batch_period, int (*item_cmp)( void* a, void* b, void* udata), int (*commit)(batch_monitor_t* m, batch_queue_t* bq)) { uv_mutex_init(&batch->lock); uv_cond_init(&batch->done); batch->queues[0].queue = heap_new((void*)item_cmp, NULL); batch->queues[1].queue = heap_new((void*)item_cmp, NULL); batch->nanos = batch_period; batch->commit = commit; return 0; }
void Start() { if(isRunning) { return; } isRunning = true; uv_mutex_init(¬ify_mutex); uv_async_init(uv_default_loop(), &async_handler, cbAsync); uv_signal_init(uv_default_loop(), &term_signal); uv_signal_init(uv_default_loop(), &int_signal); uv_cond_init(¬ifyDeviceHandled); uv_queue_work(uv_default_loop(), &work_req, cbWork, cbAfter); }
static luv_queue_t* luv_queue_create(const char* name, int limit) { if (name == NULL) { return NULL; } size_t name_len = strlen(name); luv_queue_t* queue = (luv_queue_t*)malloc(sizeof(luv_queue_t) + name_len + 1); queue->name = (char*)queue + sizeof(luv_queue_t); memcpy(queue->name, name, name_len + 1); queue->msg_head = queue->msg_tail = NULL; queue->limit = limit; queue->count = 0; queue->prev = queue->next = NULL; queue->refs = 1; uv_mutex_init(&queue->lock); uv_cond_init(&queue->send_sig); uv_cond_init(&queue->recv_sig); // printf("queue_create: %s, limit=%d\n", name, limit); return queue; }
CX264Encoder::CX264Encoder(uv_loop_t* loop) : b_stop(true) , h(NULL) , nal(NULL) , width(320), height(240) , i_frame(0) , i_frame_size(0) , i_nal(0) , p_loop(loop) , p_user_data(NULL) , fn_cb(NULL) , CResource(e_rsc_x264encoder) { uv_mutex_init(&queue_mutex); uv_cond_init(&queue_not_empty); }
static int Condition_tp_init(Condition *self, PyObject *args, PyObject *kwargs) { UNUSED_ARG(args); UNUSED_ARG(kwargs); RAISE_IF_INITIALIZED(self, -1); if (uv_cond_init(&self->uv_condition)) { PyErr_SetString(PyExc_ThreadError, "Error initializing Condition"); return -1; } self->initialized = True; return 0; }
void consinit(void) { uv_mutex_init(&line_lock); uv_cond_init(&line_ready); kbdq = qopen(512, 0, nil, nil); if(kbdq == 0) panic("no memory"); lineq = qopen(2*1024, 0, nil, nil); if(lineq == 0) panic("no memory"); gkbdq = qopen(512, 0, nil, nil); if(gkbdq == 0) panic("no memory"); randominit(); }
static mrb_value mrb_uv_cond_init(mrb_state *mrb, mrb_value self) { int err; uv_cond_t *cond; cond = (uv_cond_t*)mrb_malloc(mrb, sizeof(uv_cond_t)); err = uv_cond_init(cond); if (err < 0) { mrb_free(mrb, cond); mrb_uv_check_error(mrb, err); } DATA_PTR(self) = cond; DATA_TYPE(self) = &mrb_uv_cond_type; return self; }
int CAudioDecoder::init(void) { int ret = 0; if (!bInit){ uv_mutex_init(&queue_mutex); uv_cond_init(&queue_not_empty); // Register all formats and codecs av_register_all(); if (ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); } bInit = true; } return ret; }
static void init_threads(void) { unsigned int i; const char* val; nthreads = ARRAY_SIZE(default_threads); val = getenv("UV_THREADPOOL_SIZE"); if (val != NULL) nthreads = atoi(val); if (nthreads == 0) nthreads = 1; if (nthreads > MAX_THREADPOOL_SIZE) nthreads = MAX_THREADPOOL_SIZE; threads = default_threads; if (nthreads > ARRAY_SIZE(default_threads)) { threads = uv__malloc(nthreads * sizeof(threads[0])); if (threads == NULL) { nthreads = ARRAY_SIZE(default_threads); threads = default_threads; } } if (uv_cond_init(&cond)) abort(); if (uv_mutex_init(&mutex)) abort(); QUEUE_INIT(&wq); for (i = 0; i < nthreads; i++) { #ifndef _WIN32 struct data_t *data = malloc(sizeof(struct data_t)); memset(data, '\0', sizeof(struct data_t)); data->nr = i; if (uv_thread_create(threads + i, worker, data)) abort(); #else if (uv_thread_create(threads + i, worker, NULL)) abort(); #endif } initialized = 1; }
static void init_threads(void) { unsigned int i; const char* val; uv_sem_t sem; nthreads = ARRAY_SIZE(default_threads); val = getenv("UV_THREADPOOL_SIZE"); if (val != NULL) nthreads = atoi(val); if (nthreads == 0) nthreads = 1; if (nthreads > MAX_THREADPOOL_SIZE) nthreads = MAX_THREADPOOL_SIZE; threads = default_threads; if (nthreads > ARRAY_SIZE(default_threads)) { threads = (uv_thread_t*)uv__malloc(nthreads * sizeof(threads[0])); if (threads == NULL) { nthreads = ARRAY_SIZE(default_threads); threads = default_threads; } } if (uv_cond_init(&cond)) abort(); if (uv_mutex_init(&mutex)) abort(); QUEUE_INIT(&wq); if (uv_sem_init(&sem, 0)) abort(); for (i = 0; i < nthreads; i++) if (uv_thread_create(threads + i, worker, &sem)) abort(); for (i = 0; i < nthreads; i++) uv_sem_wait(&sem); uv_sem_destroy(&sem); }
int main() { uv_thread_t thread; worker_config wc; memset(&wc, 0, sizeof(wc)); uv_cond_init(&wc.cond); uv_mutex_init(&wc.mutex); uv_thread_create(&thread, worker, &wc); uv_mutex_lock(&wc.mutex); uv_cond_wait(&wc.cond, &wc.mutex); uv_mutex_unlock(&wc.mutex); uv_thread_join(&thread); uv_mutex_destroy(&wc.mutex); uv_cond_destroy(&wc.cond); return 0; }
struct rrdeng_page_cache_descr *pg_cache_create_descr(void) { struct rrdeng_page_cache_descr *descr; descr = mallocz(sizeof(*descr)); descr->page = NULL; descr->page_length = 0; descr->start_time = INVALID_TIME; descr->end_time = INVALID_TIME; descr->id = NULL; descr->extent = NULL; descr->flags = 0; descr->prev = descr->next = descr->private = NULL; descr->refcnt = 0; descr->waiters = 0; descr->handle = NULL; assert(0 == uv_cond_init(&descr->cond)); assert(0 == uv_mutex_init(&descr->mutex)); return descr; }
int ti_threadgroup_create(uint8_t num_sockets, uint8_t num_cores, uint8_t num_threads_per_core, ti_threadgroup_t **newtg) { int i; ti_threadgroup_t *tg; int num_threads = num_sockets * num_cores * num_threads_per_core; char *cp; tg = (ti_threadgroup_t*)jl_malloc_aligned(sizeof(ti_threadgroup_t), 64); tg->tid_map = (int16_t*)jl_malloc_aligned(num_threads * sizeof(int16_t), 64); for (i = 0; i < num_threads; ++i) tg->tid_map[i] = -1; tg->num_sockets = num_sockets; tg->num_cores = num_cores; tg->num_threads_per_core = num_threads_per_core; tg->num_threads = num_threads; tg->added_threads = 0; tg->thread_sense = (ti_thread_sense_t**) jl_malloc_aligned(num_threads * sizeof(ti_thread_sense_t*), 64); for (i = 0; i < num_threads; i++) tg->thread_sense[i] = NULL; tg->group_sense = 0; tg->forked = 0; uv_mutex_init(&tg->alarm_lock); uv_cond_init(&tg->alarm); tg->sleep_threshold = DEFAULT_THREAD_SLEEP_THRESHOLD; cp = getenv(THREAD_SLEEP_THRESHOLD_NAME); if (cp) { if (!strncasecmp(cp, "infinite", 8)) tg->sleep_threshold = 0; else tg->sleep_threshold = (uint64_t)strtol(cp, NULL, 10); } *newtg = tg; return 0; }
static int uv__custom_sem_init(uv_sem_t* sem_, unsigned int value) { int err; uv_semaphore_t* sem; sem = (uv_semaphore_t*)uv__malloc(sizeof(*sem)); if (sem == NULL) return UV_ENOMEM; if ((err = uv_mutex_init(&sem->mutex)) != 0) { uv__free(sem); return err; } if ((err = uv_cond_init(&sem->cond)) != 0) { uv_mutex_destroy(&sem->mutex); uv__free(sem); return err; } sem->value = value; *(uv_semaphore_t**)sem_ = sem; return 0; }
int main() { CassCluster* cluster = create_cluster(); CassSession* session = cass_session_new(); uuid_gen = cass_uuid_gen_new(); uv_mutex_init(&mutex); uv_cond_init(&cond); connect_session(session, cluster, on_session_connect); /* Code running in parallel with queries */ wait_exit(); uv_cond_destroy(&cond); uv_mutex_destroy(&mutex); cass_cluster_free(cluster); cass_uuid_gen_free(uuid_gen); cass_session_free(session); return 0; }
LatencyAwarePolicyTest() : ccm_(new CCM::Bridge("config.txt")) , cluster_(cass_cluster_new()) , thread_() { uv_mutex_init(&lock_); uv_cond_init(&condition_); // Create the cluster if (ccm_->create_cluster(3)) { ccm_->start_cluster(); } // Initialize the cluster for latency aware cass_cluster_set_reconnect_wait_time(cluster_.get(), 1); cass_cluster_set_connect_timeout(cluster_.get(), 240 * test_utils::ONE_SECOND_IN_MICROS); cass_cluster_set_request_timeout(cluster_.get(), 240 * test_utils::ONE_SECOND_IN_MICROS); test_utils::initialize_contact_points(cluster_.get(), ccm_->get_ip_prefix(), 3, 0); cass_cluster_set_latency_aware_routing(cluster_.get(), cass_true); cass_cluster_set_latency_aware_routing_settings(cluster_.get(), 1e6, 1, 1, 1, 1); cass_cluster_set_protocol_version(cluster_.get(), 1); // Protocol for this test doesn't matter so simply support all C* versions // Connect to the cluster session_ = test_utils::create_session(cluster_.get()); }
/// Initializes the time module void time_init() { uv_mutex_init(&delay_mutex); uv_cond_init(&delay_cond); }
int CVideoDecoder2::Init(void) { int ret = -1; while (!bInit){ pQueueMutex = (uv_mutex_t*)malloc(sizeof(uv_mutex_t)); if(!pQueueMutex){ ret = -1; break; } ret = uv_mutex_init(pQueueMutex); if (ret < 0){ free(pQueueMutex); pQueueMutex = NULL; break; } pQueueNotEmpty = (uv_cond_t*)malloc(sizeof(uv_cond_t)); if(!pQueueNotEmpty){ ret = -1; break; } ret = uv_cond_init(pQueueNotEmpty); if (ret < 0){ free(pQueueNotEmpty); pQueueNotEmpty = NULL; break; } // Register all codecs avcodec_register_all(); pCodec = avcodec_find_decoder(codecId); if (!pCodec){ ret = -1; break; } pCodecCtx = avcodec_alloc_context3(pCodec); if (!pCodecCtx){ ret = -1; break; } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0){ ret = -1; break; } pCodecParserCtx = av_parser_init(codecId); if (!pCodecParserCtx){ ret = -1; break; } decodeWorkerReq.data = this; ret = uv_queue_work(pLoop, &decodeWorkerReq, DecodeWorker, AfterDecode); if(ret < 0){ bStop = true; break; } bInit = true; } if (!bInit){ Finit(); return -1; } else { return 0; } }
void pc__client_init(pc_client_t *client) { client->listeners = pc_map_new(256, pc__release_listeners); if(client->listeners == NULL) { fprintf(stderr, "Fail to init client->listeners.\n"); abort(); } client->requests = pc_map_new(256, pc__release_requests); if(client->requests == NULL) { fprintf(stderr, "Fail to init client->requests.\n"); abort(); } client->pkg_parser = pc_pkg_parser_new(pc__pkg_cb, client); if(client->pkg_parser == NULL) { fprintf(stderr, "Fail to init client->pkg_parser.\n"); abort(); } client->heartbeat_timer = (uv_timer_t *)pc_jsonp_malloc(sizeof(uv_timer_t)); if(client->heartbeat_timer == NULL) { fprintf(stderr, "Fail to malloc client->heartbeat_timer.\n"); abort(); } if(uv_timer_init(client->uv_loop, client->heartbeat_timer)) { fprintf(stderr, "Fail to init client->heartbeat_timer.\n"); abort(); } client->heartbeat_timer->timer_cb = pc__heartbeat_cb; client->heartbeat_timer->data = client; client->heartbeat = 0; client->timeout_timer = (uv_timer_t *)pc_jsonp_malloc(sizeof(uv_timer_t)); if(client->timeout_timer == NULL) { fprintf(stderr, "Fail to malloc client->timeout_timer.\n"); abort(); } if(uv_timer_init(client->uv_loop, client->timeout_timer)) { fprintf(stderr, "Fail to init client->timeout_timer.\n"); abort(); } client->timeout_timer->timer_cb = pc__timeout_cb; client->timeout_timer->data = client; client->timeout = 0; client->close_async = (uv_async_t *)pc_jsonp_malloc(sizeof(uv_async_t)); uv_async_init(client->uv_loop, client->close_async, pc__close_async_cb); client->close_async->data = client; uv_mutex_init(&client->mutex); uv_cond_init(&client->cond); uv_mutex_init(&client->listener_mutex); uv_mutex_init(&client->state_mutex); // init package parser client->parse_msg = pc__default_msg_parse_cb; client->parse_msg_done = pc__default_msg_parse_done_cb; // init package encoder client->encode_msg = pc__default_msg_encode_cb; client->encode_msg_done = pc__default_msg_encode_done_cb; client->state = PC_ST_INITED; }
condition_variable_impl() { if (uv_cond_init(&cond_)) { assert(false); } }