Add atomic compare-and-swap
The atomic compare-and-swap can be used to implement lock-free structures. The planned use for this is to remove some of the locking done in the services when listeners are being manipulated.
This commit is contained in:
@ -102,4 +102,19 @@ static inline void atomic_synchronize()
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Atomic compare-and-swap of pointers
|
||||
*
|
||||
* @param variable Pointer to the variable
|
||||
* @param old_value Pointer to the expected value of @variable
|
||||
* @param new_value Stored value if @c variable is equal to @c old_value
|
||||
*
|
||||
* @return True if @c variable and @c old_value were equal
|
||||
*
|
||||
* @note If GCC __atomic builtins are available, the contents of @c variable are
|
||||
* written to @c old_value if the two are not equal. Do not rely on this behavior
|
||||
* and always do a separate read before attempting a compare-and-swap.
|
||||
*/
|
||||
bool atomic_cas_ptr(void **variable, void** old_value, void *new_value);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
Reference in New Issue
Block a user