mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
Fix race condition when multiple threads write to MultiplexStream simultaneously
This commit is contained in:
parent
9b5ff08011
commit
7266f5ae68
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "multiplexStreamBuf.h"
|
#include "multiplexStreamBuf.h"
|
||||||
|
#include "lightMutexHolder.h"
|
||||||
|
|
||||||
#if defined(WIN32_VC) || defined(WIN64_VC)
|
#if defined(WIN32_VC) || defined(WIN64_VC)
|
||||||
#define WINDOWS_LEAN_AND_MEAN
|
#define WINDOWS_LEAN_AND_MEAN
|
||||||
@ -113,10 +114,8 @@ void MultiplexStreamBuf::
|
|||||||
add_output(MultiplexStreamBuf::BufferType buffer_type,
|
add_output(MultiplexStreamBuf::BufferType buffer_type,
|
||||||
MultiplexStreamBuf::OutputType output_type,
|
MultiplexStreamBuf::OutputType output_type,
|
||||||
ostream *out, FILE *fout, bool owns_obj) {
|
ostream *out, FILE *fout, bool owns_obj) {
|
||||||
#ifdef OLD_HAVE_IPC
|
|
||||||
// Ensure that we have the mutex while we fiddle with the list of outputs.
|
// Ensure that we have the mutex while we fiddle with the list of outputs.
|
||||||
mutex_lock m(_lock);
|
LightMutexHolder holder(_lock);
|
||||||
#endif
|
|
||||||
|
|
||||||
Output o;
|
Output o;
|
||||||
o._buffer_type = buffer_type;
|
o._buffer_type = buffer_type;
|
||||||
@ -133,9 +132,7 @@ add_output(MultiplexStreamBuf::BufferType buffer_type,
|
|||||||
*/
|
*/
|
||||||
void MultiplexStreamBuf::
|
void MultiplexStreamBuf::
|
||||||
flush() {
|
flush() {
|
||||||
#ifdef OLD_HAVE_IPC
|
LightMutexHolder holder(_lock);
|
||||||
mutex_lock m(_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
write_chars("", 0, true);
|
write_chars("", 0, true);
|
||||||
}
|
}
|
||||||
@ -146,9 +143,7 @@ flush() {
|
|||||||
*/
|
*/
|
||||||
int MultiplexStreamBuf::
|
int MultiplexStreamBuf::
|
||||||
overflow(int ch) {
|
overflow(int ch) {
|
||||||
#ifdef OLD_HAVE_IPC
|
LightMutexHolder holder(_lock);
|
||||||
mutex_lock m(_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
streamsize n = pptr() - pbase();
|
streamsize n = pptr() - pbase();
|
||||||
|
|
||||||
@ -172,9 +167,7 @@ overflow(int ch) {
|
|||||||
*/
|
*/
|
||||||
int MultiplexStreamBuf::
|
int MultiplexStreamBuf::
|
||||||
sync() {
|
sync() {
|
||||||
#ifdef OLD_HAVE_IPC
|
LightMutexHolder holder(_lock);
|
||||||
mutex_lock m(_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
streamsize n = pptr() - pbase();
|
streamsize n = pptr() - pbase();
|
||||||
|
|
||||||
@ -242,5 +235,4 @@ write_chars(const char *start, int length, bool flush) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
|
|
||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
|
#include "lightMutex.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +70,7 @@ private:
|
|||||||
typedef pvector<Output> Outputs;
|
typedef pvector<Output> Outputs;
|
||||||
Outputs _outputs;
|
Outputs _outputs;
|
||||||
|
|
||||||
|
LightMutex _lock;
|
||||||
string _line_buffer;
|
string _line_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user