mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Added more CAS operations
This commit is contained in:
parent
2ca6aa4910
commit
a461da48cd
2 changed files with 29 additions and 5 deletions
|
@ -10,15 +10,33 @@
|
|||
|
||||
#include "cyclone/types.h"
|
||||
#include "cyclone/runtime.h"
|
||||
#include <ck_pr.h>
|
||||
#include "ck_pr.h"
|
||||
#include <unistd.h>
|
||||
|
||||
// TODO: global pthread mutex lock for this? obviously not ideal but the
|
||||
// whole purpose of this module is a minimal interface for compatibility
|
||||
// not speed
|
||||
|
||||
bool
|
||||
ck_pr_cas_int(int *target, int old_value, int new_value)
|
||||
bool ck_pr_cas_int(int *target, int old_value, int new_value)
|
||||
{
|
||||
if (*target == old_value) {
|
||||
*target = new_value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ck_pr_cas_ptr(void *target, void *old_value, void *new_value)
|
||||
{
|
||||
if ( *(void **)target == old_value ) {
|
||||
*(void **)target = new_value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// *(void **)v = set;
|
||||
}
|
||||
|
||||
bool ck_pr_cas_8(uint8_t *target, uint8_t old_value, uint8_t new_value)
|
||||
{
|
||||
if (*target == old_value) {
|
||||
*target = new_value;
|
||||
|
|
10
ck_pr.h
10
ck_pr.h
|
@ -3,7 +3,13 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool
|
||||
ck_pr_cas_int(int *target, int old_value, int new_value);
|
||||
bool
|
||||
ck_pr_cas_ptr(void *target, void *old_value, void *new_value);
|
||||
|
||||
bool
|
||||
ck_pr_cas_int(int *target, int old_value, int new_value);
|
||||
|
||||
bool
|
||||
ck_pr_cas_8(uint8_t *target, uint8_t old_value, uint8_t new_value);
|
||||
|
||||
#endif /* CYCLONE_CK_POLYFILL_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue