Beispiel #1
0
static int
test_mutex_destroyinit(void){
	pthread_mutex_t lock,*heaplock;
	int ret = -1;

	if((heaplock = Malloc("heaplock",sizeof(*heaplock))) == NULL){
		goto done;
	}
	if(Pthread_mutex_init(heaplock,NULL)){
		goto done;
	}
	if(Pthread_mutex_init(&lock,NULL)){
		goto done;
	}
	if(Pthread_mutex_init(&destroy_dyn_static_lock,NULL)){
		goto done;
	}
	printf(" Destroying dynamic-init static lock...\n");
	if(Pthread_mutex_destroy(&destroy_dyn_static_lock)){
		goto done;
	}
	printf(" Destroying dynamic-init stack lock...\n");
	if(Pthread_mutex_destroy(&lock)){
		goto done;
	}
	printf(" Destroying dynamic-init heap lock...\n");
	if(Pthread_mutex_destroy(heaplock)){
		goto done;
	}
	ret = 0;

done:
	Free(heaplock);
	return ret;
}
Beispiel #2
0
static int
test_mutex_destroystatic(void){
	int ret = -1;

	printf(" Destroying static-init lock...\n");
	pthread_mutex_lock(&destroy_static_lock);
	pthread_mutex_unlock(&destroy_static_lock);
	ret = Pthread_mutex_destroy(&destroy_static_lock);
	return ret;
}
Beispiel #3
0
int threadpool_destroy(threadpool_t *pool, int block, int timeout) {
    int ret;
    assert(pool);
    Pthread_mutex_lock(&pool->mutex);
    if (!pool->exit) {
        /* you should call `threadpool_exit' first */
        Pthread_mutex_unlock(&pool->mutex);
        return -1;
    }

    if (pool->threads_num != 0) {
        if (!block) {
            Pthread_mutex_unlock(&pool->mutex);
            return -1;
        } else {
            struct timespec ts;
            struct timeval  tv;
            gettimeofday(&tv, NULL);
            ts.tv_sec = tv.tv_sec + timeout;
            ts.tv_nsec = tv.tv_usec * 1000;

            while (pool->threads_num != 0) {
                if (timeout == 0) {
                    Pthread_cond_wait(&pool->exit_cond, &pool->mutex);
                    goto CONT;
                } else {
                    ret = Pthread_cond_timedwait(&pool->exit_cond, 
                        &pool->mutex, &ts);
                    if (ret == 0) {
                        goto CONT;
                    } else if (ret == ETIMEDOUT) {
                        Pthread_mutex_unlock(&pool->mutex);
                        return -1;
                    }
                }
            }
        }
    }
 
CONT:
    Pthread_mutex_unlock(&pool->mutex);
    heap_destroy(&pool->task_queue);
    Pthread_mutex_destroy(&pool->mutex);
    Pthread_cond_destroy(&pool->cond);
    Pthread_cond_destroy(&pool->exit_cond);
    Pthread_cond_destroy(&pool->task_over_cond);
    free(pool);
    return 0;
}
Beispiel #4
0
void *do_reg(void *arg)
{
    int sfd, confd;
    struct sockaddr_in cli_addr;		
    arg_t *rarg; 
    socklen_t len = sizeof(struct sockaddr_in); 
    pthread_t tid;

    Pthread_mutex_init(&psyc, NULL);
    sbuf_init(&sbuf, SHORT_BUF);

    rarg = (arg_t *)arg;
    sfd = init_tcp_sock(rarg->port, rarg->serv_ip);
    if(sfd == -1) {
        err_sys("failed to init tcp socket...\n");
    }

#ifdef DEBUG		
    printf("init the tcp sock\n"); /* for debuging... */
#endif
    while(1){
        Pthread_mutex_lock(&psyc);
        confd = Accept(sfd, (SA *)&cli_addr, &len);
        Pthread_mutex_unlock(&psyc);
        Pthread_create(&tid, NULL, serv_thread, &confd);
#ifdef DEBUG		
        printf("one client come to server: %s\n",
                inet_ntoa(cli_addr.sin_addr));
#endif

    }

    Pthread_mutex_destroy(&psyc);
    sbuf_deinit(&sbuf);
    close(sfd);
    return NULL;
}
Beispiel #5
0
DiskMgr::~DiskMgr()
{
	//TODO delete m_diskinfo
	Pthread_mutex_destroy(&m_mutex);
}
Beispiel #6
0
DiskInfo::~DiskInfo()
{
	Pthread_mutex_destroy(&mutex);
	pthread_cond_destroy(&cond);
}
Beispiel #7
0
	~FairLock() {
		Pthread_mutex_destroy(&m);
	}