Thread safety

This commit is contained in:
llsth 2015-08-15 19:34:32 +02:00
parent 0b071caa89
commit 24fdc7958e
4 changed files with 13 additions and 18 deletions

View File

@ -368,6 +368,8 @@ int main( int argc, char **argv )
int tos = 0;
HOST_ENTRY *cursor;
prog = argv[0];
open_libs();
s = open_ping_socket();
@ -376,7 +378,6 @@ int main( int argc, char **argv )
setuid( getuid() );
}
prog = argv[0];
ident = getpid() & 0xFFFF;
verbose_flag = 1;
backoff_flag = 1;

View File

@ -17,6 +17,8 @@
#include "config.h"
const char *vers = "\0$VER: " PACKAGE_NAME " " PACKAGE_VERSION " (15.08.2015)";
#include "inet_getaddrinfo.h"
#include <unistd.h>
#ifdef AOS3
uid_t getuid () {
@ -59,6 +61,7 @@ void close_libs()
int open_libs()
{
atexit(close_libs);
InitSemaphore(&GetaddrinfoSemaphore);
if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) {
amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV);

View File

@ -133,9 +133,7 @@ static struct addrinfo default_hints = {
/*
* Mutex.
*/
#ifdef ENABLE_PTHREAD
static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
struct SignalSemaphore GetaddrinfoSemaphore;
/*
* Declaration of static functions.
@ -276,10 +274,7 @@ struct addrinfo **res;
int saved_h_errno;
int result = 0;
#ifdef ENABLE_PTHREAD
pthread_mutex_lock(&gai_mutex);
#endif
ObtainSemaphore(&GetaddrinfoSemaphore);
saved_h_errno = h_errno;
if (nodename == NULL && servname == NULL) {
@ -434,9 +429,7 @@ struct addrinfo **res;
end:
h_errno = saved_h_errno;
#ifdef ENABLE_PTHREAD
pthread_mutex_unlock(&gai_mutex);
#endif
ReleaseSemaphore(&GetaddrinfoSemaphore);
return result;
}
@ -449,10 +442,7 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_
int saved_h_errno;
int result = 0;
#ifdef ENABLE_PTHREAD
pthread_mutex_lock(&gai_mutex);
#endif
ObtainSemaphore(&GetaddrinfoSemaphore);
saved_h_errno = h_errno;
if (sa_in->sin_family != PF_INET) {
@ -516,8 +506,6 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_
end:
h_errno = saved_h_errno;
#ifdef ENABLE_PTHREAD
pthread_mutex_unlock(&gai_mutex);
#endif
ReleaseSemaphore(&GetaddrinfoSemaphore);
return result;
}

View File

@ -194,6 +194,9 @@
typedef u_int16_t in_port_t;
typedef unsigned int sa_family_t;
#include <exec/types.h>
extern struct SignalSemaphore GetaddrinfoSemaphore;
const char* gai_strerror(int);
void freeaddrinfo(struct addrinfo *);
int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);