ldivmod, uldivmod: fix qdivrem calls
[minix.git] / include / minix / spin.h
blob1b6e1207bdafa42359a44f71fce7020f059d1afa
1 /* Prototypes for condition spinning helper functions (part of libsys). */
2 #ifndef _MINIX_SPIN_H
3 #define _MINIX_SPIN_H
5 /* Opaque spin state structure. */
6 typedef struct {
7 int s_state;
8 u32_t s_usecs;
9 u64_t s_base_tsc;
10 clock_t s_base_uptime;
11 int s_timeout;
12 } spin_t;
14 /* Functions. */
15 void spin_init(spin_t *s, u32_t usecs);
16 int spin_check(spin_t *s);
18 /* Macros. */
20 /* Execute a loop for at least 'u' microseconds, using spin object 's'.
21 * The body of the loop is guaranteed to be executed at least once.
23 #define SPIN_FOR(s,u) \
24 for (spin_init((s), (u)); spin_check((s)); )
26 /* Return whether spin object 's' timed out after a loop. */
27 #define SPIN_TIMEOUT(s) ((s)->s_timeout)
29 /* Spin until the given condition becomes true, or 'u' microseconds expired.
30 * The condition is guaranteed to be checked at least once.
32 #define SPIN_UNTIL(c,u) do { \
33 spin_t s; \
34 SPIN_FOR(&s,(u)) \
35 if (c) break; \
36 } while (0)
38 #endif /* _MINIX_SPIN_H */