ALAtomicReference.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // ALAtomicReference.h
  3. // AppLovinSDK
  4. //
  5. // Created by Alan Cao on 1/5/24.
  6. //
  7. NS_ASSUME_NONNULL_BEGIN
  8. /**
  9. * An object reference that may be updated atomically.
  10. */
  11. @interface ALAtomicReference <ObjectType> : NSObject
  12. /**
  13. * Returns the current value.
  14. */
  15. - (nullable ObjectType)get;
  16. /**
  17. * Unconditionally sets to the given value.
  18. */
  19. - (void)set:(nullable ObjectType)newValue;
  20. /**
  21. * Atomically sets to the given value and returns the previous value.
  22. */
  23. - (nullable ObjectType)getAndSet:(nullable ObjectType)newValue;
  24. /**
  25. * Atomically sets the value to the given updated value if the current value == the expected value.
  26. *
  27. * @param expect The expected value.
  28. * @param update The new value.
  29. *
  30. * @return @c YES if successful. @c NO return indicates that the actual value was not equal to the expected value.
  31. */
  32. - (BOOL)compareAndSet:(nullable ObjectType)expect update:(nullable ObjectType)update;
  33. /**
  34. * Creates an instance with the given initial value.
  35. */
  36. - (instancetype)initWithValue:(nullable ObjectType)initialValue;
  37. @end
  38. NS_ASSUME_NONNULL_END