Overview
Comment: | Add class OFCondition. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
615eb3e46b172393d32c2fc03bfbf168 |
User & Date: | js on 2011-03-07 16:00:39 |
Other Links: | manifest | tags |
Context
2011-03-07
| ||
16:03 | Add tests for OFHTTPRequest. check-in: 3c4ae255a2 user: js tags: trunk | |
16:00 | Add class OFCondition. check-in: 615eb3e46b user: js tags: trunk | |
15:39 | Add abstraction for conditions. check-in: f771ddda2d user: js tags: trunk | |
Changes
Modified src/OFExceptions.h from [40dbf508af] to [a9f1cf1d10].
︙ | ︙ | |||
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 | /** * \brief An exception indicating that a mutex is still locked. */ @interface OFMutexLockedException: OFException @end /** * \brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException @end /** | > > > > > > > > > > > > > > > > > > > > > > > > > | 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | /** * \brief An exception indicating that a mutex is still locked. */ @interface OFMutexLockedException: OFException @end /** * \brief An exception indicating waiting for a condition failed. */ @interface OFConditionWaitFailedException: OFException @end /** * \brief An exception indicating signalling a condition failed. */ @interface OFConditionSignalFailedException: OFException @end /** * \brief An exception indicating broadcasting a condition failed. */ @interface OFConditionBroadcastFailedException: OFException @end /** * \brief An exception indicating that a thread is still waiting for a * condition. */ @interface OFConditionWaitingException: OFException @end /** * \brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException @end /** |
︙ | ︙ |
Modified src/OFExceptions.m from [4e6767989a] to [cd4f398255].
︙ | ︙ | |||
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 | if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Deallocation of a mutex of type %@ was tried, even though it " @"was still locked!", inClass]; return description; } @end @implementation OFHashAlreadyCalculatedException - (OFString*)description { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Deallocation of a mutex of type %@ was tried, even though it " @"was still locked!", inClass]; return description; } @end @implementation OFConditionWaitFailedException - (OFString*)description { if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Waiting for a condition of type %@ failed!", inClass]; return description; } @end @implementation OFConditionSignalFailedException - (OFString*)description { if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Signaling a condition of type %@ failed!", inClass]; return description; } @end @implementation OFConditionBroadcastFailedException - (OFString*)description { if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Broadcasting a condition of type %@ failed!", inClass]; return description; } @end @implementation OFConditionWaitingException - (OFString*)description { if (description != nil) return description; description = [[OFString alloc] initWithFormat: @"Deallocation of a condition of type %@ was tried, even though a " @"thread was still waiting for it!", inClass]; return description; } @end @implementation OFHashAlreadyCalculatedException - (OFString*)description { |
︙ | ︙ |
Modified src/OFThread.h from [365e7ac8cd] to [b9567d8482].
︙ | ︙ | |||
219 220 221 222 223 224 225 | - (BOOL)tryLock; /** * Unlocks the mutex. */ - (void)unlock; @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | - (BOOL)tryLock; /** * Unlocks the mutex. */ - (void)unlock; @end /** * \brief A class implementing a condition variable for thread synchronization. */ @interface OFCondition: OFMutex { of_condition_t condition; BOOL cond_initialized; } /** * \return A new, autoreleased OFCondition */ + condition; /** * Blocks the current thread until another thread calls -[signal] or * -[broadcast]. */ - (void)wait; /** * Signals the next waiting thread to continue. */ - (void)signal; /** * Signals all threads to continue. */ - (void)broadcast; @end |
Modified src/OFThread.m from [e256511cbe] to [e6a6c3857f].
︙ | ︙ | |||
368 369 370 371 372 373 374 375 376 377 | - (void)dealloc { if (initialized) if (!of_mutex_free(&mutex)) @throw [OFMutexLockedException newWithClass: isa]; [super dealloc]; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | - (void)dealloc { if (initialized) if (!of_mutex_free(&mutex)) @throw [OFMutexLockedException newWithClass: isa]; [super dealloc]; } @end @implementation OFCondition + condition { return [[[self alloc] init] autorelease]; } - init { self = [super init]; if (!of_condition_new(&condition)) { Class c = isa; [self release]; @throw [OFInitializationFailedException newWithClass: c]; } cond_initialized = YES; return self; } - (void)wait { if (!of_condition_wait(&condition, &mutex)) @throw [OFConditionWaitFailedException newWithClass: isa]; } - (void)signal { if (!of_condition_signal(&condition)) @throw [OFConditionSignalFailedException newWithClass: isa]; } - (void)broadcast { if (!of_condition_broadcast(&condition)) @throw [OFConditionBroadcastFailedException newWithClass: isa]; } - (void)dealloc { if (cond_initialized) if (!of_condition_free(&condition)) @throw [OFConditionWaitingException newWithClass: isa]; [super dealloc]; } @end |