Browse Source

prevent use of threading interfaces without HAVE_THREADS

David Rose 20 years ago
parent
commit
b19e098094

+ 14 - 0
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);

+ 14 - 0
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);

+ 4 - 0
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)