-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.h
107 lines (89 loc) · 2.17 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef __CONFIG_H__
#define __CONFIG_H__
#define _GNU_SOURCE
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define ALIGN_PAGE_ALIGN 0x1000
#define UXEN_PAGE_MASK (~0xfff)
#define BDRV_SECTOR_BITS 9
#define debug_printf printf
#define Werr err
#define Wwarn warn
typedef pthread_t uxen_thread;
#define wait_thread(_a) pthread_join(_a, NULL)
#define create_thread(_a, _b, _c) pthread_create(_a, NULL, _b, (void *) _c)
#define elevate_thread(_t)
#define close_thread_handle(thread) do { } while(0)
typedef pthread_mutex_t critical_section;
static inline int file_exists(const char *path)
{
struct stat st;
if (stat(path, &st) >= 0)
return 1;
else
return 0;
}
static inline void
critical_section_init(critical_section *cs)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
int ret = pthread_mutex_init(cs, &attr);
if (ret) {
errno = ret;
err(1, "%s: pthread_mutex_init failed", __FUNCTION__);
}
}
static inline void
critical_section_free(critical_section *cs)
{
int ret;
ret = pthread_mutex_destroy(cs);
if (ret) {
errno = ret;
warn("%s: pthread_mutex_destroy failed", __FUNCTION__);
}
}
static inline void
critical_section_enter(critical_section *cs)
{
int ret;
ret = pthread_mutex_lock(cs);
if (ret) {
errno = ret;
err(1, "%s: pthread_mutex_lock failed", __FUNCTION__);
}
}
static inline void
critical_section_leave(critical_section *cs)
{
int ret;
ret = pthread_mutex_unlock(cs);
if (ret) {
errno = ret;
err(1, "%s: pthread_mutex_unlock failed", __FUNCTION__);
}
}
#include <sys/time.h>
static inline uint64_t os_get_clock(void)
{
struct timeval time;
gettimeofday(&time,0);
return (1000000 * time.tv_sec + time.tv_usec);
}
#define page_align_alloc malloc
#define page_align_free free
#define align_alloc malloc
#define align_free free
#endif /* __CONFIG_H__ */