aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vmime/platforms/posix/posixHandler.cpp53
1 files changed, 9 insertions, 44 deletions
diff --git a/src/vmime/platforms/posix/posixHandler.cpp b/src/vmime/platforms/posix/posixHandler.cpp
index 20c0f342..f8861315 100644
--- a/src/vmime/platforms/posix/posixHandler.cpp
+++ b/src/vmime/platforms/posix/posixHandler.cpp
@@ -55,9 +55,6 @@
#include <cassert>
#include <cstdlib>
-#if VMIME_HAVE_PTHREAD
-# include <pthread.h>
-#endif // VMIME_HAVE_PTHREAD
/*
#ifdef _POSIX_PRIORITY_SCHEDULING
@@ -66,45 +63,6 @@
*/
-#if VMIME_HAVE_PTHREAD
-
-namespace {
-
- // This construction ensures mutex will be initialized in compile-time
- // and will be available any time in the runtime.
- pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
-
- // Helper lock, to be exception safe all the time.
- class PLockHelper {
-
- public:
-
- PLockHelper() {
-
- if (pthread_mutex_lock(&g_mutex) != 0) {
- assert(!"unable to lock mutex - thread safety's void");
- }
- }
-
- ~PLockHelper() {
-
- if (pthread_mutex_unlock(&g_mutex) != 0) {
- assert(!"unable to unlock mutex - application's dead...");
- }
- }
-
- private:
-
- // Object cannot be copied
- PLockHelper(const PLockHelper&);
- const PLockHelper& operator=(const PLockHelper&);
- };
-
-} // unnamed namespace
-
-#endif // VMIME_HAVE_PTHREAD
-
-
namespace vmime {
namespace platforms {
namespace posix {
@@ -173,9 +131,16 @@ const vmime::datetime posixHandler::getCurrentLocalTime() const {
const vmime::charset posixHandler::getLocalCharset() const {
- const PLockHelper lock;
+ // Note: nl_langinfo() might be affected by calls to setlocale()
+ // in a multithread environment. There is not MT-safe alternative
+ // to nl_langinfo().
+ auto codeset = ::nl_langinfo(CODESET);
+
+ if (codeset) {
+ return vmime::charset(codeset);
+ }
- return vmime::charset(::nl_langinfo(CODESET));
+ return vmime::charset();
}