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