First -- it needs to use timeIntervalSince1970 to be using the same reference date required for pthread_cond_timedwait
Second -- lockWhenCondition needs to loop because pthread_cond_timedwait can return prior to delay expiring (but with the wrong condition).
Third -- Internally the lock was incorrectly being unlocked on a delayed acquire (and YES return). And was incorrectly being unlocked a second time when the timeout expired.
Also, fixed a problem with tryLockWhenCondition:
By calling lockWhenCondition: it would incorrectly report a deadlock (rather than just return no) when we already have the lock.
All these changes are in line with expected and documented behavior for NSLock.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29472 72102866-910b-0410-8b05-ffd578937521
* Headers/Foundation/NSLock.h
Completely rewritten implementations of NSLock.h classes. These are now
faster, more complete, OS X-compatible, and most importantly actually
work. The old ones, for example, called functions that were not
implemented on Windows.
* Source/NSThread.m
Call pthread functions directly in NSThread instead of via the libobjc
abstraction layer. Also fixed a few issues, such as GC not being
initialized properly for NSThread subclasses that override -main (Javaism
supported by OS X) and tidies up the code in several places, removing
premature optimizations, especially those that introduce a test for an
unlikely case at the start of a method and thus slow everything down.
As a result of this change, GNUstep now depends on an implementation of
POSIX threads. This is included as standard on all modern UNIX systems,
and as an option on less-modern UNIX systems and non-UNIX systems,
including Windows. If you are building GNUstep on Windows, please install
the pthreads-win32 package, available from:
http://sourceware.org/pthreads-win32/
PLEASE TEST THIS! There may be some code that depended on the old
behaviour. I have been running the new NSLock implementation on FreeBSD
for a few weeks without issue; please report to me any problems that you
have on your platform.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28598 72102866-910b-0410-8b05-ffd578937521
inconsistency between Cocoa (and OpenStep) and GNUstep.
Reinstatement of correction for bug #25307. Testing on both OpenStep
and on Cocoa clearly illustrates that throwing an exception in this
case was incorrect. It now emits a warning when the lock is attempted
again, but does not throw an exception.
* Testing/locktest/locktest.m: Change to test to correctly test
[NSConditionLock lock]
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27726 72102866-910b-0410-8b05-ffd578937521
documentation, NSConditionLock should return NO, if the lock is
unavailable. No exception should be thrown.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27612 72102866-910b-0410-8b05-ffd578937521
_condition opaic to avoid including private thr-mach.h header.
* Headers/Foundation/NSThread.h: Do not include private
thr-mach.h header.
* Source/thr-mach.h: Moved here from
Headers/Additions/GNUstepBase/thr-mach.h.
* Source/NSLock.m: Include private thr-mach.h header for
apple-gnu-gnu. Added defines for typing opaic instance
variables and use them in various methods.
* Source/NSThread.m: Include private thr-mach.h header for
apple-gnu-gnu.
* Source/thr-mach.m: Include private thr-mach.h header from
new location.
* Source/thr-pthread.m: Ditto.
* Source/GNUmakefile: Do not install private thr-mach.h
header.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18607 72102866-910b-0410-8b05-ffd578937521
forward declaration.
* Headers/Additions/GNUstepBase/GSCategories.h: Remove
declaraion of gnustep_global_lock.
(GS_INITIALIZED_LOCK): New macro.
(+[NSLock newLockAt:]): New method.
(+[NSRecursiveLock newLockAt:]): Ditto.
* Headers/Foundation/NSLock.h: Ditto.
* Source/Additions/GSCategories.m: Replace global lock with
local lock.
(_GSLockInitializer): New class to initialize local lock
safely.
(newLockAt): New static function shared by +newLockAt:
implementations to safely intialize lock variables.
(+[NSLock newLockAt:]): Implemented and documented.
(+[NSRecursiveLock newLockAt:]): Ditto.
* Source/Additions/GSCompatibility.m: Remove
gnustep_global_lock.
* Source/Additions/GSObjCRuntime.m: Remove superfluous
locking.
* Source/Additions/Unicode.m: Use new GS_INITIALIZED_LOCK
macro and replace global lock with local lock.
* Source/NSLock.m
(-[NSConditionLock lockWhenCondition:beforeDate:]):
Implemented.
* Testing/gslock.m: New test case.
* Testing/GNUmakefile: Add new test case.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18010 72102866-910b-0410-8b05-ffd578937521