Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ option(POCO_ENABLE_STD_MUTEX "Set to OFF|NO using mutex from standard library (d
if (POCO_ENABLE_STD_MUTEX)
add_definitions(-DPOCO_ENABLE_STD_MUTEX)
endif ()

option(POCO_ENABLE_SIG_LOCK "Set to ON if signal handlers use code that lock mutexes to prevent deadlocks (default OFF)" OFF)

if (POCO_ENABLE_SIG_LOCK)
add_definitions(-DPOCO_ENABLE_SIG_LOCK)
endif ()
include(DefinePlatformSpecifc)

# Collect the built libraries and include dirs, the will be used to create the PocoConfig.cmake file
Expand Down
13 changes: 13 additions & 0 deletions Foundation/include/Poco/Mutex_POSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <pthread.h>
#include <errno.h>

#ifdef POCO_ENABLE_SIG_LOCK
#include <signal.h>
#endif


namespace Poco {

Expand All @@ -40,6 +44,7 @@ class Foundation_API MutexImpl

private:
pthread_mutex_t _mutex;
sigset_t set, oldset;
};


Expand All @@ -56,6 +61,10 @@ class Foundation_API FastMutexImpl: public MutexImpl
//
inline void MutexImpl::lockImpl()
{
#ifdef POCO_ENABLE_SIG_LOCK
sigfillset(&set);
pthread_sigmask(SIG_BLOCK, &set, &oldset);
#endif
if (pthread_mutex_lock(&_mutex))
throw SystemException("cannot lock mutex");
}
Expand All @@ -77,6 +86,10 @@ inline void MutexImpl::unlockImpl()
{
if (pthread_mutex_unlock(&_mutex))
throw SystemException("cannot unlock mutex");

#ifdef POCO_ENABLE_SIG_LOCK
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
#endif
}


Expand Down
Loading