Ejemplo n.º 1
0
int rms_shutdown(void) {
	rms_channel *channel;

	rmsb->active = 0;

	uthread_destroy(&(rmsb->rms_rcv_thr));
	uthread_destroy(&(rmsb->rms_snd_thr));
	uthread_destroy(&(rmsb->rms_mgr_thr));

	if(rmsb->listening) {
		shutdown(rmsb->sock);
		close(rmsb->sock);
	}

	while( (channel = (rms_channel*)mqueue_remove(rmsb->mq_channels))) {
		rms_channel_close(channel);
	}
	mqueue_destroy( rmsb->mq_channels);

	uthread_mutex_lock(&rmsb->mutx_rmscb);
	while( (channel = (rms_channel*)mqueue_deq(rmsb->mq_channel_tmp))) {
		rms_channel_close(channel);
	}
	mqueue_destroy( rmsb->mq_channels_tmp);
	uthread_mutex_unlock(&rmsb->mutx_rmscb);
	uthread_mutex_destroy(&rmsb->mutx_rmscb);

	rmsb->state = 0;
	free(rmsb->hostname);

	rmsb->initialized = -1;
	return 0;
}
Ejemplo n.º 2
0
static void tea_thread_cleanup(THREAD_WORK *tw)
{
  TEA_MSG_QUEUE *mq;

  /* do thread cleanup */
  TDBG2("[tea-cleanup] Thread final cleanup started.");
  if(tw->to->cleanup)
    tw->to->cleanup(tw);

  if(tw->data != NULL)
  {
    free(tw->data);
    tw->data = NULL;
  }

  /* disassociate mqueue of tw and destroy it */
  if(tw->to->listener || tw->to->sender)
  {
    pthreadex_mutex_begin(&(tw->mqueue->mutex));
    TDBG2("[tea-cleanup] listener/sender cleanup");
    mq = tw->mqueue;
    tw->mqueue = NULL;
    pthreadex_mutex_end();

    if(mq)
    {
      TDBG2("[tea-cleanup] mqueue cleanup");
      mqueue_destroy(mq);
    }
  }

  TDBG("[tea-cleanup] Thread finished.");
  pthreadex_flag_up(&(tw->cleanup_done));
}
Ejemplo n.º 3
0
void mqueuebatch_destroy(struct mqueuebatch *qs)
{
    size_t i = 0;
    for (i = 0; i < qs->qnum; i++) {
        if (qs->queues[i])
            mqueue_destroy(qs->queues[i]);
    }

    free(qs);
}
Ejemplo n.º 4
0
void udelay(int us)
{
	u8 heap[0x10];
	u32 msg;
	s32 mqueue = -1;
	s32 timer = -1;

	mqueue = mqueue_create(heap, 1);
	if(mqueue < 0)
		goto out;
	timer = TimerCreate(us, 0, mqueue, 0xbabababa);
	if(timer < 0)
		goto out;
	mqueue_recv(mqueue, &msg, 0);
	
out:
	if(timer > 0)
		TimerDestroy(timer);
	if(mqueue > 0)
		mqueue_destroy(mqueue);
}
Ejemplo n.º 5
0
static void tea_thread_new(int tid, TEA_OBJECT *to, SNODE *command)
{
  THREAD_WORK *tw = NULL;
  TEA_OBJCFG *ocline;
  HASH_ITER hi;
  HASH_NODE *hn;
  int fatal = 0;

  DBG("[tea] Creating thread %d.", tid);
  if((tw = calloc(1, sizeof(THREAD_WORK))) == NULL)
    FAT("Cannot alloc THREAD_WORK struct for thread %d.", tid);

  tw->id         = tid;
  tw->pthread_id = 0;
  tw->to         = to;
  tw->options    = hash_copy(command->command.thc.to->options);

  /* check methods */
  if(tw->to->listener || tw->to->sender)
    tw->mqueue = mqueue_create();
  pthreadex_flag_init(&(tw->mwaiting), 0);
  pthreadex_flag_name(&(tw->mwaiting), "mwaiting");
  pthreadex_flag_init(&(tw->cleanup_do), 0);
  pthreadex_flag_name(&(tw->cleanup_do), "cleanup_do");
  pthreadex_flag_init(&(tw->cleanup_done), 0);
  pthreadex_flag_name(&(tw->cleanup_done), "cleanup_done");

  /* global thread initialization here */
  if(tw->to->global_init && !tw->to->initialized)
  {
    tw->to->initialized = -1;
    tw->to->global_init();
  }

  /* make space for thread data */
  if((tw->data = calloc(1, to->datasize)) == NULL)
    FAT("%d:%s: No memory for thread data.", command->line, to->name);

  /* check config params */
  if(to->cparams)
  {
    /* check only allowed params are defined */
    for(hn = hash_iter_first(&hi, command->command.thc.to->options);
        !hash_iter_finished(&hi);
        hn = hash_iter_next(&hi))
    {
      /* iterate all allowed params and stop if (1) declared  */
      /* parameter hn->key is found in allowed paramter list, */
      /* or (2) stop if there is not moar allowed params      */
      for(ocline = to->cparams;
          ocline->name && strcasecmp(hn->key, ocline->name);
          ocline++)
        ;
      if(!ocline->name)
        FAT("%d:%s: Parameter %s not allowed here.", command->line, to->name, hn->key);
    }

    /* set params (apply configuration) */
    for(ocline = to->cparams; ocline->name; ocline++)
    {
      SNODE *val;

      /* get configured value (or set default value if not specified) */
      val = tea_thread_param_value_get(tw->options, ocline->name);

      /* check if parameter is optional */
      if(!val && ocline->needed)
        FAT("%d:%s: Parameter %s is mandatory.", command->line, to->name, ocline->name);

      /* set value */
      if(tea_thread_param_value_set(tw, ocline, val))
        FAT("%d:%s: Cannot set parameter %s.", command->line, to->name, ocline->name);
    }
  } else {
    if(command->command.thc.to->options
    || command->command.thc.to->options->nentries > 0)
      FAT("%d:%s: Parameters not allowed for this type of thread.", command->line, to->name);
  }

  /* once configuration applied, launch thread configuration routine */
  if(tw->to->configure
  && tw->to->configure(tw, command, 1))
      FAT("%d:%s: Thread configuration failed.", command->line, to->name);

  /* add thread to the list */
  pthreadex_lock_get_exclusive_n(&ttable_lock, "install-thread");
  DBG("[tea] Installing thread %d.", tid);

  /* build threads */
  if(ttable[tid])
    FATAL_ERROR("Thread slot %d is used already.", tid);
  ttable[tid] = tw;

  /* launch thread */
  if(pthread_create(&(tw->pthread_id), NULL, tea_thread, tw) != 0)
  {
    ERR_ERRNO("Error creating thread %d", tid);
    FATAL_ERROR("Fatal error happened during thread creation.");
  }

termination:
  if(fatal && tw)
  {
    if(ttable[tid] == tw)
      ttable[tid] = NULL;
    if(tw->mqueue)
      mqueue_destroy(tw->mqueue);
    pthreadex_flag_destroy(&(tw->mwaiting));
    pthreadex_flag_destroy(&(tw->cleanup_do));
    pthreadex_flag_destroy(&(tw->cleanup_done));
    free(tw);
  }

  pthreadex_lock_release();
  
  if(!fatal)
    return;

  FAT("Aborting.");
}
Ejemplo n.º 6
0
static void mqueue_destructor(void *ptr)
{
	mqueue_destroy((MQueue)ptr);
}