From b19e0980947868d582c4f16b120da23e3cda6bca Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 30 Sep 2005 15:42:28 +0000 Subject: [PATCH] prevent use of threading interfaces without HAVE_THREADS --- panda/src/net/connectionReader.cxx | 14 ++++++++++++++ panda/src/net/connectionWriter.cxx | 14 ++++++++++++++ pandatool/src/pstatserver/pStatReader.cxx | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/panda/src/net/connectionReader.cxx b/panda/src/net/connectionReader.cxx index f0e30e94f2..acd71c4317 100644 --- a/panda/src/net/connectionReader.cxx +++ b/panda/src/net/connectionReader.cxx @@ -81,6 +81,20 @@ ConnectionReader:: ConnectionReader(ConnectionManager *manager, int num_threads) : _manager(manager) { +#ifndef HAVE_THREADS + // Although this code is written to use thread-locking primitives + // regardless of the definition of HAVE_THREADS, it is not safe to + // spawn multiple threads when HAVE_THREADS is not true, since we + // might be using a non-thread-safe malloc scheme. +#ifndef NDEBUG + if (num_threads != 0) { + net_cat.error() + << "Threading support is not available.\n"; + } +#endif // NDEBUG + num_threads = 0; +#endif // HAVE_THREADS + _raw_mode = false; _tcp_header_size = datagram_tcp16_header_size; _polling = (num_threads <= 0); diff --git a/panda/src/net/connectionWriter.cxx b/panda/src/net/connectionWriter.cxx index 360e2d5997..855e5f57fc 100644 --- a/panda/src/net/connectionWriter.cxx +++ b/panda/src/net/connectionWriter.cxx @@ -38,6 +38,20 @@ ConnectionWriter:: ConnectionWriter(ConnectionManager *manager, int num_threads) : _manager(manager) { +#ifndef HAVE_THREADS + // Although this code is written to use thread-locking primitives + // regardless of the definition of HAVE_THREADS, it is not safe to + // spawn multiple threads when HAVE_THREADS is not true, since we + // might be using a non-thread-safe malloc scheme. +#ifndef NDEBUG + if (num_threads != 0) { + net_cat.error() + << "Threading support is not available.\n"; + } +#endif // NDEBUG + num_threads = 0; +#endif // HAVE_THREADS + _raw_mode = false; _tcp_header_size = datagram_tcp16_header_size; _immediate = (num_threads <= 0); diff --git a/pandatool/src/pstatserver/pStatReader.cxx b/pandatool/src/pstatserver/pStatReader.cxx index 22235acb28..638de6ae63 100644 --- a/pandatool/src/pstatserver/pStatReader.cxx +++ b/pandatool/src/pstatserver/pStatReader.cxx @@ -35,7 +35,11 @@ //////////////////////////////////////////////////////////////////// PStatReader:: PStatReader(PStatServer *manager, PStatMonitor *monitor) : +#ifdef HAVE_THREADS ConnectionReader(manager, monitor->is_thread_safe() ? 1 : 0), +#else // HAVE_THREADS + ConnectionReader(manager, 0), +#endif // HAVE_THREADS _manager(manager), _monitor(monitor), _writer(manager, 0)