~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The interface to the operating system
 
3
process and thread control primitives
 
4
 
 
5
(c) 1995 Innobase Oy
 
6
 
 
7
Created 9/8/1995 Heikki Tuuri
 
8
*******************************************************/
 
9
 
 
10
#ifndef os0thread_h
 
11
#define os0thread_h
 
12
 
 
13
#include "univ.i"
 
14
 
 
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 */
 
18
 
 
19
#define OS_THREAD_MAX_N         srv_max_n_threads
 
20
 
 
21
 
 
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
 
27
 
 
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
 
38
 
 
39
/* Define a function pointer type to use in a typecast */
 
40
typedef void* (*os_posix_f_t) (void*);
 
41
 
 
42
/*******************************************************************
 
43
Compares two thread ids for equality. */
 
44
UNIV_INTERN
 
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! */
 
54
UNIV_INTERN
 
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. */
 
66
UNIV_INTERN
 
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
 
 
82
/*********************************************************************
 
83
Exits the current thread. */
 
84
UNIV_INTERN
 
85
void
 
86
os_thread_exit(
 
87
/*===========*/
 
88
        void*   exit_value);    /* in: exit value; in Windows this void*
 
89
                                is cast as a DWORD */
 
90
/*********************************************************************
 
91
Returns the thread identifier of current thread. */
 
92
UNIV_INTERN
 
93
os_thread_id_t
 
94
os_thread_get_curr_id(void);
 
95
/*========================*/
 
96
/*********************************************************************
 
97
Returns handle to the current thread. */
 
98
UNIV_INTERN
 
99
os_thread_t
 
100
os_thread_get_curr(void);
 
101
/*====================*/
 
102
/*********************************************************************
 
103
Advises the os to give up remainder of the thread's time slice. */
 
104
UNIV_INTERN
 
105
void
 
106
os_thread_yield(void);
 
107
/*=================*/
 
108
/*********************************************************************
 
109
The thread sleeps at least the time given in microseconds. */
 
110
UNIV_INTERN
 
111
void
 
112
os_thread_sleep(
 
113
/*============*/
 
114
        ulint   tm);    /* in: time in microseconds */
 
115
/**********************************************************************
 
116
Gets a thread priority. */
 
117
UNIV_INTERN
 
118
ulint
 
119
os_thread_get_priority(
 
120
/*===================*/
 
121
                                /* out: priority */
 
122
        os_thread_t     handle);/* in: OS handle to the thread */
 
123
/**********************************************************************
 
124
Sets a thread priority. */
 
125
UNIV_INTERN
 
126
void
 
127
os_thread_set_priority(
 
128
/*===================*/
 
129
        os_thread_t     handle, /* in: OS handle to the thread */
 
130
        ulint           pri);   /* in: priority: one of OS_PRIORITY_... */
 
131
/**********************************************************************
 
132
Gets the last operating system error code for the calling thread. */
 
133
UNIV_INTERN
 
134
ulint
 
135
os_thread_get_last_error(void);
 
136
/*==========================*/
 
137
 
 
138
#ifndef UNIV_NONINL
 
139
#include "os0thread.ic"
 
140
#endif
 
141
 
 
142
#endif