Can someone kindly answer my questions under the accepted answer?
I was reading: https://www.kernel.org/doc/htmldocs/kernel-api/API-test-and-set-bit.html but didn't understand that much.
If the bit was already 1 does it stay 1 or 0?
If it's 0 and I'm not wrong then it changes to 1?
What is "bit" here, an input can be bool which is byte not bit...
By return do they mean that after changing the value we change in back to its original condition? if so then this is useless...
In C++ when I try to call it I get:
Use of undeclared identifier 'test_and_set_bit'
Sorry but that page wasn't clear at all.
Usage:
typedef struct lock {
bool is_locked;
} lock_t;
void init(lock_t* l) {
l->is_locked = 0;
}
void lock(lock_t* l) {
while (test_and_set_bit
(l->is_locked));
}
void unlock(lock_t* l) {
l->is_locked = 0;
}