From a461da48cd7121889c8382d2670b523927daf34a Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 5 Jan 2021 19:26:15 -0800 Subject: [PATCH] Added more CAS operations --- ck-polyfill.c | 24 +++++++++++++++++++++--- ck_pr.h | 10 ++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ck-polyfill.c b/ck-polyfill.c index 3ba00187..727a345c 100644 --- a/ck-polyfill.c +++ b/ck-polyfill.c @@ -10,15 +10,33 @@ #include "cyclone/types.h" #include "cyclone/runtime.h" -#include +#include "ck_pr.h" #include // 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; diff --git a/ck_pr.h b/ck_pr.h index 0075fbce..73e94565 100644 --- a/ck_pr.h +++ b/ck_pr.h @@ -3,7 +3,13 @@ #include - 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 */