@@ -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))