~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/os0thread.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
/**************************************************//**
 
20
@file include/os0thread.h
 
21
The interface to the operating system
 
22
process and thread control primitives
 
23
 
 
24
Created 9/8/1995 Heikki Tuuri
 
25
*******************************************************/
 
26
 
 
27
#ifndef os0thread_h
 
28
#define os0thread_h
 
29
 
 
30
#include "univ.i"
 
31
 
 
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 */
 
35
 
 
36
#define OS_THREAD_MAX_N         srv_max_n_threads
 
37
 
 
38
 
 
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
 
44
 
 
45
#ifdef __WIN__
 
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 */
 
49
#else
 
50
typedef pthread_t               os_thread_t;
 
51
typedef os_thread_t             os_thread_id_t; /*!< In Unix we use the thread
 
52
                                                handle itself as the id of
 
53
                                                the thread */
 
54
#endif
 
55
 
 
56
/* Define a function pointer type to use in a typecast */
 
57
typedef void* (*os_posix_f_t) (void*);
 
58
 
 
59
/***************************************************************//**
 
60
Compares two thread ids for equality.
 
61
@return TRUE if equal */
 
62
UNIV_INTERN
 
63
ibool
 
64
os_thread_eq(
 
65
/*=========*/
 
66
        os_thread_id_t  a,      /*!< in: OS thread or thread id */
 
67
        os_thread_id_t  b);     /*!< in: OS thread or thread id */
 
68
/****************************************************************//**
 
69
Converts an OS thread id to a ulint. It is NOT guaranteed that the ulint is
 
70
unique for the thread though!
 
71
@return thread identifier as a number */
 
72
UNIV_INTERN
 
73
ulint
 
74
os_thread_pf(
 
75
/*=========*/
 
76
        os_thread_id_t  a);     /*!< in: OS thread identifier */
 
77
/****************************************************************//**
 
78
Creates a new thread of execution. The execution starts from
 
79
the function given. The start function takes a void* parameter
 
80
and returns a ulint.
 
81
NOTE: We count the number of threads in os_thread_exit(). A created
 
82
thread should always use that to exit and not use return() to exit.
 
83
@return handle to the thread */
 
84
UNIV_INTERN
 
85
os_thread_t
 
86
os_thread_create(
 
87
/*=============*/
 
88
#ifndef __WIN__
 
89
                 os_posix_f_t            start_f,
 
90
#else
 
91
        ulint (*start_f)(void*),                /*!< in: pointer to function
 
92
                                                from which to start */
 
93
#endif
 
94
        void*                   arg,            /*!< in: argument to start
 
95
                                                function */
 
96
        os_thread_id_t*         thread_id);     /*!< out: id of the created
 
97
                                                thread, or NULL */
 
98
 
 
99
/*****************************************************************//**
 
100
Exits the current thread. */
 
101
UNIV_INTERN
 
102
void
 
103
os_thread_exit(
 
104
/*===========*/
 
105
        void*   exit_value);    /*!< in: exit value; in Windows this void*
 
106
                                is cast as a DWORD */
 
107
/*****************************************************************//**
 
108
Returns the thread identifier of current thread.
 
109
@return current thread identifier */
 
110
UNIV_INTERN
 
111
os_thread_id_t
 
112
os_thread_get_curr_id(void);
 
113
/*========================*/
 
114
/*****************************************************************//**
 
115
Returns handle to the current thread.
 
116
@return current thread handle */
 
117
UNIV_INTERN
 
118
os_thread_t
 
119
os_thread_get_curr(void);
 
120
/*====================*/
 
121
/*****************************************************************//**
 
122
Advises the os to give up remainder of the thread's time slice. */
 
123
UNIV_INTERN
 
124
void
 
125
os_thread_yield(void);
 
126
/*=================*/
 
127
/*****************************************************************//**
 
128
The thread sleeps at least the time given in microseconds. */
 
129
UNIV_INTERN
 
130
void
 
131
os_thread_sleep(
 
132
/*============*/
 
133
        ulint   tm);    /*!< in: time in microseconds */
 
134
/******************************************************************//**
 
135
Gets a thread priority.
 
136
@return priority */
 
137
UNIV_INTERN
 
138
ulint
 
139
os_thread_get_priority(
 
140
/*===================*/
 
141
        os_thread_t     handle);/*!< in: OS handle to the thread */
 
142
/******************************************************************//**
 
143
Sets a thread priority. */
 
144
UNIV_INTERN
 
145
void
 
146
os_thread_set_priority(
 
147
/*===================*/
 
148
        os_thread_t     handle, /*!< in: OS handle to the thread */
 
149
        ulint           pri);   /*!< in: priority: one of OS_PRIORITY_... */
 
150
/******************************************************************//**
 
151
Gets the last operating system error code for the calling thread.
 
152
@return last error on Windows, 0 otherwise */
 
153
UNIV_INTERN
 
154
ulint
 
155
os_thread_get_last_error(void);
 
156
/*==========================*/
 
157
 
 
158
#ifndef UNIV_NONINL
 
159
#include "os0thread.ic"
 
160
#endif
 
161
 
 
162
#endif