コード例 #1
0
int destroy_ring_buffer (buffer_t *buffer) {
	assert (buffer != NULL);

	zlog_category_t *category = zlog_get_category ("ring_buffer");
	assert (category != NULL);

	buffer->shutdown = true;

	zlog_debug (category, "Destroying ring buffer.");

	


	int status;

	// NOTES: Destroy any user before destroy ring buffer!
	//status = pthread_mutex_lock (&buffer->mutex);
	//assert (status == 0);

	zlog_debug (category, "Destroying mutex.");

	simple_cond_broadcast (&buffer->cond_not_full);
	status = simple_cond_destroy (&buffer->cond_not_full);
	assert (status == 0);

	simple_cond_broadcast (&buffer->cond_not_empty);
	status = simple_cond_destroy (&buffer->cond_not_empty);
	assert (status == 0);

	status = simple_mutex_unlock (&buffer->mutex);
	assert (status == 0);
	status = simple_mutex_destroy (&buffer->mutex);
	while (status != 0) {
		status = simple_mutex_destroy (&buffer->mutex);
	}
	assert (status == 0);
	

	zlog_debug (category, "Reclaiming memory.");
	assert (&buffer->entries != NULL);
	free (buffer->entries);

	return 0;
}
コード例 #2
0
ファイル: thread.c プロジェクト: sunkwei/sysmgrt
void simple_thread_join(thread_t *p)
{
#ifdef WIN32
	WaitForSingleObject((HANDLE)p->th, -1);
	CloseHandle((HANDLE)p->th);
#else
	void *rc;
	pthread_join(p->th, &rc);
#endif // os

	simple_mutex_destroy(p->mut);
	simple_sem_destroy(p->sem_req);
	simple_sem_destroy(p->sem_rpl);

	free(p);
}