barrior_t barrior_create(int waitcount) { barrior_t b = malloc(sizeof(barrior)); b->wait_count = waitcount; b->mtx = mutex_create(); b->cond = condition_create(); return b; }
struct rtp_recorder_t* rtp_recorder_create(crypt_aes_p crypt, bool disable_audio, audio_queue_p audio_queue, struct sockaddr* local_end_point, struct sockaddr* remote_end_point, uint16_t remote_control_port, uint16_t remote_timing_port) { struct rtp_recorder_t* rr = (struct rtp_recorder_t*)malloc(sizeof(struct rtp_recorder_t)); bzero(rr, sizeof(struct rtp_recorder_t)); rr->crypt = crypt; rr->disable_audio = disable_audio; rr->audio_queue = audio_queue; rr->timer_mutex = mutex_create(); rr->timer_cond = condition_create(); rr->remote_control_end_point = sockaddr_copy(remote_end_point); rr->remote_timing_end_point = sockaddr_copy(remote_end_point); sockaddr_set_port(rr->remote_control_end_point, remote_control_port); sockaddr_set_port(rr->remote_timing_end_point, remote_timing_port); rr->streaming_socket = _rtp_recorder_create_socket(rr, "Straming socket", local_end_point, remote_end_point); rr->control_socket = _rtp_recorder_create_socket(rr, "Control socket", local_end_point, remote_end_point); rr->timing_socket = _rtp_recorder_create_socket(rr, "Timing socket", local_end_point, remote_end_point); return rr; }
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); }
static struct per_thread_struct *per_thread_create() { struct per_thread_struct *pts = calloc(1,sizeof(*pts)); pts->local_push_q = LINK_LIST_CREATE(); pts->local_pop_q = LINK_LIST_CREATE(); pts->cond = condition_create(); return pts; }
thread_t create_thread(int joinable) { thread_t t = malloc(sizeof(thread)); t->joinable = joinable; t->is_suspend = 0; t->mtx = mutex_create(); t->cond = condition_create(); return t; }
//获取本线程,与que相关的per_thread_que static inline ptq_t get_per_thread_que(struct msg_que *que,uint8_t mode) { ptq_t ptq = (ptq_t)pthread_getspecific(que->t_key); if(!ptq){ ptq = calloc(1,sizeof(*ptq)); ptq->destroy_function = que->destroy_function; ptq->mode = mode; ptq->que = que; ref_increase(&que->refbase); ptq->cond = condition_create(); pthread_setspecific(que->t_key,(void*)ptq); }else if(ptq->mode == MSGQ_NONE) ptq->mode = mode; return ptq; }
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); }