Overview
| Comment: | Add -[tryLock] to OFMutex. |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
20e1c0e24b1d882c161ccbb309a76166 |
| User & Date: | js on 2010-01-30 00:50:46 |
| Other Links: | manifest | tags |
Context
|
2010-01-30
| ||
| 01:17 | Change spinlock implementation, add fallbacks and move to threading.h. (check-in: 921b158d17 user: js tags: trunk) | |
| 00:50 | Add -[tryLock] to OFMutex. (check-in: 20e1c0e24b user: js tags: trunk) | |
| 00:45 |
Define OF_ATOMIC_OPS if we don't have threads. Without threads, we just don't care about atomicity. (check-in: 1823d543f3 user: js tags: trunk) | |
Changes
Modified src/OFThread.h from [469fa957dd] to [24a798f944].
| ︙ | ︙ | |||
131 132 133 134 135 136 137 138 139 140 141 142 | + mutex; /** * Locks the mutex. */ - lock; /** * Unlocks the mutex. */ - unlock; @end | > > > > > > > > | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | + mutex; /** * Locks the mutex. */ - lock; /** * Tries to lock the mutex and returns a boolean whether the mutex could be * acquired. * * \return A boolean whether the mutex could be acquired */ - (BOOL)tryLock; /** * Unlocks the mutex. */ - unlock; @end |
Modified src/OFThread.m from [0701aeb932] to [acb2745598].
| ︙ | ︙ | |||
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
- lock
{
if (!of_mutex_lock(&mutex))
@throw [OFMutexLockFailedException newWithClass: isa];
return self;
}
- unlock
{
if (!of_mutex_unlock(&mutex))
@throw [OFMutexUnlockFailedException newWithClass: isa];
return self;
| > > > > > | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
- lock
{
if (!of_mutex_lock(&mutex))
@throw [OFMutexLockFailedException newWithClass: isa];
return self;
}
- (BOOL)tryLock
{
return of_mutex_trylock(&mutex);
}
- unlock
{
if (!of_mutex_unlock(&mutex))
@throw [OFMutexUnlockFailedException newWithClass: isa];
return self;
|
| ︙ | ︙ |
Modified src/threading.h from [d9ecd3df92] to [118d170b8a].
| ︙ | ︙ | |||
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
#if defined(OF_HAVE_PTHREADS)
return (pthread_mutex_lock(mutex) ? NO : YES);
#elif defined(_WIN32)
EnterCriticalSection(mutex);
return YES;
#endif
}
static OF_INLINE BOOL
of_mutex_unlock(of_mutex_t *mutex)
{
#if defined(OF_HAVE_PTHREADS)
return (pthread_mutex_unlock(mutex) ? NO : YES);
#elif defined(_WIN32)
| > > > > > > > > > > | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#if defined(OF_HAVE_PTHREADS)
return (pthread_mutex_lock(mutex) ? NO : YES);
#elif defined(_WIN32)
EnterCriticalSection(mutex);
return YES;
#endif
}
static OF_INLINE BOOL
of_mutex_trylock(of_mutex_t *mutex)
{
#if defined(OF_HAVE_PTHREADS)
return (pthread_mutex_trylock(mutex) ? NO : YES);
#elif defined(_WIN32)
return (TryEnterCriticalSection(mutex) ? YES : NO);
#endif
}
static OF_INLINE BOOL
of_mutex_unlock(of_mutex_t *mutex)
{
#if defined(OF_HAVE_PTHREADS)
return (pthread_mutex_unlock(mutex) ? NO : YES);
#elif defined(_WIN32)
|
| ︙ | ︙ |