@@ -24,10 +24,13 @@ #include #import "OFArray.h" #import "OFCharacterSet.h" #import "OFLocale.h" +#ifdef OF_HAVE_THREADS +# import "OFMutex.h" +#endif #import "OFString.h" #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -36,15 +39,11 @@ #import "OFUnlockFailedException.h" #import "socket.h" #import "socket_helpers.h" #ifdef OF_HAVE_THREADS -# if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) -# import "mutex.h" -# else -# import "tlskey.h" -# endif +# import "tlskey.h" #endif #import "once.h" #ifdef OF_AMIGAOS # include @@ -54,11 +53,11 @@ # include <3ds/types.h> # include <3ds/services/soc.h> #endif #if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) -static of_mutex_t mutex; +static OFMutex *mutex; #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static bool initSuccessful = false; #endif @@ -123,12 +122,11 @@ atexit((void (*)(void))socExit); # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (of_mutex_new(&mutex) != 0) - return; + mutex = [[OFMutex alloc] init]; # ifdef OF_WII if (of_spinlock_new(&spinlock) != 0) return; # endif @@ -135,22 +133,24 @@ # endif initSuccessful = true; } -# ifdef OF_AMIGAOS OF_DESTRUCTOR() { +# ifdef OF_AMIGAOS # ifdef OF_AMIGAOS4 if (ISocket != NULL) DropInterface((struct Interface *)ISocket); # endif if (SocketBase != NULL) CloseLibrary(SocketBase); -} # endif + + [mutex release]; +} #endif bool of_socket_init(void) { @@ -327,20 +327,15 @@ socklen_t *restrict addrLen) { int ret; # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (of_mutex_lock(&mutex) != 0) - @throw [OFLockFailedException exception]; - + [mutex lock]; # endif - ret = getsockname(sock, addr, addrLen); - # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (of_mutex_unlock(&mutex) != 0) - @throw [OFUnlockFailedException exception]; + [mutex unlock]; # endif return ret; } #endif