mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / os0thread.h
blob3cf05feb3a93f40633b74b26043a8e67c0cf8249
1 /******************************************************
2 The interface to the operating system
3 process and thread control primitives
5 (c) 1995 Innobase Oy
7 Created 9/8/1995 Heikki Tuuri
8 *******************************************************/
10 #ifndef os0thread_h
11 #define os0thread_h
13 #include "univ.i"
15 /* Maximum number of threads which can be created in the program;
16 this is also the size of the wait slot array for MySQL threads which
17 can wait inside InnoDB */
19 #define OS_THREAD_MAX_N srv_max_n_threads
22 /* Possible fixed priorities for threads */
23 #define OS_THREAD_PRIORITY_NONE 100
24 #define OS_THREAD_PRIORITY_BACKGROUND 1
25 #define OS_THREAD_PRIORITY_NORMAL 2
26 #define OS_THREAD_PRIORITY_ABOVE_NORMAL 3
28 #ifdef __WIN__
29 typedef void* os_thread_t;
30 typedef ulint os_thread_id_t; /* In Windows the thread id
31 is an unsigned long int */
32 #else
33 typedef pthread_t os_thread_t;
34 typedef os_thread_t os_thread_id_t; /* In Unix we use the thread
35 handle itself as the id of
36 the thread */
37 #endif
39 /* Define a function pointer type to use in a typecast */
40 typedef void* (*os_posix_f_t) (void*);
42 /*******************************************************************
43 Compares two thread ids for equality. */
45 ibool
46 os_thread_eq(
47 /*=========*/
48 /* out: TRUE if equal */
49 os_thread_id_t a, /* in: OS thread or thread id */
50 os_thread_id_t b); /* in: OS thread or thread id */
51 /********************************************************************
52 Converts an OS thread id to a ulint. It is NOT guaranteed that the ulint is
53 unique for the thread though! */
55 ulint
56 os_thread_pf(
57 /*=========*/
58 /* out: unsigned long int */
59 os_thread_id_t a); /* in: thread or thread id */
60 /********************************************************************
61 Creates a new thread of execution. The execution starts from
62 the function given. The start function takes a void* parameter
63 and returns a ulint.
64 NOTE: We count the number of threads in os_thread_exit(). A created
65 thread should always use that to exit and not use return() to exit. */
67 os_thread_t
68 os_thread_create(
69 /*=============*/
70 /* out: handle to the thread */
71 #ifndef __WIN__
72 os_posix_f_t start_f,
73 #else
74 ulint (*start_f)(void*), /* in: pointer to function
75 from which to start */
76 #endif
77 void* arg, /* in: argument to start
78 function */
79 os_thread_id_t* thread_id); /* out: id of the created
80 thread, or NULL */
81 int
82 os_thread_join(
83 /*===========*/
84 os_thread_id_t thread_id); /* in: id of the thread to join */
85 /*********************************************************************
86 Exits the current thread. */
88 void
89 os_thread_exit(
90 /*===========*/
91 void* exit_value); /* in: exit value; in Windows this void*
92 is cast as a DWORD */
93 /*********************************************************************
94 Returns the thread identifier of current thread. */
96 os_thread_id_t
97 os_thread_get_curr_id(void);
98 /*========================*/
99 /*********************************************************************
100 Returns handle to the current thread. */
102 os_thread_t
103 os_thread_get_curr(void);
104 /*====================*/
105 /*********************************************************************
106 Advises the os to give up remainder of the thread's time slice. */
108 void
109 os_thread_yield(void);
110 /*=================*/
111 /*********************************************************************
112 The thread sleeps at least the time given in microseconds. */
114 void
115 os_thread_sleep(
116 /*============*/
117 ulint tm); /* in: time in microseconds */
118 /**********************************************************************
119 Gets a thread priority. */
121 ulint
122 os_thread_get_priority(
123 /*===================*/
124 /* out: priority */
125 os_thread_t handle);/* in: OS handle to the thread */
126 /**********************************************************************
127 Sets a thread priority. */
129 void
130 os_thread_set_priority(
131 /*===================*/
132 os_thread_t handle, /* in: OS handle to the thread */
133 ulint pri); /* in: priority: one of OS_PRIORITY_... */
134 /**********************************************************************
135 Gets the last operating system error code for the calling thread. */
137 ulint
138 os_thread_get_last_error(void);
139 /*==========================*/
141 #ifndef UNIV_NONINL
142 #include "os0thread.ic"
143 #endif
145 #endif