aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/udp_listener.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/udp_listener.c')
-rw-r--r--daemon/udp_listener.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/daemon/udp_listener.c b/daemon/udp_listener.c
index c039049..f9c7c1a 100644
--- a/daemon/udp_listener.c
+++ b/daemon/udp_listener.c
@@ -40,7 +40,8 @@ static gchar *datagram_buffer = NULL;
static HANDLE udp_listener_thread_handle = NULL;
struct fifo *udp_message_queue = NULL;
-HANDLE udp_queue_semaphore = NULL;
+HANDLE udp_queue_event = NULL;
+CRITICAL_SECTION udp_queue_cs;
/******************************************************************************
* udp_listener_thread
@@ -102,8 +103,10 @@ static unsigned __stdcall udp_listener_thread( void* arg )
/* allocate raw message and add it to the queue */
msg = g_malloc( sizeof(struct raw_message) );
memcpy( msg, &message, sizeof(struct raw_message) );
- fifo_push( udp_message_queue, msg );
- ReleaseSemaphore( udp_queue_semaphore, 1, NULL );
+ EnterCriticalSection( &udp_queue_cs );
+ if( fifo_push( udp_message_queue, msg ) )
+ SetEvent( udp_queue_event );
+ LeaveCriticalSection( &udp_queue_cs );
}
done:
@@ -115,7 +118,7 @@ done:
* shutdown_udp_listener
*
* stop listening thread and dispose all objects
- * except message queue and semaphore
+ * except message queue and event
*/
void shutdown_udp_listener()
{
@@ -184,10 +187,11 @@ void fini_udp_listener()
udp_message_queue = NULL;
}
- if( udp_queue_semaphore )
+ if( udp_queue_event )
{
- CloseHandle( udp_queue_semaphore );
- udp_queue_semaphore = NULL;
+ DeleteCriticalSection( &udp_queue_cs );
+ CloseHandle( udp_queue_event );
+ udp_queue_event = NULL;
}
TRACE_LEAVE( "done\n" );
@@ -207,17 +211,18 @@ gboolean init_udp_listener()
TRACE_ENTER( "\n" );
- /* create message queue and semaphore;
+ /* create message queue and event;
* we should do this first because of possible early returns
* from this function when no sources are defined
*/
udp_message_queue = fifo_create();
- udp_queue_semaphore = CreateSemaphore( NULL, 0, LONG_MAX, NULL );
- if( !udp_queue_semaphore )
+ udp_queue_event = CreateEvent( NULL, TRUE, FALSE, NULL );
+ if( !udp_queue_event )
{
- ERR( "Cannot create semaphore; error %lu\n", GetLastError() );
+ ERR( "Cannot create event; error %lu\n", GetLastError() );
goto done;
}
+ InitializeCriticalSection( &udp_queue_cs );
n = number_of_sources( ST_UDP );
if( 0 == n )