diff options
Diffstat (limited to 'src/boost/libs/log/config/pthread-mutex-robust')
-rw-r--r-- | src/boost/libs/log/config/pthread-mutex-robust/Jamfile.jam | 19 | ||||
-rw-r--r-- | src/boost/libs/log/config/pthread-mutex-robust/pthread_mutex_robust.cpp | 37 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/boost/libs/log/config/pthread-mutex-robust/Jamfile.jam b/src/boost/libs/log/config/pthread-mutex-robust/Jamfile.jam new file mode 100644 index 00000000..6082e66e --- /dev/null +++ b/src/boost/libs/log/config/pthread-mutex-robust/Jamfile.jam @@ -0,0 +1,19 @@ +# +# Copyright Andrey Semashev 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# + +import project ; +import log-platform-config ; + +project /boost/log/pthread-mutex-robust + : source-location . + : requirements + <conditional>@log-platform-config.set-platform-defines + + <pch>off + ; + +obj pthread_mutex_robust : pthread_mutex_robust.cpp ; diff --git a/src/boost/libs/log/config/pthread-mutex-robust/pthread_mutex_robust.cpp b/src/boost/libs/log/config/pthread-mutex-robust/pthread_mutex_robust.cpp new file mode 100644 index 00000000..36415aca --- /dev/null +++ b/src/boost/libs/log/config/pthread-mutex-robust/pthread_mutex_robust.cpp @@ -0,0 +1,37 @@ +/* + * Copyright Andrey Semashev 2015. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#include <errno.h> +#include <pthread.h> + +int main(int, char*[]) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); + + pthread_mutex_t m; + pthread_mutex_init(&m, &attr); + pthread_mutexattr_destroy(&attr); + + int err = pthread_mutex_lock(&m); + if (err == EOWNERDEAD) + { + err = pthread_mutex_consistent(&m); + } + + if (err != ENOTRECOVERABLE) + { + pthread_mutex_unlock(&m); + } + + pthread_mutex_destroy(&m); + + return 0; +} |