File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,12 @@ option(POCO_ENABLE_STD_MUTEX "Set to OFF|NO using mutex from standard library (d
247247if (POCO_ENABLE_STD_MUTEX)
248248 add_definitions (-DPOCO_ENABLE_STD_MUTEX)
249249endif ()
250+
251+ option (POCO_ENABLE_SIG_LOCK "Set to ON if signal handlers use code that lock mutexes to prevent deadlocks (default OFF)" OFF )
252+
253+ if (POCO_ENABLE_SIG_LOCK)
254+ add_definitions (-DPOCO_ENABLE_SIG_LOCK)
255+ endif ()
250256include (DefinePlatformSpecifc)
251257
252258# Collect the built libraries and include dirs, the will be used to create the PocoConfig.cmake file
Original file line number Diff line number Diff line change 2323#include < pthread.h>
2424#include < errno.h>
2525
26+ #ifdef POCO_ENABLE_SIG_LOCK
27+ #include < signal.h>
28+ #endif
29+
2630
2731namespace Poco {
2832
@@ -40,6 +44,7 @@ class Foundation_API MutexImpl
4044
4145private:
4246 pthread_mutex_t _mutex;
47+ sigset_t set, oldset;
4348};
4449
4550
@@ -56,6 +61,10 @@ class Foundation_API FastMutexImpl: public MutexImpl
5661//
5762inline void MutexImpl::lockImpl ()
5863{
64+ #ifdef POCO_ENABLE_SIG_LOCK
65+ sigfillset (&set);
66+ pthread_sigmask (SIG_BLOCK, &set, &oldset);
67+ #endif
5968 if (pthread_mutex_lock (&_mutex))
6069 throw SystemException (" cannot lock mutex" );
6170}
@@ -77,6 +86,10 @@ inline void MutexImpl::unlockImpl()
7786{
7887 if (pthread_mutex_unlock (&_mutex))
7988 throw SystemException (" cannot unlock mutex" );
89+
90+ #ifdef POCO_ENABLE_SIG_LOCK
91+ pthread_sigmask (SIG_SETMASK, &oldset, NULL );
92+ #endif
8093}
8194
8295
You can’t perform that action at this time.
0 commit comments