summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorArnaud Versini <arnaud.versini@gmail.com>2012-07-22 16:04:06 +0200
committerMichael Meeks <michael.meeks@suse.com>2012-07-23 15:36:37 +0100
commitba47dd6f03cfea17ae1117598bed8fe4e7d18a51 (patch)
tree535e20bd4f31051e0982d1ac87162561e50f454a /sal
parent17ddd27bf543eadebe3d950b5184ffce48bd5014 (diff)
Don't use a mutex for gethostbyname_r on Mac OS X
Change-Id: I5b8c7901266ae73d95626e98116b9a3b43710642
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/system.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/sal/osl/unx/system.c b/sal/osl/unx/system.c
index 720d1cd98a49..1eaeb1865dbd 100644
--- a/sal/osl/unx/system.c
+++ b/sal/osl/unx/system.c
@@ -30,11 +30,26 @@
#ifdef NO_PTHREAD_RTL
-static pthread_mutex_t getrtl_mutex = PTHREAD_MUTEX_INITIALIZER;
-
/* struct passwd differs on some platforms */
+
#if defined(MACOSX) || defined(IOS) || defined(OPENBSD) || defined(NETBSD)
+//No mutex needed on Mac OS X, gethostbyname is thread safe
+
+#if defined(MACOSX)
+
+#define RTL_MUTEX_LOCK
+#define RTL_MUTEX_UNLOCK
+
+#else //defined(MACOSX)
+
+static pthread_mutex_t getrtl_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+#define RTL_MUTEX_LOCK pthread_mutex_lock(&getrtl_mutex);
+#define RTL_MUTEX_UNLOCK pthread_mutex_unlock(&getrtl_mutex);
+
+#endif //defined(MACOSX)
+
extern int h_errno;
struct hostent *gethostbyname_r(const char *name, struct hostent *result,
@@ -50,7 +65,7 @@ struct hostent *gethostbyname_r(const char *name, struct hostent *result,
*/
struct hostent* res;
- pthread_mutex_lock(&getrtl_mutex);
+ RTL_MUTEX_LOCK
if ( (res = gethostbyname(name)) )
{
@@ -120,9 +135,9 @@ struct hostent *gethostbyname_r(const char *name, struct hostent *result,
*h_errnop = h_errno;
}
- pthread_mutex_unlock(&getrtl_mutex);
+ RTL_MUTEX_UNLOCK
- return res;
+ return res;
}
#endif // OSX || IOS || OPENBSD || NETBSD