Beispiel #1
0
static void
pull_next_local_msgid(fq_msgid *msgid) {
  uint32_t last;
  fq_msgid g;
again:
  memcpy(&g, &local_msgid, sizeof(fq_msgid));
  memcpy(msgid, &g, sizeof(fq_msgid));
  last = ck_pr_faa_32(&local_msgid.id.u32.p1, 1);
  msgid->id.u32.p1 = last + 1;
  if(last == 0xffffffffUL) {
    last = ck_pr_faa_32(&local_msgid.id.u32.p2, 1);
    msgid->id.u32.p2 = last + 1;
    if(last == 0xffffffffUL) {
      last = ck_pr_faa_32(&local_msgid.id.u32.p3, 1);
      msgid->id.u32.p3 = last + 1;
      if(last == 0xffffffffUL) {
        last = ck_pr_faa_32(&local_msgid.id.u32.p4, 1);
        msgid->id.u32.p4 = last + 1;
      }
    }
  }
  if(msgid->id.u32.p4 < g.id.u32.p4) goto again;
  if(msgid->id.u32.p4 > g.id.u32.p4) return;
  if(msgid->id.u32.p3 < g.id.u32.p3) goto again;
  if(msgid->id.u32.p3 > g.id.u32.p3) return;
  if(msgid->id.u32.p2 < g.id.u32.p2) goto again;
  if(msgid->id.u32.p2 > g.id.u32.p2) return;
  if(msgid->id.u32.p1 > g.id.u32.p1) return;
  goto again;
}
Beispiel #2
0
static ph_thread_t *ph_thread_init_myself(bool booting)
{
  ph_thread_t *me;
  ck_epoch_record_t *er;

  er = ck_epoch_recycle(&misc_epoch);
  if (er) {
    me = ph_container_of(er, ph_thread_t, epoch_record);
  } else {
    me = calloc(1, sizeof(*me));
    if (!me) {
      ph_panic("fatal OOM in ph_thread_init_myself()");
    }
    ck_epoch_register(&misc_epoch, &me->epoch_record);
    ck_stack_push_mpmc(&ph_thread_all_threads, &me->thread_linkage);
    ph_counter_init_thread(me);
  }
#ifdef HAVE___THREAD
  __ph_thread_self = me;
#endif
  pthread_setspecific(__ph_thread_key, me);

  PH_STAILQ_INIT(&me->pending_nbio);
  PH_STAILQ_INIT(&me->pending_pool);

  me->tid = ck_pr_faa_32(&next_tid, 1);
  me->thr = pthread_self();
#ifdef __sun__
  me->lwpid = _lwp_self();
#endif

#if defined(__linux__) || defined(__MACH__)
  // see if we can discover our thread name from the system
  pthread_getname_np(me->thr, me->name, sizeof(me->name));
#endif

  // If we were recycled from a non-phenom thread, and are initializing
  // a non-phenom thread, it is possible that there are still deferred
  // items to reap in this record, so get them now.
  if (er && !booting) {
    ck_epoch_barrier(&misc_epoch, &me->epoch_record);
  }

  return me;
}
Beispiel #3
0
as_event_loop*
as_event_set_external_loop(void* loop)
{
    uint32_t current = ck_pr_faa_32(&as_event_loop_size, 1);

    if (current >= as_event_loop_capacity) {
        as_log_error("Failed to add external loop. Capacity is %u", as_event_loop_capacity);
        return 0;
    }

    as_event_loop* event_loop = &as_event_loops[current];
    event_loop->loop = loop;
    pthread_mutex_init(&event_loop->lock, 0);
    event_loop->thread = pthread_self();  // Current thread must be same as event loop thread!
    event_loop->index = current;
    as_queue_init(&event_loop->pipe_cb_queue, sizeof(as_queued_pipe_cb), AS_EVENT_QUEUE_INITIAL_CAPACITY);
    event_loop->pipe_cb_calling = false;
    as_event_register_external_loop(event_loop);
    return event_loop;
}