Boron
2.1.0
urlan
os.h
1
#ifndef OS_H
2
#define OS_H
3
/*
4
Boron operating system interface.
5
*/
6
7
8
#include <assert.h>
9
#include <math.h>
10
#include <stdarg.h>
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <string.h>
14
#ifdef __sun__
15
#include <inttypes.h>
16
#else
17
#include <stdint.h>
18
#endif
19
20
21
#ifdef _WIN32
22
23
// Must define _WIN32_WINNT to use InitializeCriticalSectionAndSpinCount
24
#ifndef _WIN32_WINNT
25
#define _WIN32_WINNT 0x0403
26
#endif
27
#include <windows.h>
28
#include <direct.h>
// _chdir, _getcwd
29
30
#undef small
// Defined in RpcNdr.h (SDK v6.0A)
31
32
#ifdef _MSC_VER
33
#define inline __inline
34
#endif
35
36
#define vaStrPrint _vsnprintf
37
38
typedef
HANDLE OSThread;
39
typedef
CRITICAL_SECTION OSMutex;
40
typedef
CONDITION_VARIABLE OSCond;
41
42
#define mutexInitF(mh) \
43
(InitializeCriticalSectionAndSpinCount(&mh,0x80000400) == 0)
44
#define mutexFree(mh) DeleteCriticalSection(&mh)
45
#define mutexLock(mh) EnterCriticalSection(&mh)
46
#define mutexUnlock(mh) LeaveCriticalSection(&mh)
47
#define condInit(cond) InitializeConditionVariable(&cond)
48
#define condFree(cond)
49
#define condWaitF(cond,mh) (! SleepConditionVariableCS(&cond,&mh,INFINITE))
50
#define condSignal(cond) WakeConditionVariable(&cond)
51
52
#else
53
54
#include <pthread.h>
55
#include <unistd.h>
56
57
#define vaStrPrint vsnprintf
58
59
typedef
pthread_t OSThread;
60
typedef
pthread_mutex_t OSMutex;
61
typedef
pthread_cond_t OSCond;
62
63
#define mutexInitF(mh) (pthread_mutex_init(&mh,0) == -1)
64
#define mutexFree(mh) pthread_mutex_destroy(&mh)
65
#define mutexLock(mh) pthread_mutex_lock(&mh)
66
#define mutexUnlock(mh) pthread_mutex_unlock(&mh)
67
#define condInit(cond) pthread_cond_init(&cond,0)
68
#define condFree(cond) pthread_cond_destroy(&cond)
69
#define condWaitF(cond,mh) pthread_cond_wait(&cond,&mh)
70
#define condSignal(cond) pthread_cond_signal(&cond)
71
72
#endif
73
74
75
#define strPrint sprintf
76
#define strNCpy strncpy
77
#define strLen strlen
78
79
#define memCpy memcpy
80
#define memSet memset
81
#define memMove memmove
82
83
84
#ifdef __cplusplus
85
extern
"C"
{
86
#endif
87
88
#ifdef TRACK_MALLOC
89
void
* memAlloc(
size_t
);
90
void
* memRealloc(
void
*,
size_t
);
91
void
memFree(
void
* );
92
void
memReport(
int
verbose );
93
#else
94
#define memAlloc malloc
95
#define memRealloc realloc
96
#define memFree free
97
#endif
98
99
#ifdef UR_CONFIG_EMH
100
extern
void
ur_dprint(
const
char
*, ... );
101
#define dprint ur_dprint
102
#else
103
#define dprint printf
104
#endif
105
106
#ifdef __cplusplus
107
}
108
#endif
109
110
111
#endif
/* OS_H */
Generated by
1.13.0