~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-05-11 17:50:22 UTC
  • Revision ID: brian@gaz-20090511175022-y35q9ky6uh9ldcjt
Replacing Sun employee copyright headers (aka... anything done by a Sun
employee is copyright by Sun).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************
2
 
The interface to the operating system
3
 
synchronization primitives.
4
 
 
5
 
(c) 1995 Innobase Oy
6
 
 
7
 
Created 9/6/1995 Heikki Tuuri
8
 
*******************************************************/
9
 
#ifndef os0sync_h
10
 
#define os0sync_h
11
 
 
12
 
#include "univ.i"
13
 
#include "ut0lst.h"
14
 
 
15
 
#ifdef __WIN__
16
 
 
17
 
#define os_fast_mutex_t CRITICAL_SECTION
18
 
 
19
 
typedef HANDLE          os_native_event_t;
20
 
 
21
 
typedef struct os_event_struct  os_event_struct_t;
22
 
typedef os_event_struct_t*      os_event_t;
23
 
 
24
 
struct os_event_struct {
25
 
        os_native_event_t                 handle;
26
 
                                        /* Windows event */
27
 
        UT_LIST_NODE_T(os_event_struct_t) os_event_list;
28
 
                                        /* list of all created events */
29
 
};
30
 
#else
31
 
typedef pthread_mutex_t os_fast_mutex_t;
32
 
 
33
 
typedef struct os_event_struct  os_event_struct_t;
34
 
typedef os_event_struct_t*      os_event_t;
35
 
 
36
 
struct os_event_struct {
37
 
        os_fast_mutex_t os_mutex;       /* this mutex protects the next
38
 
                                        fields */
39
 
        ibool           is_set;         /* this is TRUE when the event is
40
 
                                        in the signaled state, i.e., a thread
41
 
                                        does not stop if it tries to wait for
42
 
                                        this event */
43
 
        ib_longlong     signal_count;   /* this is incremented each time
44
 
                                        the event becomes signaled */
45
 
        pthread_cond_t  cond_var;       /* condition variable is used in
46
 
                                        waiting for the event */
47
 
        UT_LIST_NODE_T(os_event_struct_t) os_event_list;
48
 
                                        /* list of all created events */
49
 
};
50
 
#endif
51
 
 
52
 
typedef struct os_mutex_struct  os_mutex_str_t;
53
 
typedef os_mutex_str_t*         os_mutex_t;
54
 
 
55
 
#define OS_SYNC_INFINITE_TIME   ((ulint)(-1))
56
 
 
57
 
#define OS_SYNC_TIME_EXCEEDED   1
58
 
 
59
 
/* Mutex protecting counts and the event and OS 'slow' mutex lists */
60
 
extern os_mutex_t       os_sync_mutex;
61
 
 
62
 
/* This is incremented by 1 in os_thread_create and decremented by 1 in
63
 
os_thread_exit */
64
 
extern ulint            os_thread_count;
65
 
 
66
 
extern ulint            os_event_count;
67
 
extern ulint            os_mutex_count;
68
 
extern ulint            os_fast_mutex_count;
69
 
 
70
 
/*************************************************************
71
 
Initializes global event and OS 'slow' mutex lists. */
72
 
 
73
 
void
74
 
os_sync_init(void);
75
 
/*==============*/
76
 
/*************************************************************
77
 
Frees created events and OS 'slow' mutexes. */
78
 
 
79
 
void
80
 
os_sync_free(void);
81
 
/*==============*/
82
 
/*************************************************************
83
 
Creates an event semaphore, i.e., a semaphore which may just have two states:
84
 
signaled and nonsignaled. The created event is manual reset: it must be reset
85
 
explicitly by calling sync_os_reset_event. */
86
 
 
87
 
os_event_t
88
 
os_event_create(
89
 
/*============*/
90
 
                                /* out: the event handle */
91
 
        const char*     name);  /* in: the name of the event, if NULL
92
 
                                the event is created without a name */
93
 
#ifdef __WIN__
94
 
/*************************************************************
95
 
Creates an auto-reset event semaphore, i.e., an event which is automatically
96
 
reset when a single thread is released. Works only in Windows. */
97
 
 
98
 
os_event_t
99
 
os_event_create_auto(
100
 
/*=================*/
101
 
                                /* out: the event handle */
102
 
        const char*     name);  /* in: the name of the event, if NULL
103
 
                                the event is created without a name */
104
 
#endif
105
 
/**************************************************************
106
 
Sets an event semaphore to the signaled state: lets waiting threads
107
 
proceed. */
108
 
 
109
 
void
110
 
os_event_set(
111
 
/*=========*/
112
 
        os_event_t      event); /* in: event to set */
113
 
/**************************************************************
114
 
Resets an event semaphore to the nonsignaled state. Waiting threads will
115
 
stop to wait for the event. */
116
 
 
117
 
void
118
 
os_event_reset(
119
 
/*===========*/
120
 
        os_event_t      event); /* in: event to reset */
121
 
/**************************************************************
122
 
Frees an event object. */
123
 
 
124
 
void
125
 
os_event_free(
126
 
/*==========*/
127
 
        os_event_t      event); /* in: event to free */
128
 
/**************************************************************
129
 
Waits for an event object until it is in the signaled state. If
130
 
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
131
 
waiting thread when the event becomes signaled (or immediately if the
132
 
event is already in the signaled state). */
133
 
 
134
 
void
135
 
os_event_wait(
136
 
/*==========*/
137
 
        os_event_t      event); /* in: event to wait */
138
 
/**************************************************************
139
 
Waits for an event object until it is in the signaled state or
140
 
a timeout is exceeded. In Unix the timeout is always infinite. */
141
 
 
142
 
ulint
143
 
os_event_wait_time(
144
 
/*===============*/
145
 
                                /* out: 0 if success,
146
 
                                OS_SYNC_TIME_EXCEEDED if timeout
147
 
                                was exceeded */
148
 
        os_event_t      event,  /* in: event to wait */
149
 
        ulint           time);  /* in: timeout in microseconds, or
150
 
                                OS_SYNC_INFINITE_TIME */
151
 
#ifdef __WIN__
152
 
/**************************************************************
153
 
Waits for any event in an OS native event array. Returns if even a single
154
 
one is signaled or becomes signaled. */
155
 
 
156
 
ulint
157
 
os_event_wait_multiple(
158
 
/*===================*/
159
 
                                        /* out: index of the event
160
 
                                        which was signaled */
161
 
        ulint                   n,      /* in: number of events in the
162
 
                                        array */
163
 
        os_native_event_t*      native_event_array);
164
 
                                        /* in: pointer to an array of event
165
 
                                        handles */
166
 
#endif
167
 
/*************************************************************
168
 
Creates an operating system mutex semaphore. Because these are slow, the
169
 
mutex semaphore of InnoDB itself (mutex_t) should be used where possible. */
170
 
 
171
 
os_mutex_t
172
 
os_mutex_create(
173
 
/*============*/
174
 
                                /* out: the mutex handle */
175
 
        const char*     name);  /* in: the name of the mutex, if NULL
176
 
                                the mutex is created without a name */
177
 
/**************************************************************
178
 
Acquires ownership of a mutex semaphore. */
179
 
 
180
 
void
181
 
os_mutex_enter(
182
 
/*===========*/
183
 
        os_mutex_t      mutex); /* in: mutex to acquire */
184
 
/**************************************************************
185
 
Releases ownership of a mutex. */
186
 
 
187
 
void
188
 
os_mutex_exit(
189
 
/*==========*/
190
 
        os_mutex_t      mutex); /* in: mutex to release */
191
 
/**************************************************************
192
 
Frees an mutex object. */
193
 
 
194
 
void
195
 
os_mutex_free(
196
 
/*==========*/
197
 
        os_mutex_t      mutex); /* in: mutex to free */
198
 
/**************************************************************
199
 
Acquires ownership of a fast mutex. Currently in Windows this is the same
200
 
as os_fast_mutex_lock! */
201
 
UNIV_INLINE
202
 
ulint
203
 
os_fast_mutex_trylock(
204
 
/*==================*/
205
 
                                                /* out: 0 if success, != 0 if
206
 
                                                was reserved by another
207
 
                                                thread */
208
 
        os_fast_mutex_t*        fast_mutex);    /* in: mutex to acquire */
209
 
/**************************************************************
210
 
Releases ownership of a fast mutex. */
211
 
 
212
 
void
213
 
os_fast_mutex_unlock(
214
 
/*=================*/
215
 
        os_fast_mutex_t*        fast_mutex);    /* in: mutex to release */
216
 
/*************************************************************
217
 
Initializes an operating system fast mutex semaphore. */
218
 
 
219
 
void
220
 
os_fast_mutex_init(
221
 
/*===============*/
222
 
        os_fast_mutex_t*        fast_mutex);    /* in: fast mutex */
223
 
/**************************************************************
224
 
Acquires ownership of a fast mutex. */
225
 
 
226
 
void
227
 
os_fast_mutex_lock(
228
 
/*===============*/
229
 
        os_fast_mutex_t*        fast_mutex);    /* in: mutex to acquire */
230
 
/**************************************************************
231
 
Frees an mutex object. */
232
 
 
233
 
void
234
 
os_fast_mutex_free(
235
 
/*===============*/
236
 
        os_fast_mutex_t*        fast_mutex);    /* in: mutex to free */
237
 
 
238
 
#ifndef UNIV_NONINL
239
 
#include "os0sync.ic"
240
 
#endif
241
 
 
242
 
#endif