예제 #1
0
void connection_shutdown(void)
{
    if (!_initialized) return;
    
    thread_cond_destroy(&global.shutdown_cond);
    thread_rwlock_destroy(&_source_shutdown_rwlock);
    thread_mutex_destroy(&_queue_mutex);
    thread_mutex_destroy(&_connection_mutex);
    thread_mutex_destroy(&move_clients_mutex);

    _initialized = 0;
}
예제 #2
0
int cpeer_kill(struct cpeer *p)
{
        if(!p)
	    return 0;
	if(__sync_bool_compare_and_swap(&p->status,CPEER_CONNECTED,CPEER_DISCONNECTED))
	{
		printf("ref:%d,close peer id:%lu,peer:%p,nc:%p\n",p->refcount,p->id,p,p->nc);
		close(p->sd);
		fdev_del(&p->ioev);

		//push one msg to notify disconnect
		struct msg_t *msg = (struct msg_t *)mmalloc(p->nc->allocator,
			sizeof(struct msg_t));
		msg->buf = NULL;
		msg->len = 0;
		msg->peer_id = p->id;
		msg->type = MSG_DISCONNECT;

		queue_push(p->nc->recv_queue,msg);
	}

	if(__sync_bool_compare_and_swap(&p->refcount,0,1))
	{
		printf("free peer id:%lu\n",p->id);
		iobuf_free(p->allocator,&p->recvbuf);
		iobuf_free(p->allocator,&p->sendbuf);
		//free send queue
		struct msg_t *msg = NULL,*next = NULL;
		thread_mutex_lock(p->sq_mutex);
		msg = BTPDQ_FIRST(&p->send_queue);
		while(msg){
			next = BTPDQ_NEXT(msg,msg_entry);
			BTPDQ_REMOVE(&p->send_queue,msg,msg_entry);

			mfree(p->allocator,msg->buf);
			mfree(p->allocator,msg);
			msg = next;
		}
		thread_mutex_unlock(p->sq_mutex);

		thread_mutex_destroy(p->mpool_mutex);
		thread_mutex_destroy(p->sq_mutex);

		allocator_destroy(p->allocator);

		thread_mutex_lock(p->nc->peer_mutex);
		mfree(p->nc->allocator,p);
		p->nc->peer = NULL;
		thread_mutex_unlock(p->nc->peer_mutex);
	}
	return 0;
}
예제 #3
0
파일: connection.c 프로젝트: xaiki/IceCast
void connection_shutdown(void)
{
    if (!_initialized) return;

    _connection_running = 0;
    thread_cond_signal(_connection_cond);
    DEBUG0 ("waiting for connection thread");
    thread_join(_connection_thread_id);

#ifdef HAVE_OPENSSL
    SSL_CTX_free (ssl_ctx);
#endif
    if (banned_ip.contents)  avl_tree_free (banned_ip.contents, free_filtered_ip);
    if (allowed_ip.contents) avl_tree_free (allowed_ip.contents, free_filtered_ip);

    thread_cond_destroy (_connection_cond);
    free (_connection_cond);

    thread_cond_destroy(&global.shutdown_cond);
    thread_rwlock_destroy(&_source_shutdown_rwlock);
    thread_spin_destroy (&_connection_lock);
    thread_mutex_destroy(&move_clients_mutex);

    _initialized = 0;
}
예제 #4
0
파일: fserve.c 프로젝트: onitake/icecast-kh
void fserve_shutdown(void)
{
    fserve_running = 0;
    if (mimetypes)
        avl_tree_free (mimetypes, _delete_mapping);
    if (fh_cache)
    {
        int count = 20;
        avl_delete (fh_cache, &no_file, NULL);
        while (fh_cache->length > 1 && count)
        {
            fh_node *fh = fh_cache->root->right->key;
            if (fh && fh->refcount == 0)
            {
                remove_fh_from_cache (fh);
                continue;
            }
            DEBUG1 ("waiting for %u entries to clear", fh_cache->length);
            thread_sleep (100000);
            count--;
        }
        avl_tree_free (fh_cache, _delete_fh);
    }

    thread_spin_destroy (&pending_lock);
#ifndef HAVE_PREAD
    thread_mutex_destroy (&seekread_lock);
#endif
    INFO0("file serving stopped");
}
예제 #5
0
파일: open_loop.c 프로젝트: kralf/era-libs
int main(int argc, char **argv) {
  int result;
  thread_mutex_t mutex;
  era_arm_t arm;
  era_trajectory_t trajectory;

  if (era_init_arg(&arm, argc, argv, 0, "FILE FREQUENCY"))
    return -1;
  const char* file = argv[1];
  float freq = atof(argv[2]);

  thread_mutex_init(&mutex);
  if ((result = era_trajectory_read(file, &trajectory)) < 0) {
    fprintf(stderr, "%s\n", era_trajectory_errors[-result]);
    return -1;
  }

  signal(SIGINT, era_signaled);

  if (era_open(&arm))
    return -1;
  if (!(result = era_control_open_loop_start(&control_thread, &arm, 
    &mutex, &trajectory, freq)))
    thread_wait_exit(&control_thread);
  else
    fprintf(stderr, "%s\n", era_control_open_loop_errors[result]);
  era_close(&arm);

  era_destroy(&arm);
  thread_mutex_destroy(&mutex);
  return 0;
}
예제 #6
0
/* release the auth. It is referred to by multiple structures so this is
 * refcounted and only actual freed after the last use
 */
void auth_release (auth_t *authenticator)
{
    if (authenticator == NULL)
        return;

    thread_mutex_lock (&authenticator->lock);
    authenticator->refcount--;
    ICECAST_LOG_DEBUG("...refcount on auth_t %s is now %d", authenticator->mount, authenticator->refcount);
    if (authenticator->refcount)
    {
        thread_mutex_unlock (&authenticator->lock);
        return;
    }

    /* cleanup auth thread attached to this auth */
    authenticator->running = 0;
    thread_join (authenticator->thread);

    if (authenticator->free)
        authenticator->free (authenticator);
    xmlFree (authenticator->type);
    thread_mutex_unlock (&authenticator->lock);
    thread_mutex_destroy (&authenticator->lock);
    if (authenticator->mount)
        free (authenticator->mount);
    free (authenticator);
}
예제 #7
0
int main(void)
{
	thread_mutex_t *thread_mutex = NULL;
	conn_svr_cfg cfg;
#ifdef WIN32
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2,2),&wsaData);
#endif
	
#ifdef WIN32
	strcpy_s(cfg.host,sizeof(cfg.host),"127.0.0.1");
#else
	strcpy(cfg.host,"127.0.0.1");
#endif
	cfg.port = 1029;
	thread_mutex_create(&thread_mutex,THREAD_MUTEX_DEFAULT);
	cfg.mutex = thread_mutex;
	cfg.nmin = 5;
	cfg.nkeep = 10;
	cfg.nmax = 15;
	cfg.exptime = 10;
	cfg.timeout = 1000;

	conn_pool_init(&cfg);
#ifdef WIN32
//	Sleep(100);
#else
	sleep(10);
#endif
	conn_pool_fini(&cfg);
	thread_mutex_destroy(thread_mutex);
	return 0;
}
예제 #8
0
파일: auth.c 프로젝트: balbinus/icecast-kh
/* release the auth. It is referred to by multiple structures so this is
 * refcounted and only actual freed after the last use
 */
void auth_release (auth_t *authenticator)
{
    authenticator->refcount--;
    DEBUG2 ("...refcount on auth_t %s is now %d", authenticator->mount, authenticator->refcount);
    if (authenticator->refcount)
    {
        thread_mutex_unlock (&authenticator->lock);
        return;
    }

    /* cleanup auth threads attached to this auth */
    authenticator->flags &= ~AUTH_RUNNING;
    while (authenticator->handlers)
    {
        if (authenticator->release_thread_data)
            authenticator->release_thread_data (authenticator,
                    authenticator->handles [authenticator->handlers-1].data);
        authenticator->handlers--;
    }
    free (authenticator->handles);

    if (authenticator->release)
        authenticator->release (authenticator);
    xmlFree (authenticator->type);
    xmlFree (authenticator->realm);
    xmlFree (authenticator->rejected_mount);
    thread_mutex_unlock (&authenticator->lock);
    thread_mutex_destroy (&authenticator->lock);
    free (authenticator->mount);
    free (authenticator);
}
예제 #9
0
파일: fserve.c 프로젝트: onitake/icecast-kh
static int _delete_fh (void *mapping)
{
    fh_node *fh = mapping;
    if (fh == &no_file)
    {
        ERROR0 ("no file handle free detected");
        return 0;
    }
    if (fh->refcount)
        WARN2 ("handle for %s has refcount %d", fh->finfo.mount, fh->refcount);
    else
        thread_mutex_destroy (&fh->lock);

    file_close (&fh->f);
    if (fh->format)
    {
        free (fh->format->mount);
        format_plugin_clear (fh->format, NULL);
        free (fh->format);
    }
    if (fh->clients)
        avl_tree_free (fh->clients, NULL);
    rate_free (fh->out_bitrate);
    free (fh->finfo.mount);
    free (fh->finfo.fallback);
    free (fh);

    return 1;
}
예제 #10
0
파일: avl.c 프로젝트: ampimis/RtkGps
void avl_destroy(avl_tree *tree, avl_node_func free_func)
{
	assert(tree != NULL);
  
  internal_lock_mutex(&tree->mutex);
#if PSPP
  if (free_func || tree->owner == NULL)
#endif
    {
      avl_node *an[AVL_MAX_HEIGHT];	
      unsigned long ab = 0;
      int ap = 0;
      avl_node *p = tree->root.link[0];

      for (;;)
	{
	  /* T2. */
	  while (p != NULL)
	    {
	      /* T3. */
	      ab &= ~(1ul << ap);
	      an[ap++] = p;
	      p = p->link[0];
	    }

	  /* T4. */
	  for (;;)
	    {
	      if (ap == 0)
		goto done;

	      p = an[--ap];
	      if ((ab & (1ul << ap)) == 0)
		{
		  ab |= (1ul << ap++);
		  p = p->link[1];
		  break;
		}
      
	      if (free_func)
		free_func (p->data, tree->param);
#if PSPP
	      if (tree->owner == NULL)
#endif
		free (p);
	    }
	}
    }

 done:
	internal_unlock_mutex(&tree->mutex);
	thread_mutex_destroy(&tree->mutex);
#if PSPP
  if (tree->owner == NULL)
#endif
    free (tree);
}
예제 #11
0
파일: stats.c 프로젝트: miksago/icecast
void stats_shutdown()
{
    int n;
    stats_event_t *event, *next;

    if(!_stats_running) /* We can't shutdown if we're not running. */
        return;

    /* wait for thread to exit */
    _stats_running = 0;
    thread_join(_stats_thread_id);

    /* wait for other threads to shut down */
    do {
        thread_sleep(300000);
        thread_mutex_lock(&_stats_mutex);
        n = _stats_threads;
        thread_mutex_unlock(&_stats_mutex);
    } while (n > 0);

    /* free the queues */

    /* destroy the queue mutexes */
    thread_mutex_destroy(&_global_event_mutex);

    /* tear it all down */
    thread_cond_destroy(&_event_signal_cond);
    thread_mutex_destroy(&_stats_mutex);
    avl_tree_free(_stats.source_tree, _free_source_stats);
    avl_tree_free(_stats.global_tree, _free_stats);

    event = _global_event_queue;
    while(event) {
        if(event->source)
            free(event->source);
        if(event->value)
            free(event->value);
        if(event->name)
            free(event->name);
        next = event->next;
        free(event);
        event = next;
    }
}
예제 #12
0
void global_shutdown(void)
{
    thread_mutex_destroy(&_global_mutex);
    avl_tree_free(global.source_tree, NULL);
    rate_free (global.out_bitrate);
    global.out_bitrate = NULL;
#ifdef MY_ALLOC
    avl_tree_free(global.alloc_tree, free_alloc_node);
#endif
}
예제 #13
0
파일: connection.c 프로젝트: krattai/AEBL
void connection_shutdown(void)
{
    if (!_initialized) return;
    
#ifdef HAVE_OPENSSL
    SSL_CTX_free (ssl_ctx);
#endif
    if (banned_ip.contents)  avl_tree_free (banned_ip.contents, free_filtered_ip);
    if (allowed_ip.contents) avl_tree_free (allowed_ip.contents, free_filtered_ip);
 
    thread_cond_destroy(&global.shutdown_cond);
    thread_rwlock_destroy(&_source_shutdown_rwlock);
    thread_mutex_destroy(&_con_queue_mutex);
    thread_mutex_destroy(&_req_queue_mutex);
    thread_mutex_destroy(&_connection_mutex);
    thread_mutex_destroy(&move_clients_mutex);

    _initialized = 0;
}
예제 #14
0
int nc_disconnect(net_client_t *nc)
{
    if(!nc)
	return -1;
    fdev_del(&nc->ev);
    close(nc->sd);
    nc->endgame = 1;
    pthread_join(nc->td_start,NULL);

    cpeer_kill(nc->peer);
    queue_destroy(nc->recv_queue);
    thread_mutex_destroy(nc->peer_mutex);
    //thread_mutex_destroy(nc->recv_mutex);
    thread_mutex_destroy(nc->mpool_mutex);
    allocator_destroy(nc->allocator);
    free(nc);

    return 0;
}
예제 #15
0
파일: thread.c 프로젝트: rektide/dyne-muse
void thread_shutdown(void)
{
    if (_initialized == 1) {
        thread_mutex_destroy(&_library_mutex);
        thread_mutex_destroy(&_threadtree_mutex);
#ifdef THREAD_DEBUG
        thread_mutex_destroy(&_mutextree_mutex);
        
        avl_tree_free(_mutextree, _free_mutex);
#endif
        avl_tree_free(_threadtree, _free_thread);
    }

#ifdef THREAD_DEBUG
    log_close(_logid);
    log_shutdown();
#endif

}
예제 #16
0
void stats_shutdown(void)
{
    int n;

    if (!_stats_running) /* We can't shutdown if we're not running. */
        return;

    /* wait for thread to exit */
    _stats_running = 0;
    thread_join(_stats_thread_id);

    /* wait for other threads to shut down */
    do {
        thread_sleep(300000);
        thread_mutex_lock(&_stats_mutex);
        n = _stats_threads;
        thread_mutex_unlock(&_stats_mutex);
    } while (n > 0);
    ICECAST_LOG_INFO("stats thread finished");

    /* free the queues */

    /* destroy the queue mutexes */
    thread_mutex_destroy(&_global_event_mutex);

    thread_mutex_destroy(&_stats_mutex);
    avl_tree_free(_stats.source_tree, _free_source_stats);
    avl_tree_free(_stats.global_tree, _free_stats);

    while (1)
    {
        stats_event_t *event = _get_event_from_queue (&_global_event_queue);
        if (event == NULL) break;
        if(event->source)
            free(event->source);
        if(event->value)
            free(event->value);
        if(event->name)
            free(event->name);
        free(event);
    }
}
예제 #17
0
void stats_shutdown(void)
{
    if(!_stats_running) /* We can't shutdown if we're not running. */
        return;

    _stats_running = 0;

    avl_tree_free(_stats.source_tree, _free_source_stats);
    avl_tree_free(_stats.global_tree, _free_stats);
    thread_mutex_destroy (&_stats.listeners_lock);
}
예제 #18
0
void resolver_shutdown(void)
{
    if (_initialized)
    {
        thread_mutex_destroy(&_resolver_mutex);
        _initialized = 0;
#ifdef HAVE_ENDHOSTENT
        endhostent();
#endif
    }
}
예제 #19
0
static void *yp_update_thread(void *arg)
{
    if (!kitsune_is_updating()) { /**DSU control */
        INFO0("YP update thread started");
        yp_running = 1;
    }

    while (yp_running)
    {
      kitsune_update("yp_update"); /**DSU updatepoint */
        struct yp_server *server;

        thread_sleep (200000);

        /* do the YP communication */
        thread_rwlock_rlock (&yp_lock);
        server = (struct yp_server *)active_yps;
        while (server)
        {
            /* DEBUG1 ("trying %s", server->url); */
            yp_process_server (server);
            server = server->next;
        }
        thread_rwlock_unlock (&yp_lock);

        /* update the local YP structure */
        if (yp_update)
        {
            thread_rwlock_wlock (&yp_lock);
            check_servers ();
            server = (struct yp_server *)active_yps;
            while (server)
            {
                /* DEBUG1 ("Checking yps %s", server->url); */
                add_pending_yp (server);
                delete_marked_yp (server);
                server = server->next;
            }
            yp_update = 0;
            thread_rwlock_unlock (&yp_lock);
        }
    }
    thread_rwlock_destroy (&yp_lock);
    thread_mutex_destroy (&yp_pending_lock);
    /* free server and ypdata left */
    while (active_yps)
    {
        struct yp_server *server = (struct yp_server *)active_yps;
        active_yps = server->next;
        destroy_yp_server (server);
    }

    return NULL;
}
예제 #20
0
static void free_global_ctx(void)
{
	if (__mem_slice_list) {
		private_array_destroy(__mem_slice_list, NULL);
		__mem_slice_list = NULL;
	}
	if (__mem_slice_list_lock) {
		thread_mutex_destroy(__mem_slice_list_lock);
		__mem_slice_list_lock = NULL;
	}
}
예제 #21
0
static void format_mp3_free_plugin(format_plugin_t *self)
{
    /* free the plugin instance */
    mp3_state *state = self->_state;

    thread_mutex_destroy (&state->url_lock);
    free (state->url_artist);
    free (state->url_title);
    refbuf_release (state->metadata);
    free(state);
    free(self);
}
예제 #22
0
파일: queue.c 프로젝트: breezechen/zevent
/**
 * queue_t destroy
 */
int queue_destroy(queue_t *queue) 
{
    /* Ignore errors here, we can't do anything about them anyway. */

    thread_cond_destroy(queue->not_empty);
    thread_cond_destroy(queue->not_full);
    thread_mutex_destroy(queue->one_big_mutex);

    free(queue->data);
    free(queue);
    return 0;
}
예제 #23
0
파일: cfgparse.c 프로젝트: miksago/icecast
void config_free_instance(instance_t *instance)
{
    if (instance->hostname) xmlFree(instance->hostname);
    if (instance->password) xmlFree(instance->password);
    if (instance->user) xmlFree(instance->user);
    if (instance->mount) xmlFree(instance->mount);
    if (instance->queue) 
    {
        thread_mutex_destroy(&instance->queue->lock);
        free(instance->queue);
    }
}
예제 #24
0
static void close_module(input_module_t *mod)
{
    if(mod)
    {
        if(mod->internal)
        {
            stdinpcm_state *s = mod->internal;
            thread_mutex_destroy(&s->metadatalock);
            free(s);
        }
        free(mod);
    }
}
예제 #25
0
void xslt_shutdown() {
    int i;

    for(i=0; i < CACHESIZE; i++) {
        if(cache[i].filename)
            free(cache[i].filename);
        if(cache[i].stylesheet)
            xsltFreeStylesheet(cache[i].stylesheet);
    }

    thread_mutex_destroy (&xsltlock);
    xsltCleanupGlobals();
}
예제 #26
0
파일: im_alsa.c 프로젝트: miksago/icecast
static void close_module(input_module_t *mod)
{
    if(mod)
    {
        if(mod->internal)
        {
            im_alsa_state *s = mod->internal;
            if(s->fd != NULL)
                snd_pcm_close(s->fd);
            thread_mutex_destroy(&s->metadatalock);
            free(s);
        }
        free(mod);
    }
}
예제 #27
0
static void close_module(input_module_t *mod)
{
    if(mod)
    {
        if(mod->internal)
        {
            im_sndio_state *s = mod->internal;
            if(s->hdl != NULL)
                sio_close(s->hdl);
            thread_mutex_destroy(&s->metadatalock);
            free(s);
        }
        free(mod);
    }
}
예제 #28
0
파일: xslt.c 프로젝트: cmelendez/icecast-kh
void xslt_shutdown(void) {
    int i;

    for(i=0; i < CACHESIZE; i++) {
        if(cache[i].filename)
            free(cache[i].filename);
        if(cache[i].stylesheet)
            xsltFreeStylesheet(cache[i].stylesheet);
    }

    thread_mutex_destroy (&xsltlock);
    thread_rwlock_destroy (&xslt_lock);
    thread_spin_destroy (&update_lock);
    xmlCleanupParser();
    xsltCleanupGlobals();
}
예제 #29
0
void *stats_connection(void *arg)
{
    client_t *client = (client_t *)arg;
    stats_event_t *event;
    event_listener_t listener;

    ICECAST_LOG_INFO("stats client starting");

    event_queue_init (&listener.queue);
    /* increment the thread count */
    thread_mutex_lock(&_stats_mutex);
    _stats_threads++;
    stats_event_args (NULL, "stats", "%d", _stats_threads);
    thread_mutex_unlock(&_stats_mutex);

    thread_mutex_create (&(listener.mutex));

    _register_listener (&listener);

    while (_stats_running) {
        thread_mutex_lock (&listener.mutex);
        event = _get_event_from_queue (&listener.queue);
        thread_mutex_unlock (&listener.mutex);
        if (event != NULL) {
            if (_send_event_to_client(event, client) < 0) {
                _free_event(event);
                break;
            }
            _free_event(event);
            continue;
        }
        thread_sleep (500000);
    }

    thread_mutex_lock(&_stats_mutex);
    _unregister_listener (&listener);
    _stats_threads--;
    stats_event_args (NULL, "stats", "%d", _stats_threads);
    thread_mutex_unlock(&_stats_mutex);

    thread_mutex_destroy (&listener.mutex);
    client_destroy (client);
    ICECAST_LOG_INFO("stats client finished");

    return NULL;
}
예제 #30
0
파일: stats.c 프로젝트: miksago/icecast
void *stats_connection(void *arg)
{
    stats_connection_t *statcon = (stats_connection_t *)arg;
    stats_event_t *local_event_queue = NULL;
    mutex_t local_event_mutex;
    stats_event_t *event;

    /* increment the thread count */
    thread_mutex_lock(&_stats_mutex);
    _stats_threads++;
    thread_mutex_unlock(&_stats_mutex);

    thread_mutex_create(&local_event_mutex);

    _atomic_get_and_register(&local_event_queue, &local_event_mutex);

    while (_stats_running) {
        thread_mutex_lock(&local_event_mutex);
        event = _get_event_from_queue(&local_event_queue);
        if (event != NULL) {
            if (!_send_event_to_client(event, statcon->con)) {
                _free_event(event);
                thread_mutex_unlock(&local_event_mutex);
                break;
            }
            _free_event(event);
        } else {
            thread_mutex_unlock(&local_event_mutex);
            thread_cond_wait(&_event_signal_cond);
            continue;
        }
                   
        thread_mutex_unlock(&local_event_mutex);
    }

    thread_mutex_destroy(&local_event_mutex);

    thread_mutex_lock(&_stats_mutex);
    _stats_threads--;
    thread_mutex_unlock(&_stats_mutex);

    thread_exit(0);
    
    return NULL;
}