File: RecursiveLock.m

package info (click to toggle)
gnustep-base 1.24.9-3.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,844 kB
  • sloc: objc: 975,047; ansic: 31,533; makefile: 135; cpp: 122; sh: 102; xml: 32
file content (61 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import <Foundation/Foundation.h>
#import "Testing.h"

int main()
{
  NSAutoreleasePool   *arp = [NSAutoreleasePool new];
  BOOL ret;
  NSLock *lock = [NSRecursiveLock new];

  ret = [lock tryLock];
  if (ret)
    [lock unlock];
  PASS(ret, "NSRecursiveLock with tryLock, then unlocking");
  
  ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
  if (ret)
    [lock unlock];
  PASS(ret, "NSRecursiveLock lockBeforeDate: works");
  
  ret = [lock tryLock];
  if (ret)
    {
      ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
      if (ret)
        {
          [lock unlock];
        }
      [lock unlock];
    }
  PASS(ret, "NSRecursiveLock lockBeforeDate: with NSRecursiveLock returns YES");

#if     defined(GNUSTEP_BASE_LIBRARY)
  START_SET("mutex ownership extension")
#if     defined(_WIN32)
  SKIP("mutex ownership feature not available on windows")
#endif
  NS_DURING
    {
      testHopeful = YES;
      PASS([lock isLockedByCurrentThread] == NO,
        "NSRecursiveLock isLockedByCurrentThread returns NO when not locked");
      [lock lock];
      PASS([lock isLockedByCurrentThread] == YES,
        "NSRecursiveLock isLockedByCurrentThread returns YES when locked");
      [lock unlock];
      PASS([lock isLockedByCurrentThread] == NO,
        "NSRecursiveLock isLockedByCurrentThread returns NO when unlocked");
      testHopeful = NO;
    }
  NS_HANDLER
    {
      NSLog(@"-isLockedByCurrentThread not supported");
    }
  NS_ENDHANDLER
  END_SET("mutex ownership extension")
#endif

  [arp release]; arp = nil;
  return 0;
}