diff options
author | Conrad Scott <conrad.scott@dsl.pipex.com> | 2002-07-01 01:01:48 +0400 |
---|---|---|
committer | Conrad Scott <conrad.scott@dsl.pipex.com> | 2002-07-01 01:01:48 +0400 |
commit | c89053b489bdd8adfdc16a1a11fb5e82db4c1769 (patch) | |
tree | 3e82e67b79dec300e7934823993d79c7d6832824 /winsup/cygserver | |
parent | 0eb401b32fc31015235f5e83cc26009862bb4de4 (diff) |
* woutsup.h: Remove all uses of the C++ new and delete operators
throughout cygserver until they are fully thread-safe.
(safe_new0): New macro to replace the C++ new operator.
(safe_new): Ditto.
(safe_delete): New macro to replace the C++ delete operator.
* cygserver_client.cc (client_request::handle_request): Replace
all uses of the C++ new and delete operators with the new macros
from "woutsup.h".
(client_request::make_request): Ditto.
* cygserver_process.cc (~process_cleanup): Ditto.
(process::cleanup): Ditto.
(process_cache::process): Ditto.
(process_cache::check_and_remove_process): Ditto.
* cygserver_shm.cc (server_shmmgr::new_segment): Ditto.
(server_shmmgr::delete_segment): Ditto.
* cygserver_transport.cc (create_server_transport): Ditto.
* cygserver_transport_pipes.cc
(transport_layer_pipes::accept): Ditto.
* cygserver_transport_sockets.cc
(transport_layer_sockets::accept): Ditto.
* threaded_queue.cc (~threaded_queue): Ditto.
(threaded_queue::worker_loop): Ditto.
(threaded_queue::stop): Replace sleep(3) with win32 Sleep.
* cygserver.cc (~server_request): Replace all uses of the C++ new
and delete operators with the new macros from "woutsup.h".
(server_submission_loop::request_loop): Ditto.
(main): Ditto. Replace sleep(3) with win32 Sleep. Replace
iostreams with FILEs.
(print_usage): Replace iostreams with FILEs.
(print_version): Ditto.
Diffstat (limited to 'winsup/cygserver')
-rw-r--r-- | winsup/cygserver/threaded_queue.cc | 6 | ||||
-rw-r--r-- | winsup/cygserver/woutsup.h | 34 |
2 files changed, 37 insertions, 3 deletions
diff --git a/winsup/cygserver/threaded_queue.cc b/winsup/cygserver/threaded_queue.cc index e3da7f747..ee7a36e3f 100644 --- a/winsup/cygserver/threaded_queue.cc +++ b/winsup/cygserver/threaded_queue.cc @@ -73,7 +73,7 @@ threaded_queue::~threaded_queue () { queue_request *const ptr = reqptr; reqptr = reqptr->_next; - delete ptr; + safe_delete (queue_request, ptr); } DeleteCriticalSection (&_queue_lock); @@ -146,7 +146,7 @@ threaded_queue::stop () debug_printf (("waiting for worker threads to terminate: " "%lu still running"), _workers_count); - sleep (1); + Sleep (1000); } debug_printf ("all worker threads have terminated"); } @@ -265,7 +265,7 @@ threaded_queue::worker_loop () assert (reqptr); reqptr->process (); - delete reqptr; + safe_delete (queue_request, reqptr); } } diff --git a/winsup/cygserver/woutsup.h b/winsup/cygserver/woutsup.h index 9c153793c..e93a2586c 100644 --- a/winsup/cygserver/woutsup.h +++ b/winsup/cygserver/woutsup.h @@ -106,3 +106,37 @@ extern "C" void __cygserver__printf (const char *, const char *, ...); #define malloc_printf __noop_printf #define thread_printf __noop_printf #endif + +/*****************************************************************************/ + +/* Temporary hack to get around the thread-unsafe new/delete in cygwin + * gcc 2.95.3. This should all be binned at the first opportunity, + * e.g. gcc 3.1 or sooner. + * + * The trick here is to do contruction via malloc(3) and then the + * placement new operator, and destruction via an explicit call to the + * destructor and then free(3). + */ + +#include <new.h> +#include <stdlib.h> + +#define safe_new0(T) (new (malloc (sizeof (T))) T) + +#ifdef NEW_MACRO_VARARGS + +#define safe_new(T, ...) \ + (new (malloc (sizeof (T))) T (__VA_ARGS__)) + +#else /* !NEW_MACRO_VARARGS */ + +#define safe_new(T, args...) \ + (new (malloc (sizeof (T))) T (## args)) + +#endif /* !NEW_MACRO_VARARGS */ + +#define safe_delete(T, O) \ +{ \ + (O)->~ ## T (); \ + free (O); \ +} |