-
Notifications
You must be signed in to change notification settings - Fork 3
/
util_os.h
56 lines (49 loc) · 1.03 KB
/
util_os.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
#ifndef UTIL_OS_H
#define UTIL_OS_H
#include "util_type.h"
#include <assert.h>
#include <sys/time.h>
#include <pthread.h>
//debug
#ifdef UNIV_DEBUG
//for debug state
#define ut_d(EXPR) do {EXPR;} while (0)
//for debug assert
#else
#define ut_d(EXPR)
#endif
//time
int ut_usectime(ulong* sec, ulong* ms);
//mutex
#define FAST_MUTEX_INIT NULL
typedef struct mutex_struct mutex_t;
struct mutex_struct{
pthread_mutex_t os_mutex;
//waiters count
#ifdef UNIV_DEBUG
pthread_t thread_id;
const char* mutex_name;
ulong count_using;
ulong count_os_yield; //count of os_wait
ulonglong spent_time; //os_wait timer msec
ulonglong max_spent_time;
#endif
};
void mutex_create(
mutex_t* mutex
#ifdef UNIV_DEBUG
,const char* cmutex_name
#endif
);
void mutex_destroy(mutex_t* mutex);
void mutex_enter(mutex_t* mutex);
void mutex_exit(mutex_t* mutex);
#ifdef UNIV_DEBUG
ibool mutex_own(mutex_t* mutex);
#endif
//mem
void ut_memset(byte* ptr, ulong n);
void* ut_malloc_low(ulong n, int set_to_zero);
void* ut_malloc(ulong n);
void ut_free(void *ptr);
#endif