Пример #1
0
void destroy_thread(thread_t *t)
{
	mutex_destroy(&(*t)->mtx);
	condition_destroy(&(*t)->cond);
	free(*t);
	*t = 0;
}
Пример #2
0
/* 销毁线程池 */
void threadpool_destroy( threadpool_t* pool ) 
{
   if ( pool->quit ) 
   {
      return ;
   } 

   /************************** 进入临界区 ***********************/

   condition_lock( &pool->ready ) ;

   // 设置退出标志为真
   pool->quit = 1 ;

   // 如果线程池中正在运行着线程,那么我们需要等待线程执行完毕再销毁
   if ( pool->counter > 0 ) 
   {
      if ( pool->idle > 0 )
      {
         condition_broadcast( &pool->ready ) ;
      }
      while ( pool->counter > 0 ) 
      {
         condition_wait( &pool->ready ) ; // 主线程(main 函数所在线程)将等待在条件变量上
      }
   }

   condition_unlock( &pool->ready ) ;

   /************************** 退出临界区 ***********************/
   
   // 销毁条件变量
   condition_destroy( &pool->ready ) ;
}
Пример #3
0
void barrior_destroy(barrior_t *b)
{
	mutex_destroy(&(*b)->mtx);
	condition_destroy(&(*b)->cond);
	free(*b);
	*b = 0;
}
Пример #4
0
void rtp_recorder_destroy(struct rtp_recorder_t* rr) {
    
    mutex_lock(rr->timer_mutex);
    
    if (rr->synchronization_thread != NULL) {
        condition_signal(rr->timer_cond);
        mutex_unlock(rr->timer_mutex);
        thread_join(rr->synchronization_thread);
        mutex_lock(rr->timer_mutex);
        thread_destroy(rr->synchronization_thread);
        rr->synchronization_thread = NULL;
    }
    
    mutex_unlock(rr->timer_mutex);
    
    rtp_socket_destroy(rr->streaming_socket);
    rtp_socket_destroy(rr->control_socket);
    rtp_socket_destroy(rr->timing_socket);
    
    sockaddr_destroy(rr->remote_control_end_point);
    sockaddr_destroy(rr->remote_timing_end_point);
    
    mutex_destroy(rr->timer_mutex);
    condition_destroy(rr->timer_cond);
    
    free(rr);
    
}
Пример #5
0
void tWindow_create_thread(tWindow *p){
  DWORD dwThreadId;

  mutex_create(&p->mutex);
  if(vb) printf("window create beginning thread\n");

  p->thread = CreateThread(
    NULL,
    0,
    (LPTHREAD_START_ROUTINE)WindowThreadFunc,
    (LPVOID)p,
    0,
    &dwThreadId);
    
  if (p->thread==NULL){
    printf("couldn't create thread\n");
    return;
  }

  if(vb) printf("window create init cond waiting\n");
  condition_create(&p->thread_init_cond);
  condition_wait(&p->thread_init_cond,NULL);
  if(vb) printf("window create init cond return\n");
  condition_destroy(&p->thread_init_cond);
}
Пример #6
0
static void per_thread_destroy(struct per_thread_struct **pts)
{
	LINK_LIST_DESTROY(&(*pts)->local_push_q);
	LINK_LIST_DESTROY(&(*pts)->local_pop_q);
	condition_destroy(&(*pts)->cond);
	free(*pts);
	*pts = NULL;
}
Пример #7
0
void tWindow_create_thread(tWindow *p){
  pthread_attr_t* att=NULL;

  mutex_create(&p->mutex);
  mutex_create(&p->thread_init_mutex);
  condition_create(&p->thread_init_cond);
  mutex_lock(&p->thread_init_mutex);

  if(vb) printf("window create beginning thread\n");
  if (vb) printf("tWindow create thread %p %p \n", (void*)p, (void*)WindowThreadFunc);
  if ((pthread_create(&p->thread, att, WindowThreadFunc, (void*)p ))!=0){
 	fprintf(stderr,"pthread create error\n");
	exit(1);
  }
  if (vb) printf("tWindow create thread called\n");

  condition_wait(&p->thread_init_cond,&p->thread_init_mutex);
  mutex_destroy(&p->thread_init_mutex);
  if(vb) printf("window create init cond return\n");
  condition_destroy(&p->thread_init_cond);
}
Пример #8
0
void threadpool_destroy(threadpool_t* pool)
{
	if(pool->quit)
		return;

	condition_lock(&pool->ready);
	pool->quit = 1;

	if(pool->counter > 0)	
	{
		if(pool->idle > 0)
			condition_broadcast(&pool->ready);
		
		//waiting working thread exit
		while(pool->counter > 0)
			condition_wait(&pool->ready);
	}

	condition_unlock(&pool->ready);
	condition_destroy(&pool->ready);
}
Пример #9
0
void delete_per_thread_que(void *arg)
{
#ifdef MQ_HEART_BEAT
	block_sigusr1();
#endif
	ptq_t ptq = (ptq_t)arg;
	if(ptq->mode == MSGQ_WRITE){
        dlist_remove(&ptq->write_que.pnode);
	}
	//销毁local_que中所有消息
    lnode *n;
	if(ptq->destroy_function){
        while((n = LLIST_POP(lnode*,&ptq->local_que))!=NULL)
			ptq->destroy_function((void*)n);
	}
    condition_destroy(&ptq->cond);
	ref_decrease(&ptq->que->refbase);
	free(ptq);
#ifdef MQ_HEART_BEAT
	unblock_sigusr1();
#endif
	printf("delete_per_thread_que\n");
}
Пример #10
0
int waitgroup_destroy(waitgroup_t *wg) {
    condition_destroy(&wg->cond);
    mutex_destroy(&wg->mutex);
    return 0;
}