ObjFW  Diff

Differences From Artifact [99a3d0e9e5]:

To Artifact [2faea18a32]:


12
13
14
15
16
17
18


19
20
21
22
23
24
25
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * 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"







>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>

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

#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFStillLockedException.h"
46
47
48
49
50
51
52
53
54


55


56
57
58
59
60
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
	_initialized = true;

	return self;
}

- (void)dealloc
{
	if (_initialized)
		if (!of_mutex_free(&_mutex))


			@throw [OFStillLockedException exceptionWithLock: self];



	[_name release];

	[super dealloc];
}

- (void)lock
{
	if (!of_mutex_lock(&_mutex))
		@throw [OFLockFailedException exceptionWithLock: self];

}

- (bool)tryLock
{
	return of_mutex_trylock(&_mutex);








}

- (void)unlock
{
	if (!of_mutex_unlock(&_mutex))
		@throw [OFUnlockFailedException exceptionWithLock: self];

}

- (OFString *)description
{
	if (_name == nil)
		return super.description;

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







|
|
>
>

>
>









|
>




|
>
>
>
>
>
>
>
>





|
>










48
49
50
51
52
53
54
55
56
57
58
59
60
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
100
101
102
	_initialized = true;

	return self;
}

- (void)dealloc
{
	if (_initialized) {
		if (!of_mutex_free(&_mutex)) {
			OF_ENSURE(errno == EBUSY);

			@throw [OFStillLockedException exceptionWithLock: self];
		}
	}

	[_name release];

	[super dealloc];
}

- (void)lock
{
	if (!of_mutex_lock(&_mutex))
		@throw [OFLockFailedException exceptionWithLock: self
							  errNo: errno];
}

- (bool)tryLock
{
	if (!of_mutex_trylock(&_mutex)) {
		if (errno == EBUSY)
			return false;
		else
			@throw [OFLockFailedException exceptionWithLock: self
								  errNo: errno];
	}

	return true;
}

- (void)unlock
{
	if (!of_mutex_unlock(&_mutex))
		@throw [OFUnlockFailedException exceptionWithLock: self
							    errNo: errno];
}

- (OFString *)description
{
	if (_name == nil)
		return super.description;

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