void embb_mtapi_group_initialize(embb_mtapi_group_t * that) { assert(MTAPI_NULL != that); that->group_id = MTAPI_GROUP_ID_NONE; that->deleted = MTAPI_FALSE; that->num_tasks.internal_variable = 0; embb_mtapi_task_queue_initialize(&that->queue); }
mtapi_boolean_t embb_mtapi_thread_context_initialize( embb_mtapi_thread_context_t* that, embb_mtapi_node_t* node, mtapi_uint_t worker_index, mtapi_uint_t core_num, embb_thread_priority_t priority) { mtapi_uint_t ii; mtapi_boolean_t result = MTAPI_TRUE; assert(MTAPI_NULL != that); assert(MTAPI_NULL != node); that->node = node; that->worker_index = worker_index; that->core_num = core_num; that->priorities = node->attributes.max_priorities; that->is_initialized = MTAPI_FALSE; that->thread_priority = priority; that->is_main_thread = (worker_index == 0) ? node->attributes.reuse_main_thread : MTAPI_FALSE; embb_atomic_init_int(&that->run, 0); embb_atomic_init_int(&that->is_sleeping, 0); that->queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate( sizeof(embb_mtapi_task_queue_t*)*that->priorities); if (that->queue == NULL) { that->private_queue = NULL; return MTAPI_FALSE; } for (ii = 0; ii < that->priorities; ii++) { that->queue[ii] = (embb_mtapi_task_queue_t*) embb_mtapi_alloc_allocate(sizeof(embb_mtapi_task_queue_t)); if (that->queue[ii] != NULL) { embb_mtapi_task_queue_initialize(that->queue[ii]); } else { result = MTAPI_FALSE; } } if (!result) { return MTAPI_FALSE; } that->private_queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate( sizeof(embb_mtapi_task_queue_t*)*that->priorities); if (that->private_queue == NULL) { return MTAPI_FALSE; } for (ii = 0; ii < that->priorities; ii++) { that->private_queue[ii] = (embb_mtapi_task_queue_t*) embb_mtapi_alloc_allocate(sizeof(embb_mtapi_task_queue_t)); if (that->private_queue[ii] != NULL) { embb_mtapi_task_queue_initialize(that->private_queue[ii]); } else { result = MTAPI_FALSE; } } if (!result) { return MTAPI_FALSE; } embb_mutex_init(&that->work_available_mutex, EMBB_MUTEX_PLAIN); embb_condition_init(&that->work_available); that->is_initialized = MTAPI_TRUE; return MTAPI_TRUE; }