ObjFW  Check-in [5918fe8ab2]

Overview
Comment:OFLocking: Add property for lock name.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5918fe8ab2fc71403980eed721b33b252d215f6f4e00f34f9559b26b5c045a1c
User & Date: js on 2012-12-05 12:22:19
Other Links: manifest | tags
Context
2012-12-05
21:28
OFMapTable: Reseed on resize. check-in: f7018aedf9 user: js tags: trunk
12:22
OFLocking: Add property for lock name. check-in: 5918fe8ab2 user: js tags: trunk
2012-12-04
09:59
Add a per-hashtable seed. check-in: 590fa6ed79 user: js tags: trunk
Changes

Modified src/OFLocking.h from [5f7cf70e41] to [24ff162053].

16
17
18
19
20
21
22




23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38














39

#import "OFObject.h"

/*!
 * @brief A protocol for locks.
 */
@protocol OFLocking <OFObject>




/*!
 * @brief Locks the lock.
 */
- (void)lock;

/*!
 * @brief Tries to lock the lock.
 *
 * @return A boolean whether the lock could be locked
 */
- (BOOL)tryLock;

/*!
 * @brief Unlocks the lock.
 */
- (void)unlock;














@end







>
>
>
>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>

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

#import "OFObject.h"

/*!
 * @brief A protocol for locks.
 */
@protocol OFLocking <OFObject>
#ifdef OF_HAVE_PROPERTIES
@property (copy) OFString *name;
#endif

/*!
 * @brief Locks the lock.
 */
- (void)lock;

/*!
 * @brief Tries to lock the lock.
 *
 * @return A boolean whether the lock could be locked
 */
- (BOOL)tryLock;

/*!
 * @brief Unlocks the lock.
 */
- (void)unlock;

/*!
 * @brief Sets a name for the lock.
 *
 * @param name The name for the lock
 */
- (void)setName: (OFString*)name;

/*!
 * @brief Returns the name for the lock.
 *
 * @return The name for the lock
 */
- (OFString*)name;
@end

Modified src/OFMutex.h from [9e5b4524e5] to [b170db2ce9].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
/*!
 * @brief A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject <OFLocking>
{
	of_mutex_t mutex;
	BOOL initialized;

}

/*!
 * @brief Creates a new mutex.
 *
 * @return A new autoreleased mutex.
 */







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*!
 * @brief A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject <OFLocking>
{
	of_mutex_t mutex;
	BOOL initialized;
	OFString *name;
}

/*!
 * @brief Creates a new mutex.
 *
 * @return A new autoreleased mutex.
 */

Modified src/OFMutex.m from [e9519677f8] to [0fa68d097c].

13
14
15
16
17
18
19

20
21
22
23
24


25
26
27
28
29
30
31
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFMutex.h"


#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
#import "OFUnlockFailedException.h"



@implementation OFMutex
+ (instancetype)mutex
{
	return [[[self alloc] init] autorelease];
}








>





>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFMutex.h"
#import "OFString.h"

#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
#import "OFUnlockFailedException.h"

#import "macros.h"

@implementation OFMutex
+ (instancetype)mutex
{
	return [[[self alloc] init] autorelease];
}

58
59
60
61
62
63
64


















65
66
67
68
69
70
71
72


73
74
75
76

- (void)unlock
{
	if (!of_mutex_unlock(&mutex))
		@throw [OFUnlockFailedException exceptionWithClass: [self class]
							      lock: self];
}



















- (void)dealloc
{
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFStillLockedException
			    exceptionWithClass: [self class]
					  lock: self];



	[super dealloc];
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>




61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

- (void)unlock
{
	if (!of_mutex_unlock(&mutex))
		@throw [OFUnlockFailedException exceptionWithClass: [self class]
							      lock: self];
}

- (void)setName: (OFString*)name_
{
	OF_SETTER(name, name_, YES, YES)
}

- (OFString*)name
{
	OF_GETTER(name, YES)
}

- (OFString*)description
{
	if (name == nil)
		return [super description];

	return [OFString stringWithFormat: @"<%@: %@>", [self className], name];
}

- (void)dealloc
{
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFStillLockedException
			    exceptionWithClass: [self class]
					  lock: self];

	[name release];

	[super dealloc];
}
@end

Modified src/OFRecursiveMutex.h from [6d98d1fbf7] to [6f9a6cfc49].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
 * @brief A class for creating mutual exclusions which can be entered
 *	  recursively.
 */
@interface OFRecursiveMutex: OFObject <OFLocking>
{
	of_rmutex_t rmutex;
	BOOL initialized;

}

/*!
 * @brief Creates a new recursive mutex.
 *
 * @return A new autoreleased recursive mutex.
 */







>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 * @brief A class for creating mutual exclusions which can be entered
 *	  recursively.
 */
@interface OFRecursiveMutex: OFObject <OFLocking>
{
	of_rmutex_t rmutex;
	BOOL initialized;
	OFString *name;
}

/*!
 * @brief Creates a new recursive mutex.
 *
 * @return A new autoreleased recursive mutex.
 */

Modified src/OFRecursiveMutex.m from [2706783ddc] to [fe2de7b87a].

13
14
15
16
17
18
19

20
21
22
23
24


25
26
27
28
29
30
31
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFRecursiveMutex.h"


#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
#import "OFUnlockFailedException.h"



@implementation OFRecursiveMutex
+ (instancetype)mutex
{
	return [[[self alloc] init] autorelease];
}








>





>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFRecursiveMutex.h"
#import "OFString.h"

#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
#import "OFUnlockFailedException.h"

#import "macros.h"

@implementation OFRecursiveMutex
+ (instancetype)mutex
{
	return [[[self alloc] init] autorelease];
}

58
59
60
61
62
63
64


















65
66
67
68
69
70
71
72


73
74
75
76

- (void)unlock
{
	if (!of_rmutex_unlock(&rmutex))
		@throw [OFUnlockFailedException exceptionWithClass: [self class]
							      lock: self];
}



















- (void)dealloc
{
	if (initialized)
		if (!of_rmutex_free(&rmutex))
			@throw [OFStillLockedException
			    exceptionWithClass: [self class]
					  lock: self];



	[super dealloc];
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>




61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

- (void)unlock
{
	if (!of_rmutex_unlock(&rmutex))
		@throw [OFUnlockFailedException exceptionWithClass: [self class]
							      lock: self];
}

- (void)setName: (OFString*)name_
{
	OF_SETTER(name, name_, YES, YES)
}

- (OFString*)name
{
	OF_GETTER(name, YES)
}

- (OFString*)description
{
	if (name == nil)
		return [super description];

	return [OFString stringWithFormat: @"<%@: %@>", [self className], name];
}

- (void)dealloc
{
	if (initialized)
		if (!of_rmutex_free(&rmutex))
			@throw [OFStillLockedException
			    exceptionWithClass: [self class]
					  lock: self];

	[name release];

	[super dealloc];
}
@end