1
/******************************************************
2
The interface to the operating system
3
process and thread control primitives
7
Created 9/8/1995 Heikki Tuuri
8
*******************************************************/
10
#include "os0thread.h"
12
#include "os0thread.ic"
19
/*********************************************************************
20
Returns the thread identifier of current thread. */
23
os_thread_get_curr_id(void)
24
/*=======================*/
27
return(GetCurrentThreadId());
29
return((os_thread_id_t) pthread_self());
33
/* Define a function pointer type to use in a typecast */
34
typedef void* (*os_posix_f_t) (void*);
36
/********************************************************************
37
Creates a new thread of execution. The execution starts from
38
the function given. The start function takes a void* parameter
39
and returns an ulint. */
44
/* out: handle to the thread */
45
ulint (*start_f)(void*), /* in: pointer to function
46
from which to start */
47
void* arg, /* in: argument to start
49
os_thread_id_t* thread_id) /* out: id of created
55
thread = CreateThread(NULL, /* no security attributes */
56
0, /* default size stack */
57
(LPTHREAD_START_ROUTINE)start_f,
59
0, /* thread runs immediately */
68
/* Note that below we cast the start function returning an integer
69
to a function returning a pointer: this may cause error
70
if the return value is used somewhere! */
72
ret = pthread_create(&pthread, NULL, (os_posix_f_t) start_f, arg);
78
/*********************************************************************
79
Returns handle to the current thread. */
82
os_thread_get_curr(void)
83
/*=======================*/
86
return(GetCurrentThread());
88
return(pthread_self());
92
/*********************************************************************
93
Converts a thread id to a ulint. */
96
os_thread_conv_id_to_ulint(
97
/*=======================*/
98
/* out: converted to ulint */
99
os_thread_id_t id) /* in: thread id */
104
/*********************************************************************
105
Advises the os to give up remainder of the thread's time slice. */
108
os_thread_yield(void)
109
/*=================*/
118
/*********************************************************************
119
The thread sleeps at least the time given in microseconds. */
124
ulint tm) /* in: time in microseconds */
134
select(0, NULL, NULL, NULL, &t);
138
/**********************************************************************
139
Sets a thread priority. */
142
os_thread_set_priority(
143
/*===================*/
144
os_thread_t handle, /* in: OS handle to the thread */
145
ulint pri) /* in: priority */
150
if (pri == OS_THREAD_PRIORITY_BACKGROUND) {
151
os_pri = THREAD_PRIORITY_BELOW_NORMAL;
152
} else if (pri == OS_THREAD_PRIORITY_NORMAL) {
153
os_pri = THREAD_PRIORITY_NORMAL;
154
} else if (pri == OS_THREAD_PRIORITY_ABOVE_NORMAL) {
155
os_pri = THREAD_PRIORITY_HIGHEST;
160
ut_a(SetThreadPriority(handle, os_pri));
167
/**********************************************************************
168
Gets a thread priority. */
171
os_thread_get_priority(
172
/*===================*/
174
os_thread_t handle) /* in: OS handle to the thread */
180
os_pri = GetThreadPriority(handle);
182
if (os_pri == THREAD_PRIORITY_BELOW_NORMAL) {
183
pri = OS_THREAD_PRIORITY_BACKGROUND;
184
} else if (os_pri == THREAD_PRIORITY_NORMAL) {
185
pri = OS_THREAD_PRIORITY_NORMAL;
186
} else if (os_pri == THREAD_PRIORITY_HIGHEST) {
187
pri = OS_THREAD_PRIORITY_ABOVE_NORMAL;
198
/**********************************************************************
199
Gets the last operating system error code for the calling thread. */
202
os_thread_get_last_error(void)
203
/*==========================*/
206
return(GetLastError());