libsys: add standard condition spinning primitives
This commit is contained in:
@@ -22,7 +22,7 @@ INCS+= minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \
|
||||
minix/netdriver.h minix/partition.h minix/paths.h \
|
||||
minix/portio.h minix/profile.h minix/queryparam.h \
|
||||
minix/rs.h minix/safecopies.h minix/sched.h minix/sef.h minix/sound.h \
|
||||
minix/sys_config.h minix/sysinfo.h minix/syslib.h \
|
||||
minix/spin.h minix/sys_config.h minix/sysinfo.h minix/syslib.h \
|
||||
minix/sysutil.h minix/timers.h minix/tty.h minix/type.h minix/types.h \
|
||||
minix/u64.h minix/vfsif.h minix/vm.h \
|
||||
minix/compiler.h minix/compiler-ack.h minix/sha2.h
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/sysutil.h>
|
||||
#include <minix/timers.h>
|
||||
#include <minix/spin.h>
|
||||
#include <minix/bitmap.h>
|
||||
|
||||
#include <machine/interrupt.h> /* IRQ vectors and miscellaneous ports */
|
||||
|
||||
38
include/minix/spin.h
Normal file
38
include/minix/spin.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Prototypes for condition spinning helper functions (part of libsys). */
|
||||
#ifndef _MINIX_SPIN_H
|
||||
#define _MINIX_SPIN_H
|
||||
|
||||
/* Opaque spin state structure. */
|
||||
typedef struct {
|
||||
int s_state;
|
||||
u32_t s_usecs;
|
||||
u64_t s_base_tsc;
|
||||
clock_t s_base_uptime;
|
||||
int s_timeout;
|
||||
} spin_t;
|
||||
|
||||
/* Functions. */
|
||||
_PROTOTYPE( void spin_init, (spin_t *s, u32_t usecs) );
|
||||
_PROTOTYPE( int spin_check, (spin_t *s) );
|
||||
|
||||
/* Macros. */
|
||||
|
||||
/* Execute a loop for at least 'u' microseconds, using spin object 's'.
|
||||
* The body of the loop is guaranteed to be executed at least once.
|
||||
*/
|
||||
#define SPIN_FOR(s,u) \
|
||||
for (spin_init((s), (u)); spin_check((s)); )
|
||||
|
||||
/* Return whether spin object 's' timed out after a loop. */
|
||||
#define SPIN_TIMEOUT(s) ((s)->s_timeout)
|
||||
|
||||
/* Spin until the given condition becomes true, or 'u' microseconds expired.
|
||||
* The condition is guaranteed to be checked at least once.
|
||||
*/
|
||||
#define SPIN_UNTIL(c,u) do { \
|
||||
spin_t s; \
|
||||
SPIN_FOR(&s,(u)) \
|
||||
if (c) break; \
|
||||
} while (0)
|
||||
|
||||
#endif /* _MINIX_SPIN_H */
|
||||
Reference in New Issue
Block a user