CK_PR_BTC(3)

πŸ’… ck_pr_btc(3) β€” atomic bit test-and-complement, bestie edition

okay so. picture this. you're in ck_pr_btc(3) (that's the manual page name, hi, it's me) and you need to flip ONE single bit. not the whole word. ONE bit. and you need it to happen atomically so nobody else on another thread can sneak in and ruin your whole vibe. that's the assignment. let's get into it. πŸŽ€


πŸ“š LIBRARY

Concurrency Kit β€” link it with -lck and you're in. ✨


🌸 SYNOPSIS

#include <ck_pr.h>

bool
ck_pr_btc_ptr(void *target, unsigned int bit_index);

bool
ck_pr_btc_uint(uint *target, unsigned int bit_index);

bool
ck_pr_btc_int(int *target, unsigned int bit_index);

bool
ck_pr_btc_64(uint64_t *target, unsigned int bit_index);

bool
ck_pr_btc_32(uint32_t *target, unsigned int bit_index);

bool
ck_pr_btc_16(uint16_t *target, unsigned int bit_index);

look at that family portrait. six siblings. one job. 🫢


πŸ’– DESCRIPTION

so the ck_pr_btc(3) family of functions atomically fetch the value of the bit in target at index bit_index, and then set that bit to its complement.

read that again. it reads the bit and flips it. both. atomically. no one can interrupt the glow-up. it's giving "test-and-complement", and it ate. πŸ”₯

btc = bit test and complement, iykyk. the "test" part is the return value (the OLD bit), the "complement" part is what happens to the bit (it becomes ~bit, aka the opposite of whatever it was). slay.


✨ RETURN VALUES

these functions return the original value of the bit at offset bit_index β€” like, the value it had before you flipped it β€” inside the value pointed to by target.

so if the bit was 1, you get 1 back and the bit is now 0. if the bit was 0, you get 0 back and the bit is now 1. the return value is the receipt. πŸ§ΎπŸ’…


πŸ‘‘ SEE ALSO

and more lore at http://concurrencykit.org/ if you wanna spiral (in a fun way). 🌈


that's the whole page, bestie. go flip some bits responsibly. πŸ’œ

Concurrency Kit, April 11, 2013 β€” that's the source/version and the date, mwah, no cap, the end. πŸ¦‹βœ¨

πŸ“¦ where this page comes from