Exemple #1
0
static void event_free(ACL_EVENT *eventp)
{
	const char *myname = "event_free";
	EVENT_SELECT_THR *event_thr = (EVENT_SELECT_THR *) eventp;

	if (eventp == NULL)
		acl_msg_fatal("%s, %s(%d): eventp null",
				__FILE__, myname, __LINE__);

	acl_pthread_mutex_destroy(&event_thr->event.tm_mutex);
	acl_pthread_mutex_destroy(&event_thr->event.tb_mutex);

	acl_myfree(eventp);
}
Exemple #2
0
rpc_request::~rpc_request()
{
	acl_pthread_mutex_destroy(lock_);
	acl_myfree(lock_);

	acl_pthread_cond_destroy(cond_);
	acl_myfree(cond_);
}
Exemple #3
0
thread_mutex::~thread_mutex(void)
{
#ifndef	ACL_WINDOWS
	(void) pthread_mutexattr_destroy(&mutex_attr_);
#endif
	(void) acl_pthread_mutex_destroy(mutex_);
	acl_myfree(mutex_);
}
Exemple #4
0
void acl_atomic_free(ACL_ATOMIC *self)
{
	self->value = NULL;
#ifndef HAS_ATOMIC
	acl_pthread_mutex_destroy(&self->lock);
	acl_myfree(self);
#endif
}
Exemple #5
0
void acl_mbox_free(ACL_MBOX *mbox, void (*free_fn)(void*))
{
	acl_vstream_close(mbox->in);
	acl_vstream_close(mbox->out);
	acl_ypipe_free(mbox->ypipe, free_fn);
	acl_pthread_mutex_destroy(mbox->lock);
	acl_myfree(mbox);
}
Exemple #6
0
static void mempool_bench_test2(const char *label, int use_pool, int mutex, int loop, int size)
{
	char *buf;
	time_t begin, end;
	int   i;
	static int __pool_inited = 0;

	if (use_pool) {
		if (__pool_inited == 0) {
			acl_mempool_open(__max_size, mutex);
			__pool_inited = 1;
		} else {
			acl_mempool_ctl(ACL_MEMPOOL_CTL_MUTEX, mutex,
					ACL_MEMPOOL_CTL_END);
		}

		i = 0;
		time(&begin);
		while (i++ < loop) {
			buf = MALLOC(size);
			FREE(buf);
		}
		time(&end);
	} else {
		acl_pthread_mutex_t lock;

		if (mutex)
			acl_pthread_mutex_init(&lock, NULL);

		if (__pool_inited) {
			acl_mempool_ctl(ACL_MEMPOOL_CTL_DISABLE, 1,
					ACL_MEMPOOL_CTL_END);
		}

		i = 0;
		time(&begin);
		while (i++ < loop) {
			buf = MALLOC(size);
			FREE(buf);
		}
		time(&end);

		if (mutex)
			acl_pthread_mutex_destroy(&lock);
	}

	if (use_pool)
		printf("%s: time cost is %ld seconds, count is %d, total pool alloc %d\r\n",
			label, (long int) end - begin, loop, acl_mempool_total_allocated());
	else
		printf("%s: time cost is %ld seconds, count is %d\r\n",
			label, (long int) end - begin, loop);
}
Exemple #7
0
int acl_pthread_cond_destroy(acl_pthread_cond_t *cond)
{
	if (cond == NULL)
		return -1;

	if (cond->wait_sem)
		acl_sem_destroy(cond->wait_sem);
	if (cond->wait_done)
		acl_sem_destroy(cond->wait_done);
	if ( cond->lock )
		acl_pthread_mutex_destroy(cond->lock);

	if (cond->dynamic)
		acl_myfree(cond);

	return 0;
}
Exemple #8
0
static void test_thread_pool(void)
{
	acl_pthread_pool_t *thr_pool;
	ACL_VSTREAM *fp = acl_vstream_fopen("test.log", O_WRONLY | O_CREAT, 0600, 4096);
	int   i;

	acl_pthread_mutex_init(&__mutex, NULL);
	thr_pool = acl_thread_pool_create(10, 10);

	for (i = 0; i < 1000000; i++) {
		RUN_CTX *ctx = (RUN_CTX*) acl_mymalloc(sizeof(RUN_CTX));
		ctx->fp = fp;
		ctx->i = i;
		acl_pthread_pool_add(thr_pool, run_thread, ctx);
	}

	acl_pthread_pool_destroy(thr_pool);
	acl_pthread_mutex_destroy(&__mutex);
	acl_vstream_close(fp);
}
Exemple #9
0
/*----------------------------------------------------------------------------*/
static void __dbpool_mysql_destroy(ACL_DB_POOL *db_pool)
{
	ACL_DB_POOL_MYSQL *mysql_pool;
	ACL_DB_HANDLE_MYSQL *mysql_handle;
	int   i, n;

	mysql_pool = (ACL_DB_POOL_MYSQL *) db_pool;

	n = acl_array_size(mysql_pool->handles);
	for (i = 0; i < n; i++) {
		mysql_handle = (ACL_DB_HANDLE_MYSQL *)
			acl_array_index(mysql_pool->handles, i);
		if (mysql_handle == NULL)
			continue;
		__close_mysql_handle(mysql_handle);
		acl_myfree(mysql_handle);
	}
	acl_pthread_mutex_destroy(&mysql_pool->mutex);
	acl_array_destroy(mysql_pool->handles, NULL);
	acl_myfree(mysql_pool);
	mysql_library_end();
}
Exemple #10
0
locker::~locker()
{
	if (pFile_)
		acl_myfree(pFile_);
	if (myFHandle_ && fHandle_ != ACL_FILE_INVALID)
		acl_file_close(fHandle_);
	if (mutex_)
	{
#ifndef	ACL_WINDOWS
		(void) pthread_mutexattr_destroy(&mutex_attr_);
#endif
		(void) acl_pthread_mutex_destroy(mutex_);
		acl_myfree(mutex_);
	}
#ifdef	ACL_HAS_SPINLOCK
	if (spinlock_)
	{
		pthread_spin_destroy(spinlock_);
		acl_myfree_fn((void*) spinlock_);
	}
#endif
}
Exemple #11
0
void acl_pthread_end(void)
{
	static int __thread_ended = 0;
	int   i;

	tls_value_list_free();

	if (__thread_ended)
		return;

	__thread_ended = 1;
	acl_pthread_mutex_destroy(&__thread_lock);

	for (i = 0; i < ACL_PTHREAD_KEYS_MAX; i++) {
		if (__tls_key_list[i].key >= 0
			&& __tls_key_list[i].key < ACL_PTHREAD_KEYS_MAX)
		{
			TlsFree(__tls_key_list[i].key);
			__tls_key_list[i].key = ACL_TLS_OUT_OF_INDEXES;
		}
		__tls_key_list[i].destructor = NULL;
	}
}
Exemple #12
0
static void mempool_bench_test(const char *label, int mutex, int loop, acl_mem_type type, int size)
{
	int   i = 0;
	time_t begin = 0, end = 0;
	void *buf;
#ifdef	MUTEX_INIT
	acl_pthread_mutex_t lock;
#elif defined(WIN32)
	acl_pthread_mutex_t lock;
#define MUTEX_INIT
#else
	acl_pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
#endif

	if (mutex) {
#ifdef	MUTEX_INIT
		acl_pthread_mutex_init(&lock, NULL);
#endif
		time(&begin);
		while (i++ < loop) {
			acl_pthread_mutex_lock(&lock);
			acl_pthread_mutex_unlock(&lock);
		}
		time(&end);
		printf("lock and unkock, loop %d, time cost is %ld\r\n", loop, (long int) end - begin);

		i = 0;
		if (type > ACL_MEM_TYPE_NONE && type < ACL_MEM_TYPE_MAX) {
			time(&begin);
			while (i++ < loop) {
				acl_pthread_mutex_lock(&lock);
				buf = acl_allocator_mem_alloc(__var_allocator, type);
				acl_pthread_mutex_unlock(&lock);

				acl_pthread_mutex_lock(&lock);
				acl_allocator_mem_free(__var_allocator, type, buf);
				acl_pthread_mutex_unlock(&lock);
			}
			time(&end);
		} else if (type == MEM_TYPE_GROSS) {
			acl_pthread_mutex_lock(&lock);
			buf = acl_allocator_membuf_alloc(__FILE__, __LINE__,
				__var_allocator, size);
			acl_pthread_mutex_unlock(&lock);

			acl_pthread_mutex_lock(&lock);
			acl_allocator_membuf_free(__FILE__, __LINE__,
				__var_allocator, buf);
			acl_pthread_mutex_unlock(&lock);
		} else {
			time(&begin);
			while (i++ < loop) {
				acl_pthread_mutex_lock(&lock);
				buf = MALLOC(size);
				acl_pthread_mutex_unlock(&lock);

				acl_pthread_mutex_lock(&lock);
				FREE(buf);
				acl_pthread_mutex_unlock(&lock);
			}
			time(&end);
		}
#ifdef	MUTEX_INIT
		acl_pthread_mutex_destroy(&lock);
#endif
	} else {
		if (type > ACL_MEM_TYPE_NONE && type < ACL_MEM_TYPE_MAX) {
			time(&begin);
			while (i++ < loop) {
				buf = acl_allocator_mem_alloc(__var_allocator, type);
				acl_allocator_mem_free(__var_allocator, type, buf);
			}
			time(&end);
		} else if (type == MEM_TYPE_GROSS) {
			buf = acl_allocator_membuf_alloc(__FILE__, __LINE__,
				__var_allocator, size);
			acl_allocator_membuf_free(__FILE__, __LINE__,
				__var_allocator, buf);
		} else {
			time(&begin);
			while (i++ < loop) {
				buf = MALLOC(size);
				FREE(buf);
			}
			time(&end);
		}
	}

	printf("%s: time cost is %ld seconds, count is %d\r\n",
		label, (long int) end - begin, loop);
}