gint-with-thread/include/gint/atomic.h

36 lines
1.3 KiB
C

#ifndef _SRC_KERNEL_ATOMIC_H__
# define _SRC_KERNEL_ATOMIC_H__
#include <stddef.h>
#include <stdint.h>
/* atomic_begin(): Start atomic operation
This function will block interruptions and exception until
"thread_atomic_stop()" is called. This is really useful when you need to
secure some tricky part of code (like driver kernel-level implementation).
But be carefull: your code executed after this function SHOULD be
EXCEPTION-SAFE ! Otherwise, a crash will occur and Gint can do nothing to
avoid it because is hardware specific. If you need to secure shared data,
use mutex instead.
This implementation is recursive-safe and will return:
* SR value when you enter in "atomic" operation (first call)
* 0 if you are already in a "atomic" operation (x call)
To return to the "normal" operation, you should call "thread_atomic_stop()"
as many time as you have involved with "thread_atomic_start()". */
extern void *atomic_begin(void);
/* atomic_end(): Stop atomic opration
This function will try to return to the "normal" mode and will return:
* negative value If error occur
* 0 If you are alwayrs in "atomic" mode
* the restored SR value If you are returned to the "clasic" mode */
extern void *atomic_end(void);
#endif /*_SRC_KERNEL_ATOMIC_H__*/