Пример #1
0
rwlock_t* rwlock_New(void)
{
  rwlock_t* rwlock = (rwlock_t*)malloc(sizeof(rwlock_t));
  rwlock->readers = 0;
  MUTEX_NEW(rwlock->lock);
  MUTEX_INIT(rwlock->lock);
  COND_NEW(rwlock->reader_cond);
  COND_INIT(rwlock->reader_cond);
  COND_NEW(rwlock->writer_cond);
  COND_INIT(rwlock->writer_cond);
  return rwlock;
}
Пример #2
0
fast_mtq fast_mtq_init(int threads, fast_mtq_cb cb, void *arg)
{
	fast_mtq f_mtq;
	int i;

	log_debug("Fast mtq init, threads:%d", threads);

	f_mtq =
	    (fast_mtq) malloc(sizeof(_fast_mtq) +
			      (threads * sizeof(THREAD_VAR)));
	memset(f_mtq, 0, sizeof(_fast_mtq));
	f_mtq->threads = threads;
	f_mtq->cb = cb;
	f_mtq->arg = arg;
	f_mtq->shutdown = 0;
	f_mtq->first = NULL;
	f_mtq->last = NULL;
	f_mtq->queue = 0;

	SEM_INIT(f_mtq->sem);
	COND_INIT(f_mtq->cond);

	for (i = 0; i < f_mtq->threads; i++) {
		THREAD_CREATE(f_mtq->threads_table[i], fast_mtq_thread,
			      f_mtq);
	}

	return f_mtq;
}
Пример #3
0
void
Parrot_alarm_init(void)
{
    ASSERT_ARGS(Parrot_alarm_init)
    Parrot_thread thread;
    MUTEX_INIT(alarm_lock);
    COND_INIT(sleep_cond);
    THREAD_CREATE_JOINABLE(thread, Parrot_alarm_runloop, NULL);
}
Пример #4
0
int
mvar_init (MVar *const mvar, void *const value)
{
	int e = 0;
	assert (mvar);

	e = pthread_mutex_init (&mvar->lock, NULL);
	MUTEX_INIT (e, e_lock);

	e = pthread_cond_init (&mvar->put, NULL);
	COND_INIT (e, e_put);

	e = pthread_cond_init (&mvar->read, NULL);
	COND_INIT (e, e_read);

	e = pthread_cond_init (&mvar->take, NULL);
	COND_INIT (e, e_take);

	mvar->value = NULL;

	if (value)
		e = mvar_put (mvar, value);

	goto end;

	e = pthread_cond_destroy (&mvar->take);
	UNRECOVERABLE (e);
e_take:

	e = pthread_cond_destroy (&mvar->read);
	UNRECOVERABLE (e);
e_read:

	e = pthread_cond_destroy (&mvar->put);
	UNRECOVERABLE (e);
e_put:

	e = pthread_mutex_destroy (&mvar->lock);
	UNRECOVERABLE (e);
e_lock:

end:
	return e;
}
Пример #5
0
/**
 * @brief Chain Constructor
 */
Chain::Chain()
{	
	MUTEX_INIT(_recycledIdsMutex)
	MUTEX_INIT(_statusMutex)
	MUTEX_INIT(_pendingMutex)

	MUTEX_INIT(_chainMutex)
	MUTEX_INIT(_tailsMutex)
	MUTEX_INIT(_attachedMutex)
	
	MUTEX_INIT(_toLongestMutex)

	COND_INIT(_pendingCV)
	COND_INIT(_attachedCV)


	_maxHeight = EMPTY;
	_expected_size = EMPTY;

	_isClosing = false;
	s_initiated = true;
}
Пример #6
0
Yodar_4028B::Yodar_4028B()
{
	memset((char *) m_data, 0, MAX_DATA_COUNT * sizeof(com_data));

	m_handleThread = NULL;
	INITIALIZE_MUTEX(&m_handleMutex);
	COND_INIT(&m_handleCond);
	
	m_bRun = false;
	m_nReadIndex = 0;
	m_nWriteIndex = 0;
	
	StartHandleThread();
}
Пример #7
0
grn_rc
grn_com_event_init(grn_ctx *ctx, grn_com_event *ev, int max_nevents, int data_size)
{
    ev->max_nevents = max_nevents;
    if ((ev->hash = grn_hash_create(ctx, NULL, sizeof(grn_sock), data_size, 0))) {
        MUTEX_INIT(ev->mutex);
        COND_INIT(ev->cond);
        GRN_COM_QUEUE_INIT(&ev->recv_old);
        ev->msg_handler = NULL;
        memset(&(ev->curr_edge_id), 0, sizeof(grn_com_addr));
        ev->acceptor = NULL;
        ev->opaque = NULL;
#ifndef USE_SELECT
# ifdef USE_EPOLL
        if ((ev->events = GRN_MALLOC(sizeof(struct epoll_event) * max_nevents))) {
            if ((ev->epfd = epoll_create(max_nevents)) != -1) {
                goto exit;
            } else {
                SERR("epoll_create");
            }
            GRN_FREE(ev->events);
        }
# else /* USE_EPOLL */
#  ifdef USE_KQUEUE
        if ((ev->events = GRN_MALLOC(sizeof(struct kevent) * max_nevents))) {
            if ((ev->kqfd = kqueue()) != -1) {
                goto exit;
            } else {
                SERR("kqueue");
            }
            GRN_FREE(ev->events);
        }
#  else /* USE_KQUEUE */
        if ((ev->events = GRN_MALLOC(sizeof(struct pollfd) * max_nevents))) {
            goto exit;
        }
#  endif /* USE_KQUEUE*/
# endif /* USE_EPOLL */
        grn_hash_close(ctx, ev->hash);
        ev->hash = NULL;
        ev->events = NULL;
#else /* USE_SELECT */
        goto exit;
#endif /* USE_SELECT */
    }
exit :
    return ctx->rc;
}
Пример #8
0
void mtq_init() {
    mtq mtq = NULL; /* queue */
    mth t = NULL;
    int n,k; 
    pool newp;


	mtq__master = malloc(sizeof(_mtqmaster)); /* happens once, global */
	mtq__master->random = 0;

	/* start MTQ threads */
	for(n=0;n<MTQ_THREADS;n++)  {
	  newp = pool_new();
	  t = pmalloco(newp, sizeof(_mth));
	  t->p = newp;
	  t->mtq = pmalloco(newp,sizeof(_mtq));
	  t->mtq->first = t->mtq->last = NULL;
	  t->mtq->free_first = t->mtq->free_last = NULL;	    
	  t->mtq->users_count = 0;
	  t->mtq->dl = 0;	    
	  t->mtq->length = 0;

	  mtq = t->mtq;
	
	  /* build queue cache */
	  for (k=0;k<MTQ_QUEUE_LONG;k++)  {
		/* mtq->free_last if the first to take from queue*/	
		mtq->queue[k].memory = 0;
		mtq->queue[k].prev   = NULL;
		
		/* if queue is empty */
		if (mtq->free_last == NULL)
		  mtq->free_last = &(mtq->queue[k]);
		else
		  mtq->free_first->prev = &(mtq->queue[k]);
		
		mtq->free_first = &(mtq->queue[k]);
		mtq->length++;
	  }
	  
	  SEM_INIT(t->mtq->sem);
	  COND_INIT(t->mtq->cond);
		
	  pthread_create(&(t->thread), NULL, mtq_main, (void *)t);
	  mtq__master->all[n] = t; /* assign it as available */
	}
}
Пример #9
0
modperl_tipool_t *modperl_tipool_new(apr_pool_t *p,
                                     modperl_tipool_config_t *cfg,
                                     modperl_tipool_vtbl_t *func,
                                     void *data)
{
    modperl_tipool_t *tipool =
        (modperl_tipool_t *)apr_pcalloc(p, sizeof(*tipool));

    tipool->cfg = cfg;
    tipool->func = func;
    tipool->data = data;

    MUTEX_INIT(&tipool->tiplock);
    COND_INIT(&tipool->available);

    return tipool;
}
Пример #10
0
void queue_init(message_queue* queue) {
	Zero(queue, 1, message_queue);
	MUTEX_INIT(&queue->mutex);
	COND_INIT(&queue->condvar);
	queue->refcount = 1;
}