Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -5,13 +5,10 @@ SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} -# OFThread needs to be before OFFile, as OFFile requires OFMutex in +[load]. -# Some new ld versions are very picky about this, while it always worked with -# older versions. SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFConstantString.m \ @@ -21,11 +18,10 @@ OFDate.m \ OFDictionary.m \ OFDoubleMatrix.m \ OFDoubleVector.m \ OFEnumerator.m \ - ${OFTHREAD_M} \ OFFile.m \ OFFloatMatrix.m \ OFFloatVector.m \ OFHash.m \ OFHTTPRequest.m \ @@ -53,10 +49,11 @@ OFString+Serialization.m \ OFString+URLEncoding.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ OFTCPSocket.m \ + ${OFTHREAD_M} \ OFURL.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -37,11 +37,11 @@ #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #ifdef OF_THREADS -# import "OFThread.h" +# import "threading.h" #endif #import "OFDate.h" #import "OFApplication.h" #import "OFAutoreleasePool.h" @@ -49,12 +49,15 @@ #import "OFChangeFileModeFailedException.h" #import "OFChangeFileOwnerFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFDeleteDirectoryFailedException.h" #import "OFDeleteFileFailedException.h" +#import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" +#import "OFMutexLockFailedException.h" +#import "OFMutexUnlockFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFReadFailedException.h" #import "OFRenameFileFailedException.h" @@ -91,11 +94,11 @@ OFStream *of_stdin = nil; OFStream *of_stdout = nil; OFStream *of_stderr = nil; #if defined(OF_THREADS) && !defined(_WIN32) -static OFMutex *mutex; +static of_mutex_t mutex; #endif static int parse_mode(const char *mode) { if (!strcmp(mode, "r")) @@ -161,12 +164,16 @@ } #if defined(OF_THREADS) && !defined(_WIN32) + (void)initialize { - if (self == [OFFile class]) - mutex = [[OFMutex alloc] init]; + if (self != [OFFile class]) + return; + + if (!of_mutex_new(&mutex)) + @throw [OFInitializationFailedException + exceptionWithClass: self]; } #endif + fileWithPath: (OFString*)path mode: (OFString*)mode @@ -387,11 +394,13 @@ if (owner == nil && group == nil) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; # ifdef OF_THREADS - [mutex lock]; + if (!of_mutex_lock(&mutex)) + @throw [OFMutexLockFailedException exceptionWithClass: self + mutex: nil]; @try { # endif if (owner != nil) { struct passwd *passwd; @@ -420,11 +429,14 @@ gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { - [mutex unlock]; + if (!of_mutex_unlock(&mutex)) + @throw [OFMutexUnlockFailedException + exceptionWithClass: self + mutex: nil]; } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid))