akaros/tests/misc-compat.h
<<
>>
Prefs
   1#pragma once
   2
   3#ifdef __ros__
   4
   5#include <parlib/timing.h>
   6
   7#define pthread_id() (pthread_self()->id)
   8
   9#else
  10
  11#include <stdbool.h>
  12#ifndef TRUE
  13#define TRUE    1
  14#endif
  15
  16#ifndef FALSE
  17#define FALSE   0
  18#endif
  19
  20#include <sys/param.h> /* MIN/MAX */
  21#include <unistd.h>
  22
  23/* not quite, since akaros udelay is a busy wait */
  24#define udelay(usec) usleep(usec)
  25#define ndelay(nsec)                                                           \
  26{                                                                              \
  27        struct timespec ts = {0, 0};                                           \
  28        ts.tv_nsec = (nsec);                                                   \
  29        nanosleep(&ts, 0);                                                     \
  30}
  31
  32/* not quite a normal relax, which also pauses, but this works for all archs */
  33static inline void cpu_relax(void)
  34{
  35        asm volatile("" : : : "memory");
  36}
  37
  38#define pthread_id() (pthread_self())
  39
  40#define vcore_id() (-1)
  41
  42#define num_vcores() ((int)sysconf(_SC_NPROCESSORS_ONLN))
  43
  44#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
  45
  46typedef void* atomic_t;
  47
  48static void uth_disable_notifs(void)
  49{
  50}
  51
  52static void uth_enable_notifs(void)
  53{
  54}
  55
  56static int get_pcoreid(void)
  57{
  58        return -1;
  59}
  60
  61#define printd(args...) {}
  62
  63#define COUNT_OF(x) (sizeof((x))/sizeof((x)[0]))
  64
  65#ifdef __x86_64__
  66
  67#define mb() ({ asm volatile("mfence" ::: "memory"); })
  68#define cmb() ({ asm volatile("" ::: "memory"); })
  69#define rmb() cmb()
  70#define wmb() cmb()
  71#define wrmb() mb()
  72#define rwmb() cmb()
  73
  74#endif /* __x86_64__ */
  75
  76#endif /* __ros__ */
  77