CK_PR_CAS(3)

πŸ’– CK_PR_CAS πŸ’– (that's ck_pr_cas(3), bestie)

okay so. hi. sit down. we're learning the atomic compare-and-swap family from Concurrency Kit and honestly? it's giving main character energy. 🌟

This page covers ck_pr_cas_ptr, ck_pr_cas_ptr_value, ck_pr_cas_ptr_2, ck_pr_cas_ptr_2_value, ck_pr_cas_double, ck_pr_cas_double_value, ck_pr_cas_char, ck_pr_cas_char_value, ck_pr_cas_uint, ck_pr_cas_uint_value, ck_pr_cas_int, ck_pr_cas_int_value, ck_pr_cas_64_2, ck_pr_cas_64_2_value, ck_pr_cas_64, ck_pr_cas_64_value, ck_pr_cas_32, ck_pr_cas_32_value, ck_pr_cas_16, ck_pr_cas_16_value, ck_pr_cas_8, and ck_pr_cas_8_value β€” all of them atomic compare-and-swap operations. yes. all of them. we're doing the whole girl group. πŸ‘‘


✨ LIBRARY ✨

Concurrency Kit (libck, -lck) πŸŽ€


🌸 SYNOPSIS 🌸

#include <ck_pr.h>

bool
ck_pr_cas_ptr(void *target, void *old_value, void *new_value);

bool
ck_pr_cas_ptr_value(void *target, void *old_value, void *new_value,
    void *original_value);

bool
ck_pr_cas_ptr_2(void *target, void *old_value, void *new_value);

bool
ck_pr_cas_ptr_2_value(void *target, void *old_value, void *new_value,
    void *original_value);

bool
ck_pr_cas_double(double *target, double old_value, double new_value);

bool
ck_pr_cas_double_value(double *target, double old_value,
    double new_value, double *original_value);

bool
ck_pr_cas_char(char *target, char old_value, char new_value);

bool
ck_pr_cas_char_value(char *target, char old_value, char new_value,
    char *original_value);

bool
ck_pr_cas_uint(unsigned int *target, unsigned int old_value,
    unsigned int new_value);

bool
ck_pr_cas_uint_value(unsigned int *target, unsigned int old_value,
    unsigned int new_value, unsigned int *original_value);

bool
ck_pr_cas_int(int *target, int old_value, int new_value);

bool
ck_pr_cas_int_value(int *target, int old_value, int new_value,
    int *original_value);

bool
ck_pr_cas_64_2(uint64_t target[static 2], uint64_t old_value[static 2],
    uint64_t new_value[static 2]);

bool
ck_pr_cas_64_2_value(uint64_t target[static 2],
    uint64_t old_value[static 2], uint64_t new_value[static 2],
    uint64_t original_value[static 2]);

bool
ck_pr_cas_64(uint64_t *target, uint64_t old_value, uint64_t new_value);

bool
ck_pr_cas_64_value(uint64_t *target, uint64_t old_value,
    uint64_t new_value, uint64_t *original_value);

bool
ck_pr_cas_32(uint32_t *target, uint32_t old_value, uint32_t new_value);

bool
ck_pr_cas_32_value(uint32_t *target, uint32_t old_value,
    uint32_t new_value, uint32_t *original_value);

bool
ck_pr_cas_16(uint16_t *target, uint16_t old_value, uint16_t new_value);

bool
ck_pr_cas_16_value(uint16_t *target, uint16_t old_value,
    uint16_t new_value, uint16_t *original_value);

bool
ck_pr_cas_8(uint8_t *target, uint8_t old_value, uint8_t new_value);

bool
ck_pr_cas_8_value(uint8_t *target, uint8_t old_value, uint8_t new_value,
    uint8_t *original_value);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the ck_pr_cas(3) family β€” the whole squad β€” does one very specific, very iconic thing: it atomically compares the value sitting in target for equality with old_value, and if they match, it replaces the value that target points to with the value you gave in new_value. πŸ’…

and if target was not equal to old_value? then literally nothing happens. no modification. no touchy. target stays exactly as it was. 🫢

now, the *_value girlies have a lil extra: they unconditionally update original_value. like, no matter what, original_value gets updated. that's their whole thing. periodt. ✨


πŸ”₯ RETURN VALUES πŸ”₯

this family returns true if the value in target was modified as a result of the operation. otherwise? false. that's it. that's the tea. πŸ“


πŸ’œ SEE ALSO πŸ’œ

Additional information available at http://concurrencykit.org/ 🌈


okay that's the whole page bestie, you ate it, you understood it, i'm so proud of you πŸ₯ΉπŸ’–

this was the ck_pr_cas(3) page, dated April 11, 2013 β€” yeah she's a lil vintage but she still serves βœ¨πŸ’…

πŸ“¦ where this page comes from