예제 #1
0
static int add_context(const struct nodeID *local,
                       struct cloud_helper_context *ctx)
{
  int i;
  struct ctx_map_entry *entry;

  /* Checks whether the queue is already initialized */
  if (ctx_map == NULL) {
    ctx_map = fifo_queue_create(CLOUD_HELPER_INITAIL_INSTANCES);
    if (!ctx_map) {
      return 1;
    }
  }

  /* Check if the node is already present in the ctx_map */
  for (i=0; i<fifo_queue_size(ctx_map); i++) {
    entry = fifo_queue_get(ctx_map, i);
    if (nodeid_equal(entry->node, local)) {
      return 1;
    }
  }

  /* Add the new entry to the ctx_map */
  entry = malloc(sizeof(struct ctx_map_entry));
  if (!entry) {
    return 1;
  }

  entry->node = local;
  entry->cloud_ctx = ctx;

  if (fifo_queue_add(ctx_map, entry) != 0) {
    free (entry);
    return 1;
  }

  return 0;
}
예제 #2
0
파일: fifo_queue.c 프로젝트: thibugio/813
void fifo_queue_clear(struct fifo_queue* fq) {
    free(fq);
    fq = fifo_queue_create();
}