From d826fc5be99dc2d32d76d1c2afb2c45f2b09b67f Mon Sep 17 00:00:00 2001 From: yaworsky Date: Thu, 3 Nov 2005 04:33:27 +0000 Subject: Avoid race --- daemon/dest_file.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/daemon/dest_file.c b/daemon/dest_file.c index a1e917b..3925499 100644 --- a/daemon/dest_file.c +++ b/daemon/dest_file.c @@ -246,11 +246,13 @@ static void destroy_file_writer( struct file_writer* writer ) /****************************************************************************** * create_file_writer */ -static struct file_writer* create_file_writer( gchar* file_name ) +static struct file_writer* create_file_writer( gchar* file_name, + struct destination* destination ) { struct file_writer *ret; unsigned writer_thread_id; HANDLE *writer_thread; + struct dest_extra *extra; TRACE_ENTER( "file_name=%s\n", file_name ); ret = g_malloc0( sizeof(struct file_writer) ); @@ -268,14 +270,23 @@ static struct file_writer* create_file_writer( gchar* file_name ) ERR( "Cannot create event; error %lu\n", GetLastError() ); goto error; } + writer_thread = (HANDLE) _beginthreadex( NULL, 0, writer_thread_proc, ret, - 0, &writer_thread_id ); + CREATE_SUSPENDED, &writer_thread_id ); if( !writer_thread ) { ERR( "Cannot create thread; error %lu\n", GetLastError() ); goto error; } + + /* add writer to destination */ + extra = destination->extra; + extra->file_writers = g_list_append( extra->file_writers, ret ); + ret->destination = destination; + + ResumeThread( writer_thread ); CloseHandle( writer_thread ); + TRACE_LEAVE( "done; ret=%p\n", ret ); return ret; @@ -464,12 +475,9 @@ static void put_message_to_file_dest( struct destination* destination, struct me if( !writer ) { /* create new writer */ - writer = create_file_writer( file_name ); + writer = create_file_writer( file_name, destination ); if( !writer ) goto done; - /* add writer to destination */ - extra->file_writers = g_list_append( extra->file_writers, writer ); - writer->destination = destination; } /* put message into queue */ reference_message( msg ); -- cgit v1.2.3