static void
logClose(struct _TServer * const srvP) {

    if (srvP->logfileisopen) {
        FileClose(&srvP->logfile);
        MutexFree(&srvP->logmutex);
        srvP->logfileisopen = FALSE;
    }
}
Beispiel #2
0
int PoolCreate(TPool *p,uint32 zonesize)
{
	/* sanity */
	if (!p) {
		return FALSE;
	}

	p->zonesize=zonesize;
	if (MutexCreate(&p->mutex))
		if (!(p->firstzone=p->currentzone=PoolZoneAlloc(zonesize)))
		{
			MutexFree(&p->mutex);
			return FALSE;
		};
	
	return TRUE;
}
Beispiel #3
0
static void testMutexes()
{
	/* for now at least, be aware that a TMutex is just typedeffed
	   to a pthread_mutex_t */

	{
		/* test TMutexes that live on the stack */
		TMutex stackMutex;
		assert(MutexCreate(&stackMutex) == TRUE);
		assert(MutexCreate(&stackMutex) == TRUE);
		assert(MutexLock(&stackMutex) == TRUE);
		assert(MutexUnlock(&stackMutex) == TRUE);
		assert(MutexTryLock(&stackMutex) == TRUE);
		assert(MutexUnlock(&stackMutex) == TRUE);

		assert(MutexLock(&stackMutex) == TRUE);
		assert(MutexTryLock(&stackMutex) == FALSE);
		assert(MutexUnlock(&stackMutex) == TRUE);

		MutexFree(&stackMutex);
	}

	{
		/* just a sanity, please don't core on me test */
		TMutex *heapMutex = 0;

		assert(MutexCreate(heapMutex) == FALSE);
		assert(MutexLock(heapMutex) == FALSE);
		assert(MutexUnlock(heapMutex) == FALSE);
		assert(MutexTryLock(heapMutex) == FALSE);
		assert(MutexUnlock(heapMutex) == FALSE);

		assert(MutexLock(heapMutex) == FALSE);
		assert(MutexTryLock(heapMutex) == FALSE);
		assert(MutexUnlock(heapMutex) == FALSE);

		MutexFree(heapMutex);

		assert(heapMutex == 0);
	}

	{
		/* test TMutexes that live on the heap */
		TMutex *heapMutex = (TMutex*)malloc(sizeof(TMutex));

		assert(MutexCreate(heapMutex) == TRUE);
		assert(MutexLock(heapMutex) == TRUE);
		assert(MutexUnlock(heapMutex) == TRUE);
		assert(MutexTryLock(heapMutex) == TRUE);
		assert(MutexUnlock(heapMutex) == TRUE);

		assert(MutexLock(heapMutex) == TRUE);
		assert(MutexTryLock(heapMutex) == FALSE);
		assert(MutexUnlock(heapMutex) == TRUE);

		MutexFree(heapMutex);

		free(heapMutex);
		heapMutex = 0;
	}
}