}
}
+#if defined(PEGASUS_OS_LINUX)
+void Mutex::reinitialize()
+{
+ pthread_mutex_init(&_mutex.mut, &_mutex.mutatt);
+ _mutex.owner = 0;
+}
+#endif
+
#ifdef PEGASUS_READWRITE_NATIVE
//-----------------------------------------------------------------
inline PEGASUS_THREAD_TYPE get_owner() { return(_mutex.owner); }
+#if defined(PEGASUS_OS_LINUX)
+ /**
+ This method must only be called after a fork() to reset the mutex
+ lock status in the new process. Any other use of this method is
+ unsafe.
+ */
+ void reinitialize();
+#endif
+
private:
inline void _set_owner(PEGASUS_THREAD_TYPE owner) { _mutex.owner = owner; }
PEGASUS_MUTEX_HANDLE _mutex;
static Mutex writeMutex;
+// Ensure that the static writeMutex is not locked across a fork().
+
+#if defined(PEGASUS_OS_LINUX)
+
+class ForkSafeWriteMutex
+{
+public:
+ ForkSafeWriteMutex()
+ {
+ pthread_atfork(
+ 0,
+ 0,
+ _reinitializeMutex);
+ }
+
+private:
+ static void _reinitializeMutex()
+ {
+ writeMutex.reinitialize();
+ }
+};
+
+static ForkSafeWriteMutex __forkSafeWriteMutex;
+
+#elif !defined(PEGASUS_OS_ZOS) && !defined(PEGASUS_OS_VMS)
+
+class ForkSafeWriteMutex
+{
+public:
+ ForkSafeWriteMutex()
+ {
+ pthread_atfork(
+ _lockMutex,
+ _unlockMutex,
+ _unlockMutex);
+ }
+
+private:
+ static void _lockMutex()
+ {
+ writeMutex.lock(pegasus_thread_self());
+ }
+
+ static void _unlockMutex()
+ {
+ writeMutex.unlock();
+ }
+};
+
+static ForkSafeWriteMutex __forkSafeWriteMutex;
+
+#endif
+
///////////////////////////////////////////////////////////////////////////////
// Writes message to file. Locks the file before writing to it
// Implementation of this function is platform specific