美文网首页
YYSentinel

YYSentinel

作者: 幸运的小强本人 | 来源:发表于2016-03-03 18:13 被阅读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

相关文章

  • YYSentinel

    /**YYSentinel is a thread safe incrementing counterIt may...

网友评论

      本文标题:YYSentinel

      本文链接:https://www.haomeiwen.com/subject/ueqokttx.html