~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/sync0arr.h
 
1
/******************************************************
21
2
The wait array used in synchronization primitives
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 9/5/1995 Heikki Tuuri
24
7
*******************************************************/
25
8
 
31
14
#include "ut0mem.h"
32
15
#include "os0thread.h"
33
16
 
34
 
/** Synchronization wait array cell */
35
17
typedef struct sync_cell_struct         sync_cell_t;
36
 
/** Synchronization wait array */
37
18
typedef struct sync_array_struct        sync_array_t;
38
19
 
39
 
/** Parameters for sync_array_create() @{ */
40
 
#define SYNC_ARRAY_OS_MUTEX     1       /*!< protected by os_mutex_t */
41
 
#define SYNC_ARRAY_MUTEX        2       /*!< protected by mutex_t */
42
 
/* @} */
 
20
#define SYNC_ARRAY_OS_MUTEX     1
 
21
#define SYNC_ARRAY_MUTEX        2
43
22
 
44
 
/*******************************************************************//**
 
23
/***********************************************************************
45
24
Creates a synchronization wait array. It is protected by a mutex
46
25
which is automatically reserved when the functions operating on it
47
 
are called.
48
 
@return own: created wait array */
 
26
are called. */
49
27
UNIV_INTERN
50
28
sync_array_t*
51
29
sync_array_create(
52
30
/*==============*/
53
 
        ulint   n_cells,        /*!< in: number of cells in the array
 
31
                                /* out, own: created wait array */
 
32
        ulint   n_cells,        /* in: number of cells in the array
54
33
                                to create */
55
 
        ulint   protection);    /*!< in: either SYNC_ARRAY_OS_MUTEX or
 
34
        ulint   protection);    /* in: either SYNC_ARRAY_OS_MUTEX or
56
35
                                SYNC_ARRAY_MUTEX: determines the type
57
36
                                of mutex protecting the data structure */
58
 
/******************************************************************//**
 
37
/**********************************************************************
59
38
Frees the resources in a wait array. */
60
39
UNIV_INTERN
61
40
void
62
41
sync_array_free(
63
42
/*============*/
64
 
        sync_array_t*   arr);   /*!< in, own: sync wait array */
65
 
/******************************************************************//**
 
43
        sync_array_t*   arr);   /* in, own: sync wait array */
 
44
/**********************************************************************
66
45
Reserves a wait array cell for waiting for an object.
67
46
The event of the cell is reset to nonsignalled state. */
68
47
UNIV_INTERN
69
48
void
70
49
sync_array_reserve_cell(
71
50
/*====================*/
72
 
        sync_array_t*   arr,    /*!< in: wait array */
73
 
        void*           object, /*!< in: pointer to the object to wait for */
74
 
        ulint           type,   /*!< in: lock request type */
75
 
        const char*     file,   /*!< in: file where requested */
76
 
        ulint           line,   /*!< in: line where requested */
77
 
        ulint*          index); /*!< out: index of the reserved cell */
78
 
/******************************************************************//**
 
51
        sync_array_t*   arr,    /* in: wait array */
 
52
        void*           object, /* in: pointer to the object to wait for */
 
53
        ulint           type,   /* in: lock request type */
 
54
        const char*     file,   /* in: file where requested */
 
55
        ulint           line,   /* in: line where requested */
 
56
        ulint*          index); /* out: index of the reserved cell */
 
57
/**********************************************************************
79
58
This function should be called when a thread starts to wait on
80
59
a wait array cell. In the debug version this function checks
81
60
if the wait for a semaphore will result in a deadlock, in which
84
63
void
85
64
sync_array_wait_event(
86
65
/*==================*/
87
 
        sync_array_t*   arr,    /*!< in: wait array */
88
 
        ulint           index);  /*!< in: index of the reserved cell */
89
 
/******************************************************************//**
 
66
        sync_array_t*   arr,    /* in: wait array */
 
67
        ulint           index);  /* in: index of the reserved cell */
 
68
/**********************************************************************
90
69
Frees the cell. NOTE! sync_array_wait_event frees the cell
91
70
automatically! */
92
71
UNIV_INTERN
93
72
void
94
73
sync_array_free_cell(
95
74
/*=================*/
96
 
        sync_array_t*   arr,    /*!< in: wait array */
97
 
        ulint           index); /*!< in: index of the cell in array */
98
 
/**********************************************************************//**
 
75
        sync_array_t*   arr,    /* in: wait array */
 
76
        ulint           index); /* in: index of the cell in array */
 
77
/**************************************************************************
99
78
Note that one of the wait objects was signalled. */
100
79
UNIV_INTERN
101
80
void
102
81
sync_array_object_signalled(
103
82
/*========================*/
104
 
        sync_array_t*   arr);   /*!< in: wait array */
105
 
/**********************************************************************//**
 
83
        sync_array_t*   arr);   /* in: wait array */
 
84
/**************************************************************************
106
85
If the wakeup algorithm does not work perfectly at semaphore relases,
107
86
this function will do the waking (see the comment in mutex_exit). This
108
87
function should be called about every 1 second in the server. */
110
89
void
111
90
sync_arr_wake_threads_if_sema_free(void);
112
91
/*====================================*/
113
 
/**********************************************************************//**
114
 
Prints warnings of long semaphore waits to stderr.
115
 
@return TRUE if fatal semaphore wait threshold was exceeded */
 
92
/**************************************************************************
 
93
Prints warnings of long semaphore waits to stderr. */
116
94
UNIV_INTERN
117
95
ibool
118
96
sync_array_print_long_waits(void);
119
97
/*=============================*/
120
 
/********************************************************************//**
 
98
                        /* out: TRUE if fatal semaphore wait threshold
 
99
                        was exceeded */
 
100
/************************************************************************
121
101
Validates the integrity of the wait array. Checks
122
102
that the number of reserved cells equals the count variable. */
123
103
UNIV_INTERN
124
104
void
125
105
sync_array_validate(
126
106
/*================*/
127
 
        sync_array_t*   arr);   /*!< in: sync wait array */
128
 
/**********************************************************************//**
 
107
        sync_array_t*   arr);   /* in: sync wait array */
 
108
/**************************************************************************
129
109
Prints info of the wait array. */
130
110
UNIV_INTERN
131
111
void
132
112
sync_array_print_info(
133
113
/*==================*/
134
 
        FILE*           file,   /*!< in: file where to print */
135
 
        sync_array_t*   arr);   /*!< in: wait array */
 
114
        FILE*           file,   /* in: file where to print */
 
115
        sync_array_t*   arr);   /* in: wait array */
136
116
 
137
117
 
138
118
#ifndef UNIV_NONINL