Example #1
0
pn_event_t *pn_collector_put(pn_collector_t *collector,
                             const pn_class_t *clazz, void *context,
                             pn_event_type_t type)
{
  if (!collector) {
    return NULL;
  }

  assert(context);

  if (collector->freed) {
    return NULL;
  }

  pn_event_t *tail = collector->tail;
  if (tail && tail->type == type && tail->context == context) {
    return NULL;
  }

  clazz = clazz->reify(context);

  pn_event_t *event = (pn_event_t *) pn_list_pop(collector->pool);

  if (!event) {
    event = pn_event();
  }

  event->pool = collector->pool;
  pn_incref(event->pool);

  if (tail) {
    tail->next = event;
    collector->tail = event;
  } else {
    collector->tail = event;
    collector->head = event;
  }

  event->clazz = clazz;
  event->context = context;
  event->type = type;
  pn_class_incref(clazz, event->context);

  return event;
}
Example #2
0
void *pn_list_minpop(pn_list_t *list)
{
  assert(list);
  // we use one based indexing for the heap
  void **heap = list->elements - 1;
  void *min = heap[1];
  void *last = pn_list_pop(list);
  int size = pn_list_size(list);
  int now, child;
  for (now = 1; now*2 <= size; now = child) {
    child = now*2;
    if (child != size && pn_class_compare(list->clazz, heap[child], heap[child + 1]) > 0) {
      child++;
    }
    if (pn_class_compare(list->clazz, last, heap[child]) > 0) {
      heap[now] = heap[child];
    } else {
      break;
    }
  }
  heap[now] = last;
  return min;
}