~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/scheduler.cc

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
  Implementation for the thread scheduler
18
18
*/
19
19
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <libdrizzle/libdrizzle.h>
 
20
#ifdef USE_PRAGMA_INTERFACE
 
21
#pragma implementation
 
22
#endif
 
23
 
 
24
#include <mysql_priv.h>
22
25
#include "event.h"
23
26
 
24
27
 
28
31
 */
29
32
 
30
33
static bool init_dummy(void) {return 0;}
31
 
static void post_kill_dummy(THD *thd __attribute__((unused))) {}
 
34
static void post_kill_dummy(THD *thd __attribute__((__unused__))) {}
32
35
static void end_dummy(void) {}
33
 
static bool end_thread_dummy(THD *thd __attribute__((unused)),
34
 
                             bool cache_thread __attribute__((unused)))
 
36
static bool end_thread_dummy(THD *thd __attribute__((__unused__)),
 
37
                             bool cache_thread __attribute__((__unused__)))
35
38
{ return 0; }
36
39
 
37
40
/*
47
50
   end_thread(end_thread_dummy), end(end_dummy)
48
51
{}
49
52
 
50
 
static uint32_t created_threads, killed_threads;
 
53
static uint created_threads, killed_threads;
51
54
static bool kill_pool_threads;
52
55
 
53
56
static struct event thd_add_event;
101
104
 
102
105
thd_scheduler::thd_scheduler()
103
106
  : logged_in(false), io_event(NULL), thread_attached(false)
104
 
{
 
107
{  
105
108
  dbug_explain_buf[0]= 0;
106
109
}
107
110
 
108
111
 
109
112
thd_scheduler::~thd_scheduler()
110
113
{
111
 
  free(io_event);
 
114
  my_free(io_event, MYF(MY_ALLOW_ZERO_PTR));
112
115
}
113
116
 
114
117
 
115
 
thd_scheduler::thd_scheduler(const thd_scheduler&)
116
 
  : logged_in(false), io_event(NULL), thread_attached(false)
117
 
{}
118
 
 
119
 
void thd_scheduler::operator=(const thd_scheduler&)
120
 
{}
121
 
 
122
118
bool thd_scheduler::init(THD *parent_thd)
123
119
{
124
120
  io_event=
126
122
    
127
123
  if (!io_event)
128
124
  {
129
 
    sql_print_error(_("Memory allocation error in thd_scheduler::init\n"));
 
125
    sql_print_error("Memory allocation error in thd_scheduler::init\n");
130
126
    return true;
131
127
  }
132
128
  
133
 
  event_set(io_event, net_get_sd(&(parent_thd->net)), EV_READ, 
 
129
  event_set(io_event, parent_thd->net.vio->sd, EV_READ, 
134
130
            libevent_io_callback, (void*)parent_thd);
135
131
    
136
132
  list.data= parent_thd;
203
199
 
204
200
static bool libevent_init(void)
205
201
{
206
 
  uint32_t i;
 
202
  uint i;
207
203
 
208
204
  event_init();
209
205
  
217
213
  /* set up the pipe used to add new thds to the event pool */
218
214
  if (init_pipe(thd_add_pipe))
219
215
  {
220
 
    sql_print_error(_("init_pipe(thd_add_pipe) error in libevent_init\n"));
 
216
    sql_print_error("init_pipe(thd_add_pipe) error in libevent_init\n");
221
217
    return(1);
222
218
  }
223
219
  /* set up the pipe used to kill thds in the event queue */
224
220
  if (init_pipe(thd_kill_pipe))
225
221
  {
226
 
    sql_print_error(_("init_pipe(thd_kill_pipe) error in libevent_init\n"));
 
222
    sql_print_error("init_pipe(thd_kill_pipe) error in libevent_init\n");
227
223
    close(thd_add_pipe[0]);
228
224
    close(thd_add_pipe[1]);
229
225
    return(1);
235
231
 
236
232
 if (event_add(&thd_add_event, NULL) || event_add(&thd_kill_event, NULL))
237
233
 {
238
 
   sql_print_error(_("thd_add_event event_add error in libevent_init\n"));
 
234
   sql_print_error("thd_add_event event_add error in libevent_init\n");
239
235
   libevent_end();
240
236
   return(1);
241
237
   
251
247
    if ((error= pthread_create(&thread, &connection_attrib,
252
248
                               libevent_thread_proc, 0)))
253
249
    {
254
 
      sql_print_error(_("Can't create completion port thread (error %d)"),
 
250
      sql_print_error("Can't create completion port thread (error %d)",
255
251
                      error);
256
252
      pthread_mutex_unlock(&LOCK_thread_count);
257
253
      libevent_end();                      // Cleanup
364
360
      /* Add to libevent */
365
361
      if (event_add(thd->scheduler.io_event, NULL))
366
362
      {
367
 
        sql_print_error(_("event_add error in libevent_add_thd_callback\n"));
 
363
        sql_print_error("event_add error in libevent_add_thd_callback\n");
368
364
        libevent_connection_close(thd);
369
365
      } 
370
366
      else
390
386
{
391
387
  if (thd->scheduler.init(thd))
392
388
  {
393
 
    sql_print_error(_("Scheduler init error in libevent_add_new_connection\n"));
 
389
    sql_print_error("Scheduler init error in libevent_add_new_connection\n");
394
390
    pthread_mutex_unlock(&LOCK_thread_count);
395
391
    libevent_connection_close(thd);
396
392
    return;
437
433
{
438
434
  thd->killed= THD::KILL_CONNECTION;          // Avoid error messages
439
435
 
440
 
  if (net_get_sd(&(thd->net)) >= 0)                  // not already closed
 
436
  if (thd->net.vio->sd >= 0)                  // not already closed
441
437
  {
442
438
    end_connection(thd);
443
439
    close_connection(thd, 0, 1);
456
452
 
457
453
static bool libevent_should_close_connection(THD* thd)
458
454
{
459
 
  return net_should_close(&(thd->net)) ||
 
455
  return thd->net.error ||
 
456
         thd->net.vio == 0 ||
460
457
         thd->killed == THD::KILL_CONNECTION;
461
458
}
462
459
 
466
463
  These procs only return/terminate on shutdown (kill_pool_threads == true).
467
464
*/
468
465
 
469
 
pthread_handler_t libevent_thread_proc(void *arg __attribute__((unused)))
 
466
pthread_handler_t libevent_thread_proc(void *arg __attribute__((__unused__)))
470
467
{
471
468
  if (init_new_connection_handler_thread())
472
469
  {
473
470
    my_thread_global_end();
474
 
    sql_print_error(_("libevent_thread_proc: my_thread_init() failed\n"));
 
471
    sql_print_error("libevent_thread_proc: my_thread_init() failed\n");
475
472
    exit(1);
476
473
  }
477
474
 
579
576
    Note: we cannot add for event processing because the whole request might
580
577
    already be buffered and we wouldn't receive an event.
581
578
  */
582
 
  if (net_more_data(&(thd->net)))
 
579
  if (thd->net.vio == 0 || thd->net.vio->read_pos < thd->net.vio->read_end)
583
580
    return true;
584
581
  
585
582
  thd->scheduler.thread_detach();