2
0
Эх сурвалжийг харах

*** empty log message ***

David Rose 25 жил өмнө
parent
commit
4fa76ebd0b

+ 14 - 6
panda/src/downloader/Sources.pp

@@ -14,6 +14,8 @@
     downloadDb.cxx downloadDb.h						\
     downloader.I downloader.cxx downloader.h extractor.cxx extractor.h	\
     hashVal.cxx hashVal.I hashVal.h \
+    multiplexStream.I multiplexStream.cxx multiplexStream.h \
+    multiplexStreamBuf.I multiplexStreamBuf.cxx multiplexStreamBuf.h \
     patcher.cxx								\
     patcher.h
 
@@ -24,12 +26,18 @@
   #define IF_CRYPTO_SOURCES \
     crypto_utils.cxx crypto_utils.h
 
-  #define INSTALL_HEADERS					\
-    downloader.h downloader.I					\
-    config_downloader.h zcompressor.I zcompressor.h		\
-    asyncUtility.h asyncUtility.I decompressor.h		\
-    extractor.h download_utils.h downloadDb.h downloadDb.I	\
-    hashVal.I hashVal.h patcher.h
+  #define INSTALL_HEADERS \
+    asyncUtility.h asyncUtility.I \
+    config_downloader.h \
+    decompressor.h \
+    download_utils.h downloadDb.h downloadDb.I \
+    downloader.h downloader.I \
+    extractor.h \
+    hashVal.I hashVal.h \
+    multiplexStream.I multiplexStream.h \
+    multiplexStreamBuf.I multiplexStreamBuf.I \
+    patcher.h \
+    zcompressor.I zcompressor.h
 
   #define IGATESCAN all
 

+ 0 - 0
panda/src/express/multiplexStream.I → panda/src/downloader/multiplexStream.I


+ 0 - 0
panda/src/express/multiplexStream.cxx → panda/src/downloader/multiplexStream.cxx


+ 0 - 0
panda/src/express/multiplexStream.h → panda/src/downloader/multiplexStream.h


+ 5 - 0
panda/src/downloader/multiplexStreamBuf.I

@@ -0,0 +1,5 @@
+// Filename: multiplexStreamBuf.I
+// Created by:  drose (27Nov00)
+// 
+////////////////////////////////////////////////////////////////////
+

+ 69 - 16
panda/src/express/multiplexStreamBuf.cxx → panda/src/downloader/multiplexStreamBuf.cxx

@@ -108,25 +108,44 @@ MultiplexStreamBuf::
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: MultiplexStreamBuf::sync
-//       Access: Public, Virtual
-//  Description: Called by the system ostream implementation when the
-//               buffer should be flushed to output (for instance, on
-//               destruction).
+//     Function: MultiplexStreamBuf::add_output
+//       Access: Public
+//  Description: Adds the indicated output destinition to the set of
+//               things that will be written to when characters are
+//               output to the MultiplexStream.
 ////////////////////////////////////////////////////////////////////
-int MultiplexStreamBuf::
-sync() { 
-  streamsize n = pptr() - pbase();
+void MultiplexStreamBuf::
+add_output(MultiplexStreamBuf::BufferType buffer_type,
+	   MultiplexStreamBuf::OutputType output_type,
+	   ostream *out, FILE *fout, bool owns_obj) {
+#ifdef HAVE_IPC
+  // Ensure that we have the mutex while we fiddle with the list of
+  // outputs.
+  mutex_lock m(_lock);
+#endif
 
-  // We pass in false for the flush value, even though our
-  // transmitting ostream said to sync.  This allows us to get better
-  // line buffering, since our transmitting ostream is often set
-  // unitbuf, and might call sync multiple times in one line.  We
-  // still have an explicit flush() call to force the issue.
-  write_chars(pbase(), n, false);
-  pbump(-n);
+  Output o;
+  o._buffer_type = buffer_type;
+  o._output_type = output_type;
+  o._out = out;
+  o._fout = fout;
+  o._owns_obj = owns_obj;
+  _outputs.push_back(o);
+}
 
-  return 0;  // Return 0 for success, EOF to indicate write full.
+
+////////////////////////////////////////////////////////////////////
+//     Function: MultiplexStreamBuf::flush
+//       Access: Public
+//  Description: Forces out all output that hasn't yet been written.
+////////////////////////////////////////////////////////////////////
+void MultiplexStreamBuf::
+flush() {
+#ifdef HAVE_IPC
+  mutex_lock m(_lock);
+#endif
+
+  write_chars("", 0, true);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -137,6 +156,10 @@ sync() {
 ////////////////////////////////////////////////////////////////////
 int MultiplexStreamBuf::
 overflow(int ch) { 
+#ifdef HAVE_IPC
+  mutex_lock m(_lock);
+#endif
+
   streamsize n = pptr() - pbase();
 
   if (n != 0) {
@@ -153,12 +176,42 @@ overflow(int ch) {
   return 0;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MultiplexStreamBuf::sync
+//       Access: Public, Virtual
+//  Description: Called by the system ostream implementation when the
+//               buffer should be flushed to output (for instance, on
+//               destruction).
+////////////////////////////////////////////////////////////////////
+int MultiplexStreamBuf::
+sync() { 
+#ifdef HAVE_IPC
+  mutex_lock m(_lock);
+#endif
+
+  streamsize n = pptr() - pbase();
+
+  // We pass in false for the flush value, even though our
+  // transmitting ostream said to sync.  This allows us to get better
+  // line buffering, since our transmitting ostream is often set
+  // unitbuf, and might call sync multiple times in one line.  We
+  // still have an explicit flush() call to force the issue.
+  write_chars(pbase(), n, false);
+  pbump(-n);
+
+  return 0;  // Return 0 for success, EOF to indicate write full.
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MultiplexStreamBuf::write_chars
 //       Access: Private
 //  Description: An internal function called by sync() and overflow()
 //               to store one or more characters written to the stream
 //               into the memory buffer.
+//
+//               It is assumed that there is only one thread at a time
+//               running this code; it is the responsibility of the
+//               caller to grab the _lock mutex before calling this.
 ////////////////////////////////////////////////////////////////////
 void MultiplexStreamBuf::
 write_chars(const char *start, int length, bool flush) {

+ 13 - 5
panda/src/express/multiplexStreamBuf.h → panda/src/downloader/multiplexStreamBuf.h

@@ -8,6 +8,10 @@
 
 #include <pandabase.h>
 
+#ifdef HAVE_IPC
+#include <ipc_mutex.h>
+#endif
+
 #include <vector>
 #include <stdio.h>
 
@@ -33,12 +37,12 @@ public:
     OT_system_debug,
   };
 
-  INLINE void add_output(BufferType buffer_type, OutputType output_type,
-			 ostream *out = (ostream *)NULL, 
-			 FILE *fout = (FILE *)NULL, 
-			 bool owns_obj = false);
+  void add_output(BufferType buffer_type, OutputType output_type,
+		  ostream *out = (ostream *)NULL, 
+		  FILE *fout = (FILE *)NULL, 
+		  bool owns_obj = false);
 
-  INLINE void flush();
+  void flush();
 
 protected:
   virtual int overflow(int c);
@@ -64,6 +68,10 @@ private:
   Outputs _outputs;
 
   string _line_buffer;
+
+#ifdef HAVE_IPC
+  mutex _lock;
+#endif
 };
 
 #include "multiplexStreamBuf.I"

+ 0 - 4
panda/src/express/Sources.pp

@@ -19,8 +19,6 @@
     littleEndian.cxx littleEndian.h memoryUsage.I memoryUsage.cxx	\
     memoryUsage.h memoryUsagePointers.I memoryUsagePointers.cxx		\
     memoryUsagePointers.h multifile.I multifile.cxx multifile.h \
-    multiplexStream.I multiplexStream.cxx multiplexStream.h \
-    multiplexStreamBuf.I multiplexStreamBuf.cxx multiplexStreamBuf.h \
     namable.I namable.cxx namable.h numeric_types.h patchfile.I		\
     patchfile.cxx patchfile.h pointerTo.I pointerTo.h referenceCount.I	\
     referenceCount.cxx referenceCount.h tokenBoard.I tokenBoard.h	\
@@ -38,8 +36,6 @@
     indent.I indent.h littleEndian.I littleEndian.h			\
     memoryUsage.I memoryUsage.h memoryUsagePointers.I			\
     memoryUsagePointers.h multifile.I multifile.h \
-    multiplexStream.I multiplexStream.h \
-    multiplexStreamBuf.I multiplexStreamBuf.I \
     numeric_types.h	\
     pointerTo.I pointerTo.h referenceCount.I referenceCount.h		\
     tokenBoard.h trueClock.I trueClock.h typeHandle.I typeHandle.h	\

+ 0 - 36
panda/src/express/multiplexStreamBuf.I

@@ -1,36 +0,0 @@
-// Filename: multiplexStreamBuf.I
-// Created by:  drose (27Nov00)
-// 
-////////////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: MultiplexStreamBuf::add_output
-//       Access: Public
-//  Description: Adds the indicated output destinition to the set of
-//               things that will be written to when characters are
-//               output to the MultiplexStream.
-////////////////////////////////////////////////////////////////////
-INLINE void MultiplexStreamBuf::
-add_output(MultiplexStreamBuf::BufferType buffer_type,
-	   MultiplexStreamBuf::OutputType output_type,
-	   ostream *out, FILE *fout, bool owns_obj) {
-  Output o;
-  o._buffer_type = buffer_type;
-  o._output_type = output_type;
-  o._out = out;
-  o._fout = fout;
-  o._owns_obj = owns_obj;
-  _outputs.push_back(o);
-}
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: MultiplexStreamBuf::flush
-//       Access: Public
-//  Description: Forces out all output that hasn't yet been written.
-////////////////////////////////////////////////////////////////////
-INLINE void MultiplexStreamBuf::
-flush() {
-  write_chars("", 0, true);
-}