rtems atomic operation (bit set_bit and test_and_clear_bit)

Chan Kim ckim at etri.re.kr
Sat Sep 5 09:52:48 UTC 2015



Dear rtems users,

I have an ISR which sets some bits according to interrupt and a thread which tests the bit and if it is '1' clears it.
The setting and testing/clearing  of the bits should be done using atomic operation.

In linux case, there are conveinient functions
- static inline void set_bit(unsigned long nr, volatile unsigned long *addr) and
- static inline int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
they provide atomic operations. (nr is the bit number and addr is the address of the unsigned long.

I impleted this function without atomicity and it's now causing problems. So I have to fix it now.
What are the equivalents in rtems? (I tried using spinlock around accessing the variable but the task can go to sleep holding the lock)
I found  _Atomic_Flag_test_and_set and _Atomic_Flag_clear in rtems-4.10.99-src/cpukit/score/include/rtems/score/atomic.h
But couldn't find any example on how to use these functions.
(BTW, I'm looking for set and test_and_clear, but rtems provides clear and test_and_set!!  :) )

Please somebody tell me how to implement set_bit and test_and_clear_bit in rtems.

Thanks,
Chan Kim


More information about the users mailing list