~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
8
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
The interface to the operating system
21
process and thread control primitives
22
23
Created 9/8/1995 Heikki Tuuri
24
*******************************************************/
25
26
#ifndef os0thread_h
27
#define os0thread_h
28
29
#include "univ.i"
30
31
/* Maximum number of threads which can be created in the program;
32
this is also the size of the wait slot array for MySQL threads which
33
can wait inside InnoDB */
34
35
#define	OS_THREAD_MAX_N		srv_max_n_threads
36
37
38
/* Possible fixed priorities for threads */
39
#define OS_THREAD_PRIORITY_NONE		100
40
#define OS_THREAD_PRIORITY_BACKGROUND	1
41
#define OS_THREAD_PRIORITY_NORMAL	2
42
#define OS_THREAD_PRIORITY_ABOVE_NORMAL	3
43
44
#ifdef __WIN__
45
typedef void*			os_thread_t;
46
typedef ulint			os_thread_id_t;	/* In Windows the thread id
47
						is an unsigned long int */
48
#else
49
typedef pthread_t		os_thread_t;
50
typedef os_thread_t		os_thread_id_t;	/* In Unix we use the thread
51
						handle itself as the id of
52
						the thread */
53
#endif
54
55
/* Define a function pointer type to use in a typecast */
56
typedef void* (*os_posix_f_t) (void*);
57
58
/*******************************************************************
59
Compares two thread ids for equality. */
60
UNIV_INTERN
61
ibool
62
os_thread_eq(
63
/*=========*/
64
				/* out: TRUE if equal */
65
	os_thread_id_t	a,	/* in: OS thread or thread id */
66
	os_thread_id_t	b);	/* in: OS thread or thread id */
67
/********************************************************************
68
Converts an OS thread id to a ulint. It is NOT guaranteed that the ulint is
69
unique for the thread though! */
70
UNIV_INTERN
71
ulint
72
os_thread_pf(
73
/*=========*/
74
				/* out: unsigned long int */
75
	os_thread_id_t	a);	/* in: thread or thread id */
76
/********************************************************************
77
Creates a new thread of execution. The execution starts from
78
the function given. The start function takes a void* parameter
79
and returns a ulint.
80
NOTE: We count the number of threads in os_thread_exit(). A created
81
thread should always use that to exit and not use return() to exit. */
82
UNIV_INTERN
83
os_thread_t
84
os_thread_create(
85
/*=============*/
86
						/* out: handle to the thread */
87
#ifndef __WIN__
88
		 os_posix_f_t		 start_f,
89
#else
90
	ulint (*start_f)(void*),		/* in: pointer to function
91
						from which to start */
92
#endif
93
	void*			arg,		/* in: argument to start
94
						function */
95
	os_thread_id_t*		thread_id);	/* out: id of the created
96
						thread, or NULL */
97
98
/*********************************************************************
99
Exits the current thread. */
100
UNIV_INTERN
101
void
102
os_thread_exit(
103
/*===========*/
104
	void*	exit_value);	/* in: exit value; in Windows this void*
105
				is cast as a DWORD */
106
/*********************************************************************
107
Returns the thread identifier of current thread. */
108
UNIV_INTERN
109
os_thread_id_t
110
os_thread_get_curr_id(void);
111
/*========================*/
112
/*********************************************************************
113
Returns handle to the current thread. */
114
UNIV_INTERN
115
os_thread_t
116
os_thread_get_curr(void);
117
/*====================*/
118
/*********************************************************************
119
Advises the os to give up remainder of the thread's time slice. */
120
UNIV_INTERN
121
void
122
os_thread_yield(void);
123
/*=================*/
124
/*********************************************************************
125
The thread sleeps at least the time given in microseconds. */
126
UNIV_INTERN
127
void
128
os_thread_sleep(
129
/*============*/
130
	ulint	tm);	/* in: time in microseconds */
131
/**********************************************************************
132
Gets a thread priority. */
133
UNIV_INTERN
134
ulint
135
os_thread_get_priority(
136
/*===================*/
137
				/* out: priority */
138
	os_thread_t	handle);/* in: OS handle to the thread */
139
/**********************************************************************
140
Sets a thread priority. */
141
UNIV_INTERN
142
void
143
os_thread_set_priority(
144
/*===================*/
145
	os_thread_t	handle,	/* in: OS handle to the thread */
146
	ulint		pri);	/* in: priority: one of OS_PRIORITY_... */
147
/**********************************************************************
148
Gets the last operating system error code for the calling thread. */
149
UNIV_INTERN
150
ulint
151
os_thread_get_last_error(void);
152
/*==========================*/
153
154
#ifndef UNIV_NONINL
155
#include "os0thread.ic"
156
#endif
157
158
#endif