~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduler.cc

  • Committer: Andy Lester
  • Date: 2008-08-09 05:13:22 UTC
  • mto: (266.1.29 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 287.
  • Revision ID: andy@petdance.com-20080809051322-dzas70no2mv6c9i5
removed incorrect comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
 
20
20
#include <drizzled/server_includes.h>
21
 
#include <libdrizzle/libdrizzle.h>
22
21
#include "event.h"
23
22
 
24
23
 
47
46
   end_thread(end_thread_dummy), end(end_dummy)
48
47
{}
49
48
 
50
 
static uint32_t created_threads, killed_threads;
 
49
static uint created_threads, killed_threads;
51
50
static bool kill_pool_threads;
52
51
 
53
52
static struct event thd_add_event;
101
100
 
102
101
thd_scheduler::thd_scheduler()
103
102
  : logged_in(false), io_event(NULL), thread_attached(false)
104
 
{
 
103
{  
105
104
  dbug_explain_buf[0]= 0;
106
105
}
107
106
 
108
107
 
109
108
thd_scheduler::~thd_scheduler()
110
109
{
111
 
  free(io_event);
 
110
  my_free(io_event, MYF(MY_ALLOW_ZERO_PTR));
112
111
}
113
112
 
114
113
 
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
114
bool thd_scheduler::init(THD *parent_thd)
123
115
{
124
116
  io_event=
126
118
    
127
119
  if (!io_event)
128
120
  {
129
 
    sql_print_error(_("Memory allocation error in thd_scheduler::init\n"));
 
121
    sql_print_error("Memory allocation error in thd_scheduler::init\n");
130
122
    return true;
131
123
  }
132
124
  
133
 
  event_set(io_event, net_get_sd(&(parent_thd->net)), EV_READ, 
 
125
  event_set(io_event, parent_thd->net.vio->sd, EV_READ, 
134
126
            libevent_io_callback, (void*)parent_thd);
135
127
    
136
128
  list.data= parent_thd;
203
195
 
204
196
static bool libevent_init(void)
205
197
{
206
 
  uint32_t i;
 
198
  uint i;
207
199
 
208
200
  event_init();
209
201
  
217
209
  /* set up the pipe used to add new thds to the event pool */
218
210
  if (init_pipe(thd_add_pipe))
219
211
  {
220
 
    sql_print_error(_("init_pipe(thd_add_pipe) error in libevent_init\n"));
 
212
    sql_print_error("init_pipe(thd_add_pipe) error in libevent_init\n");
221
213
    return(1);
222
214
  }
223
215
  /* set up the pipe used to kill thds in the event queue */
224
216
  if (init_pipe(thd_kill_pipe))
225
217
  {
226
 
    sql_print_error(_("init_pipe(thd_kill_pipe) error in libevent_init\n"));
 
218
    sql_print_error("init_pipe(thd_kill_pipe) error in libevent_init\n");
227
219
    close(thd_add_pipe[0]);
228
220
    close(thd_add_pipe[1]);
229
221
    return(1);
235
227
 
236
228
 if (event_add(&thd_add_event, NULL) || event_add(&thd_kill_event, NULL))
237
229
 {
238
 
   sql_print_error(_("thd_add_event event_add error in libevent_init\n"));
 
230
   sql_print_error("thd_add_event event_add error in libevent_init\n");
239
231
   libevent_end();
240
232
   return(1);
241
233
   
251
243
    if ((error= pthread_create(&thread, &connection_attrib,
252
244
                               libevent_thread_proc, 0)))
253
245
    {
254
 
      sql_print_error(_("Can't create completion port thread (error %d)"),
 
246
      sql_print_error("Can't create completion port thread (error %d)",
255
247
                      error);
256
248
      pthread_mutex_unlock(&LOCK_thread_count);
257
249
      libevent_end();                      // Cleanup
364
356
      /* Add to libevent */
365
357
      if (event_add(thd->scheduler.io_event, NULL))
366
358
      {
367
 
        sql_print_error(_("event_add error in libevent_add_thd_callback\n"));
 
359
        sql_print_error("event_add error in libevent_add_thd_callback\n");
368
360
        libevent_connection_close(thd);
369
361
      } 
370
362
      else
390
382
{
391
383
  if (thd->scheduler.init(thd))
392
384
  {
393
 
    sql_print_error(_("Scheduler init error in libevent_add_new_connection\n"));
 
385
    sql_print_error("Scheduler init error in libevent_add_new_connection\n");
394
386
    pthread_mutex_unlock(&LOCK_thread_count);
395
387
    libevent_connection_close(thd);
396
388
    return;
437
429
{
438
430
  thd->killed= THD::KILL_CONNECTION;          // Avoid error messages
439
431
 
440
 
  if (net_get_sd(&(thd->net)) >= 0)                  // not already closed
 
432
  if (thd->net.vio->sd >= 0)                  // not already closed
441
433
  {
442
434
    end_connection(thd);
443
435
    close_connection(thd, 0, 1);
456
448
 
457
449
static bool libevent_should_close_connection(THD* thd)
458
450
{
459
 
  return net_should_close(&(thd->net)) ||
 
451
  return thd->net.error ||
 
452
         thd->net.vio == 0 ||
460
453
         thd->killed == THD::KILL_CONNECTION;
461
454
}
462
455
 
471
464
  if (init_new_connection_handler_thread())
472
465
  {
473
466
    my_thread_global_end();
474
 
    sql_print_error(_("libevent_thread_proc: my_thread_init() failed\n"));
 
467
    sql_print_error("libevent_thread_proc: my_thread_init() failed\n");
475
468
    exit(1);
476
469
  }
477
470
 
579
572
    Note: we cannot add for event processing because the whole request might
580
573
    already be buffered and we wouldn't receive an event.
581
574
  */
582
 
  if (net_more_data(&(thd->net)))
 
575
  if (thd->net.vio == 0 || thd->net.vio->read_pos < thd->net.vio->read_end)
583
576
    return true;
584
577
  
585
578
  thd->scheduler.thread_detach();