diff options
Diffstat (limited to 'sal/osl/unx/system.c')
-rw-r--r-- | sal/osl/unx/system.c | 25 |
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 |