CK_PR_BTR(3)

πŸ’– ck_pr_btr(3) β€” the bit test-and-reset girlies πŸ’–

okay so bestie, welcome to CK_PR_BTR(3) β€” no cap, this is the manual page for the atomic bit test-and-reset operations. it's giving "tiny function, huge main character energy" ✨


🌸 LIBRARY 🌸

Concurrency Kit β€” link it with -lck and you're sooo set, fr fr πŸ’…


✨ SYNOPSIS ✨

first things first, you gotta bring the header in:

#include <ck_pr.h>

and then, like, pick your fighter πŸŽ€ β€” here's the whole squad:

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

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

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

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

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

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so the ck_pr_btr(3) family of functions is lowkey iconic: it atomically fetches the value of the bit in target at index bit_index, and then sets that bit to 0. that's it. that's the whole vibe. test it, then reset it. πŸ‘‘

no other thread is gonna catch you mid-operation, that's the whole point β€” atomicity is the moment, periodt. ✨


πŸŽ€ RETURN VALUES πŸŽ€

this whole family of functions returns the original value of the bit at offset bit_index inside the value that target points to. so you get the tea on what the bit was before you yeeted it back down to 0. πŸ’–


🌈 SEE ALSO 🌈

go read these next, bestie, they're all part of the same friend group 🫢:

and if you want even more lore, there's additional information available at http://concurrencykit.org/ 🌐


okay that's the whole page bestie, you ate that πŸ’…

mwah! this was ck_pr_btr(3), dated April 11, 2013 β€” ily, go be atomic, and don't forget to link with -lck πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from