Selfie
Loading...
Searching...
No Matches
selfie_lib.Atomic.AtomicReference Class Reference
Inheritance diagram for selfie_lib.Atomic.AtomicReference:

Public Member Functions

 __init__ (self, T initial_value)
 
T get (self)
 
None set (self, T new_value)
 
T get_and_set (self, T new_value)
 
bool compare_and_set (self, T expected_value, T new_value)
 
T get_and_update (self, Callable[[T], T] update_function)
 
T update_and_get (self, Callable[[T], T] update_function)
 
T get_and_accumulate (self, T x, Callable[[T, T], T] accumulator)
 
T accumulate_and_get (self, T x, Callable[[T, T], T] accumulator)
 

Public Attributes

 value
 

Detailed Description

This has the same API as Java's AtomicReference, but it doesn't make any sense in the Python runtime.
The point of keeping it is that it makes the port from Kotlin more 1:1

Definition at line 6 of file Atomic.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.Atomic.AtomicReference.__init__ (   self,
T  initial_value 
)

Definition at line 12 of file Atomic.py.

12 def __init__(self, initial_value: T):
13 self.value: T = initial_value
14

Member Function Documentation

◆ accumulate_and_get()

T selfie_lib.Atomic.AtomicReference.accumulate_and_get (   self,
T  x,
Callable[[T, T], T accumulator 
)

Definition at line 46 of file Atomic.py.

46 def accumulate_and_get(self, x: T, accumulator: Callable[[T, T], T]) -> T:
47 self.value = accumulator(self.value, x)
48 return self.value

◆ compare_and_set()

bool selfie_lib.Atomic.AtomicReference.compare_and_set (   self,
T  expected_value,
T  new_value 
)

Definition at line 26 of file Atomic.py.

26 def compare_and_set(self, expected_value: T, new_value: T) -> bool:
27 if self.value == expected_value:
28 self.value = new_value
29 return True
30 return False
31

◆ get()

T selfie_lib.Atomic.AtomicReference.get (   self)

Definition at line 15 of file Atomic.py.

15 def get(self) -> T:
16 return self.value
17

◆ get_and_accumulate()

T selfie_lib.Atomic.AtomicReference.get_and_accumulate (   self,
T  x,
Callable[[T, T], T accumulator 
)

Definition at line 41 of file Atomic.py.

41 def get_and_accumulate(self, x: T, accumulator: Callable[[T, T], T]) -> T:
42 old_value = self.value
43 self.value = accumulator(self.value, x)
44 return old_value
45

◆ get_and_set()

T selfie_lib.Atomic.AtomicReference.get_and_set (   self,
T  new_value 
)

Definition at line 21 of file Atomic.py.

21 def get_and_set(self, new_value: T) -> T:
22 old_value = self.value
23 self.value = new_value
24 return old_value
25

◆ get_and_update()

T selfie_lib.Atomic.AtomicReference.get_and_update (   self,
Callable[[T], T update_function 
)

Definition at line 32 of file Atomic.py.

32 def get_and_update(self, update_function: Callable[[T], T]) -> T:
33 old_value = self.value
34 self.value = update_function(self.value)
35 return old_value
36

◆ set()

None selfie_lib.Atomic.AtomicReference.set (   self,
T  new_value 
)

Definition at line 18 of file Atomic.py.

18 def set(self, new_value: T) -> None:
19 self.value = new_value
20

◆ update_and_get()

T selfie_lib.Atomic.AtomicReference.update_and_get (   self,
Callable[[T], T update_function 
)

Definition at line 37 of file Atomic.py.

37 def update_and_get(self, update_function: Callable[[T], T]) -> T:
38 self.value = update_function(self.value)
39 return self.value
40

Member Data Documentation

◆ value

selfie_lib.Atomic.AtomicReference.value

Definition at line 19 of file Atomic.py.


The documentation for this class was generated from the following file: