Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -108,10 +108,15 @@ } #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_HAVE_THREADS) static OFMutex *mutex; + +OF_DESTRUCTOR() +{ + [mutex release]; +} #endif #ifdef OF_WINDOWS static __time64_t (*func__mktime64)(struct tm *); #endif Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -107,13 +107,23 @@ # define S_ISLNK(mode) (mode & S_IFLNK) #endif #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) static OFMutex *passwdMutex; + +OF_DESTRUCTOR() +{ + [passwdMutex release]; +} #endif #if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) && !defined(OF_WINDOWS) static OFMutex *readdirMutex; + +OF_DESTRUCTOR() +{ + [readdirMutex release]; +} #endif #ifdef OF_WINDOWS static int (*func__wutime64)(const wchar_t *, struct __utimbuf64 *); static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD); Index: src/OFURLHandler.m ================================================================== --- src/OFURLHandler.m +++ src/OFURLHandler.m @@ -34,10 +34,15 @@ #endif static OFMutableDictionary OF_GENERIC(OFString *, OFURLHandler *) *handlers; #ifdef OF_HAVE_THREADS static OFMutex *mutex; + +OF_DESTRUCTOR() +{ + [mutex release]; +} #endif @implementation OFURLHandler @synthesize scheme = _scheme; Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -27,21 +27,20 @@ #endif #import "OFException.h" #import "OFArray.h" #import "OFLocale.h" +#ifdef OF_HAVE_THREADS +# import "OFMutex.h" +#endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" -#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) -# import "mutex.h" -#endif - #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # include #endif #if defined(OF_ARM) && !defined(__ARM_DWARF_EH__) @@ -69,16 +68,20 @@ extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int, void *); #endif #if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) -static of_mutex_t mutex; +static OFMutex *mutex; OF_CONSTRUCTOR() { - if (of_mutex_new(&mutex) != 0) - @throw [OFInitializationFailedException exception]; + mutex = [[OFMutex alloc] init]; +} + +OF_DESTRUCTOR() +{ + [mutex release]; } #endif OFString * of_strerror(int errNo) @@ -187,22 +190,19 @@ ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS - if (of_mutex_lock(&mutex) != 0) - @throw [OFLockFailedException exception]; - + [mutex lock]; @try { # endif ret = [OFString stringWithCString: strerror(errNo) encoding: [OFLocale encoding]]; # ifdef OF_HAVE_THREADS } @finally { - if (of_mutex_unlock(&mutex) != 0) - @throw [OFUnlockFailedException exception]; + [mutex unlock]; } # endif #endif return ret; Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -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