Ejemplo n.º 1
0
Archivo: zctx.c Proyecto: calid/czmq
zctx_t *
zctx_shadow (zctx_t *ctx)
{
    zctx_t
        *self;

    //  Shares same 0MQ context but has its own list of sockets so that
    //  we create, use, and destroy sockets only within a single thread.
    self = (zctx_t *) zmalloc (sizeof (zctx_t));
    if (!self)
        return NULL;

    self->sockets = zlist_new ();
    self->mutex = zmutex_new ();
    if (!self->sockets || !self->mutex) {
        zlist_destroy (&self->sockets);
        zmutex_destroy (&self->mutex);
        free (self);
        return NULL;
    }
    self->context = ctx->context;
    self->pipehwm = ctx->pipehwm;
    self->sndhwm = ctx->sndhwm;
    self->rcvhwm = ctx->rcvhwm;
    self->linger = ctx->linger;
    self->shadow = true;             //  This is a shadow context
    return self;
}
Ejemplo n.º 2
0
Archivo: zctx.c Proyecto: calid/czmq
zctx_t *
zctx_new (void)
{
    zctx_t
        *self;

    self = (zctx_t *) zmalloc (sizeof (zctx_t));
    if (!self)
        return NULL;

    self->sockets = zlist_new ();
    self->mutex = zmutex_new ();
    if (!self->sockets || !self->mutex) {
        zlist_destroy (&self->sockets);
        zmutex_destroy (&self->mutex);
        free (self);
        return NULL;
    }
    self->iothreads = 1;
    self->pipehwm = 1000;   
    self->sndhwm = 1000;
    self->rcvhwm = 1000;
    zsys_handler_set (s_signal_handler);
    return self;
}
Ejemplo n.º 3
0
void VdtWindow::vdtExit(){
  // stop vdt and fini
  if(timerId){
    killTimer(timerId);
  }
  tmn_stop();
  tmn_fini();
  zmutex_destroy(msgMtx);
}
Ejemplo n.º 4
0
void vn_close(vnode_t *vp)
{
    rwst_destroy(&vp->v_vfsmhlock.ve_lock);
    zmutex_destroy(&vp->v_lock);
    if(vp->v_fd != -1)
        close(vp->v_fd);
    if(vp->v_path != NULL)
        free(vp->v_path);
    kmem_cache_free(vnode_cache, vp);
    /* fprintf(stderr, "VNode %p freed\n", vp); */
}
Ejemplo n.º 5
0
void
zmutex_test (bool verbose)
{
    printf (" * zmutex: ");

    //  @selftest
    zmutex_t *mutex = zmutex_new ();
    zmutex_lock (mutex);
    zmutex_unlock (mutex);
    zmutex_destroy (&mutex);
    //  @end
    printf ("OK\n");
}
Ejemplo n.º 6
0
int main(int argc, char* argv[]){  
	Fix_Initialize(); 

	g_apex_cfg = apex_cfg_new(argc,argv); 
	assert(g_apex_cfg);

	if(g_apex_cfg->log_path){
		zlog_use_file(g_apex_cfg->log_path); 
	} else {
		zlog_use_stdout();
	}  
	g_zmq_context = zctx_new(1);
	g_mutex_hash = zmutex_new(); 
	g_msgid2reply = hash_new(&g_hctrl_msgid2reply, NULL);


	char* broker = zstrdup(g_apex_cfg->broker);

	int thread_count = g_apex_cfg->worker_threads;
	zthread_t* reply_threads = (zthread_t*)zmalloc(thread_count*sizeof(zthread_t));
	zthread_t* recv_threads = (zthread_t*)zmalloc(thread_count*sizeof(zthread_t));

	for(int i=0; i<g_apex_cfg->worker_threads; i++){
		//reply_threads[i] = zthread_new(thread_reply, zstrdup(broker));
		recv_threads[i] = zthread_new(thread_recv, zstrdup(broker));
	}  
	zfree(broker); 

	for(int i=0; i<thread_count; i++){
		//zthread_join(reply_threads[i]);
		zthread_join(recv_threads[i]);
	} 

	zmutex_destroy(&g_mutex_hash);  
	hash_destroy(&g_msgid2reply);
	apex_cfg_destroy(&g_apex_cfg); 
	zctx_destroy(&g_zmq_context);	
	
	
	Fix_Uninitialize();  
	return 0;
}
Ejemplo n.º 7
0
Archivo: zctx.c Proyecto: calid/czmq
void
zctx_destroy (zctx_t **self_p)
{
    assert (self_p);
    if (*self_p) {
        zctx_t *self = *self_p;

        //  Destroy all sockets
        while (zlist_size (self->sockets))
            zctx__socket_destroy (self, zlist_first (self->sockets));
        zlist_destroy (&self->sockets);
        zmutex_destroy (&self->mutex);

        //  ZMQ context may not yet be instantiated
        if (self->context && !self->shadow)
            zmq_term (self->context);

        free (self);
        *self_p = NULL;
    }
}
Ejemplo n.º 8
0
Archivo: zmutex.c Proyecto: calid/czmq
int
zmutex_test (bool verbose)
{
    printf (" * zmutex: ");

    //  @selftest
    zmutex_t *mutex = zmutex_new ();
    // Try to lock while unlocked
    assert (zmutex_try_lock (mutex));
    zmutex_unlock (mutex);
    // Try to lock while locked
    zmutex_lock (mutex);
    assert (zmutex_try_lock (mutex) == 0);
    zmutex_unlock (mutex);
    // Try to lock while unlocked, again
    assert (zmutex_try_lock (mutex));
    zmutex_unlock (mutex);
    
    zmutex_destroy (&mutex);
    //  @end
    printf ("OK\n");
    return 0;
}