/**
YYSentinel is a thread safe incrementing counter
It may be used in some multi-thread situation.
*/
@interface YYSentinel: NSObject
// Returns the current value of the counter
@property (readonly) int32_t value;
// Increase the value atomically.
// @return The new value
- (int32_t)increase;
@end
@implementation YYSentinel {
int32_t _value
}
- (int32_t)value {
return _value;
}
- (int32_t)increase {
return OSAtomicIncrement32(&_value)
}
@end