YYSentinel

2016-03-03  本文已影响53人  幸运的小强本人

/**
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
上一篇 下一篇

猜你喜欢

热点阅读