~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/srv/srv0que.c

  • Committer: Brian Aker
  • Date: 2009-03-25 18:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 963.
  • Revision ID: brian@tangent.org-20090325182415-opf2720c1hidtfgk
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
old lock system).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1996, 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
Server query execution
 
21
 
 
22
Created 6/5/1996 Heikki Tuuri
 
23
*******************************************************/
 
24
 
 
25
#include "srv0que.h"
 
26
 
 
27
#include "srv0srv.h"
 
28
#include "sync0sync.h"
 
29
#include "os0thread.h"
 
30
#include "usr0sess.h"
 
31
#include "que0que.h"
 
32
 
 
33
/**************************************************************************
 
34
Checks if there is work to do in the server task queue. If there is, the
 
35
thread starts processing a task. Before leaving, it again checks the task
 
36
queue and picks a new task if any exists. This is called by a SRV_WORKER
 
37
thread. */
 
38
UNIV_INTERN
 
39
void
 
40
srv_que_task_queue_check(void)
 
41
/*==========================*/
 
42
{
 
43
        que_thr_t*      thr;
 
44
 
 
45
        for (;;) {
 
46
                mutex_enter(&kernel_mutex);
 
47
 
 
48
                thr = UT_LIST_GET_FIRST(srv_sys->tasks);
 
49
 
 
50
                if (thr == NULL) {
 
51
                        mutex_exit(&kernel_mutex);
 
52
 
 
53
                        return;
 
54
                }
 
55
 
 
56
                UT_LIST_REMOVE(queue, srv_sys->tasks, thr);
 
57
 
 
58
                mutex_exit(&kernel_mutex);
 
59
 
 
60
                que_run_threads(thr);
 
61
        }
 
62
}
 
63
 
 
64
/**************************************************************************
 
65
Performs round-robin on the server tasks. This is called by a SRV_WORKER
 
66
thread every second or so. */
 
67
UNIV_INTERN
 
68
que_thr_t*
 
69
srv_que_round_robin(
 
70
/*================*/
 
71
                                /* out: the new (may be == thr) query thread
 
72
                                to run */
 
73
        que_thr_t*      thr)    /* in: query thread */
 
74
{
 
75
        que_thr_t*      new_thr;
 
76
 
 
77
        ut_ad(thr);
 
78
        ut_ad(thr->state == QUE_THR_RUNNING);
 
79
 
 
80
        mutex_enter(&kernel_mutex);
 
81
 
 
82
        UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
 
83
 
 
84
        new_thr = UT_LIST_GET_FIRST(srv_sys->tasks);
 
85
 
 
86
        mutex_exit(&kernel_mutex);
 
87
 
 
88
        return(new_thr);
 
89
}
 
90
 
 
91
/**************************************************************************
 
92
Enqueues a task to server task queue and releases a worker thread, if there
 
93
is a suspended one. */
 
94
UNIV_INTERN
 
95
void
 
96
srv_que_task_enqueue_low(
 
97
/*=====================*/
 
98
        que_thr_t*      thr)    /* in: query thread */
 
99
{
 
100
        ut_ad(thr);
 
101
        ut_ad(mutex_own(&kernel_mutex));
 
102
 
 
103
        UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
 
104
 
 
105
        srv_release_threads(SRV_WORKER, 1);
 
106
}
 
107
 
 
108
/**************************************************************************
 
109
Enqueues a task to server task queue and releases a worker thread, if there
 
110
is a suspended one. */
 
111
UNIV_INTERN
 
112
void
 
113
srv_que_task_enqueue(
 
114
/*=================*/
 
115
        que_thr_t*      thr)    /* in: query thread */
 
116
{
 
117
        ut_ad(thr);
 
118
 
 
119
        ut_a(0);        /* Under MySQL this is never called */
 
120
 
 
121
        mutex_enter(&kernel_mutex);
 
122
 
 
123
        srv_que_task_enqueue_low(thr);
 
124
 
 
125
        mutex_exit(&kernel_mutex);
 
126
}