1
/*****************************************************************************
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/os0thread.h
21
The interface to the operating system
22
process and thread control primitives
24
Created 9/8/1995 Heikki Tuuri
25
*******************************************************/
32
/* Maximum number of threads which can be created in the program;
33
this is also the size of the wait slot array for MySQL threads which
34
can wait inside InnoDB */
36
#define OS_THREAD_MAX_N srv_max_n_threads
39
/* Possible fixed priorities for threads */
40
#define OS_THREAD_PRIORITY_NONE 100
41
#define OS_THREAD_PRIORITY_BACKGROUND 1
42
#define OS_THREAD_PRIORITY_NORMAL 2
43
#define OS_THREAD_PRIORITY_ABOVE_NORMAL 3
46
typedef void* os_thread_t;
47
typedef unsigned long os_thread_id_t; /*!< In Windows the thread id
48
is an unsigned long int */
51
typedef pthread_t os_thread_t;
52
typedef os_thread_t os_thread_id_t; /*!< In Unix we use the thread
53
handle itself as the id of
57
/* Define a function pointer type to use in a typecast */
58
typedef void* (*os_posix_f_t) (void*);
60
/***************************************************************//**
61
Compares two thread ids for equality.
62
@return TRUE if equal */
67
os_thread_id_t a, /*!< in: OS thread or thread id */
68
os_thread_id_t b); /*!< in: OS thread or thread id */
69
/****************************************************************//**
70
Converts an OS thread id to a ulint. It is NOT guaranteed that the ulint is
71
unique for the thread though!
72
@return thread identifier as a number */
77
os_thread_id_t a); /*!< in: OS thread identifier */
78
/****************************************************************//**
79
Creates a new thread of execution. The execution starts from
80
the function given. The start function takes a void* parameter
82
NOTE: We count the number of threads in os_thread_exit(). A created
83
thread should always use that to exit and not use return() to exit.
84
@return handle to the thread */
92
ulint (*start_f)(void*), /*!< in: pointer to function
93
from which to start */
95
void* arg, /*!< in: argument to start
97
os_thread_id_t* thread_id); /*!< out: id of the created
100
/*****************************************************************//**
101
Exits the current thread. */
106
void* exit_value); /*!< in: exit value; in Windows this void*
107
is cast as a DWORD */
108
/*****************************************************************//**
109
Returns the thread identifier of current thread.
110
@return current thread identifier */
113
os_thread_get_curr_id(void);
114
/*========================*/
115
/*****************************************************************//**
116
Returns handle to the current thread.
117
@return current thread handle */
120
os_thread_get_curr(void);
121
/*====================*/
122
/*****************************************************************//**
123
Advises the os to give up remainder of the thread's time slice. */
126
os_thread_yield(void);
127
/*=================*/
128
/*****************************************************************//**
129
The thread sleeps at least the time given in microseconds. */
134
ulint tm); /*!< in: time in microseconds */
135
/******************************************************************//**
136
Gets a thread priority.
140
os_thread_get_priority(
141
/*===================*/
142
os_thread_t handle);/*!< in: OS handle to the thread */
143
/******************************************************************//**
144
Sets a thread priority. */
147
os_thread_set_priority(
148
/*===================*/
149
os_thread_t handle, /*!< in: OS handle to the thread */
150
ulint pri); /*!< in: priority: one of OS_PRIORITY_... */
151
/******************************************************************//**
152
Gets the last operating system error code for the calling thread.
153
@return last error on Windows, 0 otherwise */
156
os_thread_get_last_error(void);
157
/*==========================*/
160
#include "os0thread.ic"