Beispiel #1
0
static void ioWorkerThread(void) {
	while (!gIOTerminate) {
		SleepThread();

		// no processing when io is blocked
		if (isIOBlocked)
			continue;
			
		// if term requested exit immediately from the loop
		if (gIOTerminate)
			break;
		
		// do we have a request in the queue?
		while (gReqList) {
			WaitSema(gProcSemaId);
			
			struct io_request_t* req = gReqList;
			ioProcessRequest(req);

			// lock the queue tip as well now
			WaitSema(gEndSemaId);
			
			// can't be sure if the request was
			gReqList = req->next;
			free(req);
						
			if (!gReqList)
				gReqEnd = NULL;

			SignalSema(gProcSemaId);
			SignalSema(gEndSemaId);
		}
	}
	
	// delete the pending requests
	while (gReqList) {
		struct io_request_t* req = gReqList;
		gReqList = gReqList->next;
		free(req); // TODO: Leak over here - we need a propper flag to free/not the user data
	}
	
	// delete the semaphores
	DeleteSema(gProcSemaId);
	DeleteSema(gEndSemaId);
	
	isIORunning = 0;

	ExitDeleteThread();
}
Beispiel #2
0
static void ioWorkerThread(void *arg) {
	while (!gIOTerminate) {
		SleepThread();

		// if term requested exit immediately from the loop
		if (gIOTerminate)
			break;

		// do we have a request in the queue?
		WaitSema(gProcSemaId);
		while (gReqList) {
			// if term requested exit immediately from the loop
			if (gIOTerminate)
				break;

			struct io_request_t* req = gReqList;
			ioProcessRequest(req);

			// lock the queue tip as well now
			WaitSema(gEndSemaId);

			// can't be sure if the request was
			gReqList = req->next;
			free(req);

			if (!gReqList)
				gReqEnd = NULL;

			SignalSema(gEndSemaId);
		}
		SignalSema(gProcSemaId);
	}

	// delete the pending requests
	while (gReqList) {
		struct io_request_t* req = gReqList;
		gReqList = gReqList->next;
		free(req);
	}

	// delete the semaphores
	DeleteSema(gProcSemaId);
	DeleteSema(gEndSemaId);

	isIORunning = 0;

	ExitDeleteThread();
}