Merge pull request 1422 from master

This commit is contained in:
Bernhard Miklautz 2013-08-26 20:11:31 +02:00
commit 84f1001573
4 changed files with 68 additions and 14 deletions

View File

@ -286,6 +286,7 @@ static void parallel_free(DEVICE* device)
MessageQueue_PostQuit(parallel->queue, 0);
WaitForSingleObject(parallel->thread, INFINITE);
Stream_Free(parallel->device.data, TRUE);
MessageQueue_Free(parallel->queue);
CloseHandle(parallel->thread);

View File

@ -323,29 +323,28 @@ static void* serial_thread_func(void* arg)
IRP* irp;
DWORD status;
SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg;
HANDLE ev[] = {serial->stopEvent, Queue_Event(serial->queue)};
while (1)
{
if (WaitForSingleObject(serial->stopEvent, 0) == WAIT_OBJECT_0)
break;
status = WaitForMultipleObjects(2, ev, FALSE, 1);
status = WaitForSingleObject(Queue_Event(serial->queue), 10);
if ((status != WAIT_OBJECT_0) && (status != WAIT_TIMEOUT))
if (WAIT_OBJECT_0 == status)
break;
serial->nfds = 1;
FD_ZERO(&serial->read_fds);
FD_ZERO(&serial->write_fds);
serial->tv.tv_sec = 1;
serial->tv.tv_sec = 0;
serial->tv.tv_usec = 0;
serial->select_timeout = 0;
if (status == WAIT_OBJECT_0)
if (status == WAIT_OBJECT_0 + 1)
{
if ((irp = (IRP*) Queue_Dequeue(serial->queue)))
serial_process_irp(serial, irp);
continue;
}
serial_check_fds(serial);
@ -367,10 +366,18 @@ static void serial_free(DEVICE* device)
DEBUG_SVC("freeing device");
/* Stop thread */
SetEvent(serial->stopEvent);
WaitForSingleObject(serial->thread, INFINITE);
/* TODO: free lists */
serial_tty_free(serial->tty);
/* Clean up resources */
Stream_Free(serial->device.data, TRUE);
Queue_Free(serial->queue);
list_free(serial->pending_irps);
CloseHandle(serial->stopEvent);
CloseHandle(serial->thread);
free(serial);
}
@ -383,6 +390,11 @@ static void serial_abort_single_io(SERIAL_DEVICE* serial, UINT32 file_id, UINT32
DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
switch (abort_io)
{
@ -433,6 +445,11 @@ static void serial_check_for_events(SERIAL_DEVICE* serial)
SERIAL_TTY* tty;
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));
@ -478,6 +495,11 @@ void serial_get_timeouts(SERIAL_DEVICE* serial, IRP* irp, UINT32* timeout, UINT3
DEBUG_SVC("length read %u", Length);
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
*timeout = (tty->read_total_timeout_multiplier * Length) + tty->read_total_timeout_constant;
*interval_timeout = tty->read_interval_timeout;
@ -492,6 +514,11 @@ static void serial_handle_async_irp(SERIAL_DEVICE* serial, IRP* irp)
SERIAL_TTY* tty;
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
switch (irp->MajorFunction)
{
@ -542,6 +569,11 @@ static void __serial_check_fds(SERIAL_DEVICE* serial)
ZeroMemory(&serial->tv, sizeof(struct timeval));
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
/* scan every pending */
irp = list_peek(serial->pending_irps);
@ -604,6 +636,11 @@ static void serial_set_fds(SERIAL_DEVICE* serial)
DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));
tty = serial->tty;
if(!tty)
{
DEBUG_WARN("tty = %p", tty);
return;
}
irp = (IRP*) list_peek(serial->pending_irps);
while (irp)
@ -705,7 +742,8 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial);
serial->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL);
serial->thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL);
}
return 0;

View File

@ -412,7 +412,11 @@ BOOL serial_tty_read(SERIAL_TTY* tty, BYTE* buffer, UINT32* Length)
status = read(tty->fd, buffer, *Length);
if (status < 0)
{
DEBUG_WARN("failed with %zd, errno=[%d] %s\n",
status, errno, strerror(errno));
return FALSE;
}
tty->event_txempty = status;
*Length = status;
@ -456,6 +460,9 @@ void serial_tty_free(SERIAL_TTY* tty)
{
DEBUG_SVC("in");
if(!tty)
return;
if (tty->fd >= 0)
{
if (tty->pold_termios)

View File

@ -44,8 +44,7 @@ static void smartcard_free(DEVICE* dev)
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) dev;
SetEvent(smartcard->stopEvent);
CloseHandle(smartcard->thread);
CloseHandle(smartcard->irpEvent);
WaitForSingleObject(smartcard->thread, INFINITE);
while ((irp = (IRP*) InterlockedPopEntrySList(smartcard->pIrpList)) != NULL)
irp->Discard(irp);
@ -55,8 +54,14 @@ static void smartcard_free(DEVICE* dev)
/* Begin TS Client defect workaround. */
while ((CompletionIdInfo = (COMPLETIONIDINFO*) list_dequeue(smartcard->CompletionIds)) != NULL)
free(CompletionIdInfo);
free(CompletionIdInfo);
CloseHandle(smartcard->thread);
CloseHandle(smartcard->irpEvent);
CloseHandle(smartcard->stopEvent);
CloseHandle(smartcard->CompletionIdsMutex);
Stream_Free(smartcard->device.data, TRUE);
list_free(smartcard->CompletionIds);
/* End TS Client defect workaround. */
@ -119,13 +124,16 @@ static void smartcard_process_irp_thread_func(SMARTCARD_IRP_WORKER* irpWorker)
static void* smartcard_thread_func(void* arg)
{
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) arg;
HANDLE ev[] = {smartcard->irpEvent, smartcard->stopEvent};
while (1)
{
WaitForSingleObject(smartcard->irpEvent, INFINITE);
DWORD status = WaitForSingleObject(2, ev, FALSE, INFINITE);
if (WaitForSingleObject(smartcard->stopEvent, 0) == WAIT_OBJECT_0)
if (status == WAIT_OBJECT_0 + 1)
break;
else if(status != WAIT_OBJECT_0)
continue;
ResetEvent(smartcard->irpEvent);
smartcard_process_irp_list(smartcard);