mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / srv / srv0que.c
blobe2b4e217980dae0d323d43bd8d6120fa64c39a23
1 /******************************************************
2 Server query execution
4 (c) 1996 Innobase Oy
6 Created 6/5/1996 Heikki Tuuri
7 *******************************************************/
9 #include "srv0que.h"
11 #include "srv0srv.h"
12 #include "sync0sync.h"
13 #include "os0thread.h"
14 #include "usr0sess.h"
15 #include "que0que.h"
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. */
23 void
24 srv_que_task_queue_check(void)
25 /*==========================*/
27 que_thr_t* thr;
29 for (;;) {
30 mutex_enter(&kernel_mutex);
32 thr = UT_LIST_GET_FIRST(srv_sys->tasks);
34 if (thr == NULL) {
35 mutex_exit(&kernel_mutex);
37 return;
40 UT_LIST_REMOVE(queue, srv_sys->tasks, thr);
42 mutex_exit(&kernel_mutex);
44 que_run_threads(thr);
48 /**************************************************************************
49 Performs round-robin on the server tasks. This is called by a SRV_WORKER
50 thread every second or so. */
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 */
59 que_thr_t* new_thr;
61 ut_ad(thr);
62 ut_ad(thr->state == QUE_THR_RUNNING);
64 mutex_enter(&kernel_mutex);
66 UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
68 new_thr = UT_LIST_GET_FIRST(srv_sys->tasks);
70 mutex_exit(&kernel_mutex);
72 return(new_thr);
75 /**************************************************************************
76 Enqueues a task to server task queue and releases a worker thread, if there
77 is a suspended one. */
79 void
80 srv_que_task_enqueue_low(
81 /*=====================*/
82 que_thr_t* thr) /* in: query thread */
84 ut_ad(thr);
85 ut_ad(mutex_own(&kernel_mutex));
87 UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
89 srv_release_threads(SRV_WORKER, 1);
92 /**************************************************************************
93 Enqueues a task to server task queue and releases a worker thread, if there
94 is a suspended one. */
96 void
97 srv_que_task_enqueue(
98 /*=================*/
99 que_thr_t* thr) /* in: query thread */
101 ut_ad(thr);
103 ut_a(0); /* Under MySQL this is never called */
105 mutex_enter(&kernel_mutex);
107 srv_que_task_enqueue_low(thr);
109 mutex_exit(&kernel_mutex);