Example #1
0
File: hal.c Project: morrey/bt_bcm
static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) {
  static hash_map_t *timers;

  if (!timers) {
    timers = hash_map_new(TIMER_BUCKET_COUNT, hash_function_pointer, NULL, NULL, NULL);
  }

  timer_t *timer = hash_map_get(timers, cb);
  if (!timer) {
    timer = malloc(sizeof(timer_t));
    hash_map_set(timers, cb, timer);

    struct sigevent sigevent;
    memset(&sigevent, 0, sizeof(sigevent));
    sigevent.sigev_notify = SIGEV_THREAD;
    sigevent.sigev_notify_function = (void (*)(union sigval))cb;
    sigevent.sigev_value.sival_ptr = data;
    timer_create(CLOCK_MONOTONIC, &sigevent, timer);
  }

  struct itimerspec new_value;
  new_value.it_value.tv_sec = delay_millis / 1000;
  new_value.it_value.tv_nsec = (delay_millis % 1000) * 1000 * 1000;
  new_value.it_interval.tv_sec = 0;
  new_value.it_interval.tv_nsec = 0;
  if(!timer){
      return false;
  } else {
       timer_settime(*timer, 0, &new_value, NULL);
       return true;
  }

}
data_dispatcher_t *data_dispatcher_new(const char *name) {
  assert(name != NULL);

  data_dispatcher_t *ret = osi_calloc(sizeof(data_dispatcher_t));
  if (!ret) {
    LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new data dispatcher.", __func__);
    goto error;
  }

  ret->dispatch_table = hash_map_new(DEFAULT_TABLE_BUCKETS, hash_function_naive, NULL, NULL, NULL);
  if (!ret->dispatch_table) {
    LOG_ERROR(LOG_TAG, "%s unable to create dispatch table.", __func__);
    goto error;
  }

  ret->name = osi_strdup(name);
  if (!ret->name) {
    LOG_ERROR(LOG_TAG, "%s unable to duplicate provided name.", __func__);
    goto error;
  }

  return ret;

error:;
  data_dispatcher_free(ret);
  return NULL;
}
Example #3
0
static void background_connections_lazy_init()
{
  if (!background_connections) {
    background_connections = hash_map_new(background_connection_buckets,
                                      hash_function_bdaddr, NULL, osi_free, bdaddr_equality_fn);
    assert(background_connections);
  }
}
Example #4
0
/*****************************************************************************
**
** Function         BTU_StartUp
**
** Description      Initializes the BTU control block.
**
**                  NOTE: Must be called before creating any tasks
**                      (RPC, BTU, HCIT, APPL, etc.)
**
** Returns          void
**
******************************************************************************/
void BTU_StartUp(void)
{
#if BTU_DYNAMIC_MEMORY
    btu_cb_ptr = (tBTU_CB *)osi_malloc(sizeof(tBTU_CB));
#endif /* #if BTU_DYNAMIC_MEMORY */
    memset (&btu_cb, 0, sizeof (tBTU_CB));
    btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL;

    btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE,
                                 hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_general_alarm_hash_map == NULL) {
        goto error_exit;
    }

    osi_mutex_new(&btu_general_alarm_lock);

    btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE,
                                 hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_oneshot_alarm_hash_map == NULL) {
        goto error_exit;
    }

    osi_mutex_new(&btu_oneshot_alarm_lock);

    btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE,
                                            hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_l2cap_alarm_hash_map == NULL) {
        goto error_exit;
    }

    osi_mutex_new(&btu_l2cap_alarm_lock);

    xBtuQueue = xQueueCreate(BTU_QUEUE_LEN, sizeof(BtTaskEvt_t));
    xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, BTU_TASK_PINNED_TO_CORE);

    btu_task_post(SIG_BTU_START_UP, NULL, TASK_POST_BLOCKING);

    return;

error_exit:;
    LOG_ERROR("%s Unable to allocate resources for bt_workqueue", __func__);
    BTU_ShutDown();
}
Example #5
0
void module_management_start(void) {
  metadata = hash_map_new(
    number_of_metadata_buckets,
    hash_function_pointer,
    NULL,
    osi_free,
    NULL
  );

  pthread_mutex_init(&metadata_lock, NULL);
}
Example #6
0
static future_t *init(void) {
  peers_by_address = hash_map_new(
    number_of_address_buckets,
    hash_function_bdaddr,
    NULL,
    osi_free,
    bdaddr_equality_fn);

  pthread_mutex_init(&bag_of_peers_lock, NULL);

  initialized = true;
  return NULL;
}
Example #7
0
hash_map_t *hash_map_utils_new_from_string_params(const char *params) {
  assert(params != NULL);

  hash_map_t *map = hash_map_new(BUCKETS_NUM, hash_function_string, osi_free,
                                 osi_free, string_equals);
  if (!map)
    return NULL;

  char *str = osi_strdup(params);
  if (!str)
    return NULL;

  LOG_VERBOSE(LOG_TAG, "%s: source string: '%s'", __func__, str);

  // Parse |str| and add extracted key-and-value pair(s) in |map|.
  int items = 0;
  char *tmpstr;
  char *kvpair = strtok_r(str, ";", &tmpstr);
  while (kvpair && *kvpair) {
    char *eq = strchr(kvpair, '=');

    if (eq == kvpair)
      goto next_pair;

    char *key;
    char *value;
    if (eq) {
      key = osi_strndup(kvpair, eq - kvpair);

      // The increment of |eq| moves |eq| to the beginning of the value.
      ++eq;
      value = (*eq != '\0') ? osi_strdup(eq) : osi_strdup("");
    } else {
      key = osi_strdup(kvpair);
      value = osi_strdup("");
    }

    hash_map_set(map, key, value);

    items++;
next_pair:
    kvpair = strtok_r(NULL, ";", &tmpstr);
  }

  if (!items)
    LOG_VERBOSE(LOG_TAG, "%s: no items found in string\n", __func__);

  osi_free(str);
  return map;
}
Example #8
0
dict* dict_new(int n)
{
    dict * d = pdf_malloc(sizeof(dict));
    if (d)
    {
#if defined(HASHMAP)
        d->dict = hash_map_new(n);
#else
        d->dict = NULL;
#endif
	    d->n = 0;
	    d->stream = 0;
    }
    return d;
}
Example #9
0
/*****************************************************************************
**
** Function         BTU_StartUp
**
** Description      Initializes the BTU control block.
**
**                  NOTE: Must be called before creating any tasks
**                      (RPC, BTU, HCIT, APPL, etc.)
**
** Returns          void
**
******************************************************************************/
void BTU_StartUp(void)
{
    memset (&btu_cb, 0, sizeof (tBTU_CB));
    btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL;

    btu_bta_msg_queue = fixed_queue_new(SIZE_MAX);
    if (btu_bta_msg_queue == NULL) {
        goto error_exit;
    }

    btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE,
                                 hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_general_alarm_hash_map == NULL) {
        goto error_exit;
    }

    pthread_mutex_init(&btu_general_alarm_lock, NULL);

    btu_general_alarm_queue = fixed_queue_new(SIZE_MAX);
    if (btu_general_alarm_queue == NULL) {
        goto error_exit;
    }

    btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE,
                                 hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_oneshot_alarm_hash_map == NULL) {
        goto error_exit;
    }

    pthread_mutex_init(&btu_oneshot_alarm_lock, NULL);

    btu_oneshot_alarm_queue = fixed_queue_new(SIZE_MAX);
    if (btu_oneshot_alarm_queue == NULL) {
        goto error_exit;
    }

    btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE,
                                            hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
    if (btu_l2cap_alarm_hash_map == NULL) {
        goto error_exit;
    }

    pthread_mutex_init(&btu_l2cap_alarm_lock, NULL);

    btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX);
    if (btu_l2cap_alarm_queue == NULL) {
        goto error_exit;
    }

    xBtuQueue = xQueueCreate(BTU_QUEUE_NUM, sizeof(BtTaskEvt_t));
    xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, 0);
    btu_task_post(SIG_BTU_START_UP);
    /*
        // Continue startup on bt workqueue thread.
        thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
    */
    return;

error_exit:;
    LOG_ERROR("%s Unable to allocate resources for bt_workqueue", __func__);
    BTU_ShutDown();
}
Example #10
0
static void init(const packet_fragmenter_callbacks_t *result_callbacks)
{
    current_fragment_packet = NULL;
    callbacks = result_callbacks;
    partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL, NULL);
}