コード例 #1
0
mtapi_boolean_t embb_mtapi_thread_context_start(
  embb_mtapi_thread_context_t* that,
  embb_mtapi_scheduler_t * scheduler) {
  int err;
  embb_mtapi_scheduler_worker_func_t * worker_func;
  embb_core_set_t core_set;

  assert(MTAPI_NULL != that);
  assert(MTAPI_NULL != scheduler);

  worker_func = embb_mtapi_scheduler_worker_func(scheduler);

  /* pin thread to core */
  embb_core_set_init(&core_set, 0);
  embb_core_set_add(&core_set, that->core_num);

  /* create thread */
  if (that->is_main_thread) {
    /* reuse main thread */
    that->thread = embb_thread_current();
    err = embb_tss_create(&that->tss_id);
    if (EMBB_SUCCESS != err) {
      /* report error to scheduler */
      embb_atomic_store_int(&that->run, -1);
      return MTAPI_FALSE;
    }
    embb_tss_set(&(that->tss_id), that);
    embb_atomic_store_int(&that->run, 1);
  } else {
    err = embb_thread_create_with_priority(
      &that->thread, &core_set, that->thread_priority, worker_func, that);
    if (EMBB_SUCCESS != err) {
      embb_mtapi_log_error(
        "embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
        "create thread %d on core %d\n", that->worker_index, that->core_num);
      return MTAPI_FALSE;
    }
    /* wait for worker to come up */
    while (0 == embb_atomic_load_int(&that->run)) {
      embb_thread_yield();
    }
  }

  if (0 < embb_atomic_load_int(&that->run)) {
    return MTAPI_TRUE;
  } else {
    return MTAPI_FALSE;
  }
}
コード例 #2
0
ファイル: embb_mtapi_group_t.c プロジェクト: cfeld/embb
void embb_mtapi_group_finalize(embb_mtapi_group_t * that) {
  assert(MTAPI_NULL != that);

  embb_atomic_store_int(&that->deleted, MTAPI_TRUE);
  that->num_tasks.internal_variable = 0;
  embb_mtapi_task_queue_finalize(&that->queue);
}
コード例 #3
0
ファイル: embb_mtapi_group_t.c プロジェクト: cfeld/embb
void embb_mtapi_group_initialize(embb_mtapi_group_t * that) {
  assert(MTAPI_NULL != that);

  that->group_id = MTAPI_GROUP_ID_NONE;
  embb_atomic_store_int(&that->deleted, MTAPI_FALSE);
  that->num_tasks.internal_variable = 0;
  embb_mtapi_task_queue_initialize(&that->queue);
}
コード例 #4
0
void embb_mtapi_thread_context_stop(embb_mtapi_thread_context_t* that) {
  int result;
  if (0 < embb_atomic_load_int(&that->run)) {
    embb_atomic_store_int(&that->run, 0);
    embb_condition_notify_one(&that->work_available);
    if (MTAPI_FALSE == that->is_main_thread) {
      embb_thread_join(&(that->thread), &result);
    }
  }
}
コード例 #5
0
ファイル: embb_mtapi_action_t.c プロジェクト: cfeld/embb
void embb_mtapi_action_initialize(embb_mtapi_action_t* that) {
  that->action_function = NULL;
  that->job_id = MTAPI_JOB_ID_INVALID;
  that->domain_id = MTAPI_DOMAIN_ID_INVALID;
  that->node_id = MTAPI_NODE_ID_INVALID;
  that->enabled = MTAPI_FALSE;
  that->node_local_data = NULL;
  that->node_local_data_size = 0;
  that->plugin_data = MTAPI_NULL;
  embb_atomic_store_int(&that->num_tasks, 0);
}
コード例 #6
0
ファイル: thread_index.c プロジェクト: danklmn/embb
embb_counter_t* embb_thread_index_counter() {
  int compare_to = 0;
  if (embb_atomic_load_int(&embb_thread_index_counter_flag) != 2) {
    if (embb_atomic_compare_and_swap_int(
        &embb_thread_index_counter_flag, &compare_to, 1)) {
      embb_counter_init(&embb_thread_index_counter_index);
      embb_atomic_store_int(&embb_thread_index_counter_flag, 2);
    }
    while (embb_atomic_load_int(&embb_thread_index_counter_flag) != 2) {}
  }
  return &embb_thread_index_counter_index;
}
コード例 #7
0
ファイル: embb_mtapi_group_t.c プロジェクト: cfeld/embb
void embb_mtapi_group_initialize_with_node(
  embb_mtapi_group_t * that,
  embb_mtapi_node_t * node) {
  assert(MTAPI_NULL != that);
  assert(MTAPI_NULL != node);

  that->group_id = MTAPI_GROUP_ID_NONE;
  embb_atomic_store_int(&that->deleted, MTAPI_FALSE);
  that->num_tasks.internal_variable = 0;
  embb_mtapi_task_queue_initialize_with_capacity(
    &that->queue, node->attributes.queue_limit);
}
コード例 #8
0
ファイル: thread_index.c プロジェクト: danklmn/embb
unsigned int* embb_max_number_thread_indices() {
  int compare_to = 0;
  if (embb_atomic_load_int(&embb_max_number_thread_indices_flag) != 2) {
    if (embb_atomic_compare_and_swap_int(
        &embb_max_number_thread_indices_flag, &compare_to, 1)) {
      embb_max_number_thread_indices_max =
        (int)(embb_core_count_available() * 2);
      embb_atomic_store_int(&embb_max_number_thread_indices_flag, 2);
    }
    while (embb_atomic_load_int(&embb_max_number_thread_indices_flag) != 2) {}
  }
  return (unsigned int*) &embb_max_number_thread_indices_max;
}
コード例 #9
0
ファイル: embb_mtapi_action_t.c プロジェクト: cfeld/embb
mtapi_action_hndl_t mtapi_action_create(
  MTAPI_IN mtapi_job_id_t job_id,
  MTAPI_IN mtapi_action_function_t action_function,
  MTAPI_IN void* node_local_data,
  MTAPI_IN mtapi_size_t node_local_data_size,
  MTAPI_IN mtapi_action_attributes_t* attributes,
  MTAPI_OUT mtapi_status_t* status) {
  mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
  mtapi_action_hndl_t action_handle = { 0, EMBB_MTAPI_IDPOOL_INVALID_ID };

  embb_mtapi_log_trace("mtapi_action_create() called\n");

  if (embb_mtapi_node_is_initialized()) {
    embb_mtapi_node_t* node = embb_mtapi_node_get_instance();
    /* check if job is valid */
    if (embb_mtapi_job_is_id_valid(node, job_id)) {
      embb_mtapi_job_t* job = embb_mtapi_job_get_storage_for_id(node, job_id);
      embb_mtapi_action_t* new_action =
        embb_mtapi_action_pool_allocate(node->action_pool);
      if (MTAPI_NULL != new_action) {
        new_action->domain_id = node->domain_id;
        new_action->node_id = node->node_id;
        new_action->job_id = job_id;
        new_action->node_local_data = node_local_data;
        new_action->node_local_data_size = node_local_data_size;
        new_action->enabled = MTAPI_TRUE;
        new_action->is_plugin_action = MTAPI_FALSE;
        embb_atomic_store_int(&new_action->num_tasks, 0);

        new_action->action_function = action_function;

        /* set defaults if no attributes were given */
        if (MTAPI_NULL != attributes) {
          new_action->attributes = *attributes;
          local_status = MTAPI_SUCCESS;
        } else {
          /* use the default */
          mtapi_actionattr_init(&new_action->attributes, &local_status);
        }

        /* check if affinity is sane */
        if (0 == new_action->attributes.affinity) {
          local_status = MTAPI_ERR_PARAMETER;
        }

        if (MTAPI_SUCCESS == local_status) {
          action_handle = new_action->handle;
          embb_mtapi_job_add_action(job, new_action);
        } else {
          embb_mtapi_action_pool_deallocate(node->action_pool, new_action);
        }
      } else {
        /* no more space left in action pool */
        local_status = MTAPI_ERR_ACTION_LIMIT;
      }
    } else {
      local_status = MTAPI_ERR_JOB_INVALID;
    }
  } else {
    embb_mtapi_log_error("mtapi not initialized\n");
    local_status = MTAPI_ERR_NODE_NOTINIT;
  }

  mtapi_status_set(status, local_status);
  return action_handle;
}
コード例 #10
0
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_store_int(&that->run, 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_with_capacity(
        that->queue[ii], node->attributes.queue_limit);
    } 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_with_capacity(
        that->private_queue[ii], node->attributes.queue_limit);
    } 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);
  embb_atomic_store_int(&that->is_sleeping, 0);

  that->is_initialized = MTAPI_TRUE;

  return MTAPI_TRUE;
}
コード例 #11
0
ファイル: embb_mtapi_spinlock_t.c プロジェクト: danklmn/embb
void embb_mtapi_spinlock_finalize(embb_mtapi_spinlock_t * that) {
  embb_atomic_store_int(that, 0);
}