~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/scheduler.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 03:40:03 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020034003-t2dcnl0ayr2ymm8k
THD -> Session rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 */
29
29
 
30
30
static bool init_dummy(void) {return 0;}
31
 
static void post_kill_dummy(THD *thd __attribute__((unused))) {}
 
31
static void post_kill_dummy(Session *thd __attribute__((unused))) {}
32
32
static void end_dummy(void) {}
33
 
static bool end_thread_dummy(THD *thd __attribute__((unused)),
 
33
static bool end_thread_dummy(Session *thd __attribute__((unused)),
34
34
                             bool cache_thread __attribute__((unused)))
35
35
{ return 0; }
36
36
 
69
69
 
70
70
pthread_handler_t libevent_thread_proc(void *arg);
71
71
static void libevent_end();
72
 
static bool libevent_needs_immediate_processing(THD *thd);
73
 
static void libevent_connection_close(THD *thd);
74
 
static bool libevent_should_close_connection(THD* thd);
75
 
static void libevent_thd_add(THD* thd);
 
72
static bool libevent_needs_immediate_processing(Session *thd);
 
73
static void libevent_connection_close(Session *thd);
 
74
static bool libevent_should_close_connection(Session* thd);
 
75
static void libevent_thd_add(Session* thd);
76
76
void libevent_io_callback(int Fd, short Operation, void *ctx);
77
77
void libevent_add_thd_callback(int Fd, short Operation, void *ctx);
78
78
void libevent_kill_thd_callback(int Fd, short Operation, void *ctx);
95
95
 
96
96
 
97
97
/*
98
 
  thd_scheduler keeps the link between THD and events.
99
 
  It's embedded in the THD class.
 
98
  thd_scheduler keeps the link between Session and events.
 
99
  It's embedded in the Session class.
100
100
*/
101
101
 
102
102
thd_scheduler::thd_scheduler()
118
118
void thd_scheduler::operator=(const thd_scheduler&)
119
119
{}
120
120
 
121
 
bool thd_scheduler::init(THD *parent_thd)
 
121
bool thd_scheduler::init(Session *parent_thd)
122
122
{
123
123
  io_event=
124
124
    (struct event*)my_malloc(sizeof(*io_event),MYF(MY_ZEROFILL|MY_WME));
145
145
bool thd_scheduler::thread_attach()
146
146
{
147
147
  assert(!thread_attached);
148
 
  THD* thd = (THD*)list.data;
 
148
  Session* thd = (Session*)list.data;
149
149
  if (libevent_should_close_connection(thd) ||
150
150
      setup_connection_thread_globals(thd))
151
151
  {
167
167
{
168
168
  if (thread_attached)
169
169
  {
170
 
    THD* thd = (THD*)list.data;
 
170
    Session* thd = (Session*)list.data;
171
171
    thd->mysys_var= NULL;
172
172
    thread_attached= false;
173
173
  }
267
267
void libevent_io_callback(int, short, void *ctx)
268
268
{    
269
269
  safe_mutex_assert_owner(&LOCK_event_loop);
270
 
  THD *thd= (THD*)ctx;
 
270
  Session *thd= (Session*)ctx;
271
271
  thds_waiting_for_io= list_delete(thds_waiting_for_io, &thd->scheduler.list);
272
272
  thds_need_processing= list_add(thds_need_processing, &thd->scheduler.list);
273
273
}
291
291
  LIST* list= thds_waiting_for_io;
292
292
  while (list)
293
293
  {
294
 
    THD *thd= (THD*)list->data;
 
294
    Session *thd= (Session*)list->data;
295
295
    list= list_rest(list);
296
 
    if (thd->killed == THD::KILL_CONNECTION)
 
296
    if (thd->killed == Session::KILL_CONNECTION)
297
297
    {
298
298
      /*
299
299
        Delete from libevent and add to the processing queue.
330
330
  while (thds_need_adding)
331
331
  {
332
332
    /* pop the first thd off the list */
333
 
    THD* thd= (THD*)thds_need_adding->data;
 
333
    Session* thd= (Session*)thds_need_adding->data;
334
334
    thds_need_adding= list_delete(thds_need_adding, thds_need_adding);
335
335
 
336
336
    pthread_mutex_unlock(&LOCK_thd_add);
371
371
    LOCK_thread_count is locked on entry. This function MUST unlock it!
372
372
*/
373
373
 
374
 
static void libevent_add_connection(THD *thd)
 
374
static void libevent_add_connection(Session *thd)
375
375
{
376
376
  if (thd->scheduler.init(thd))
377
377
  {
391
391
/**
392
392
  @brief Signal a waiting connection it's time to die.
393
393
 
394
 
  @details This function will signal libevent the THD should be killed.
395
 
    Either the global LOCK_thd_count or the THD's LOCK_delete must be locked
 
394
  @details This function will signal libevent the Session should be killed.
 
395
    Either the global LOCK_thd_count or the Session's LOCK_delete must be locked
396
396
    upon entry.
397
397
 
398
398
  @param[in]  thd The connection to kill
399
399
*/
400
400
 
401
 
static void libevent_post_kill_notification(THD *)
 
401
static void libevent_post_kill_notification(Session *)
402
402
{
403
403
  /*
404
 
    Note, we just wake up libevent with an event that a THD should be killed,
 
404
    Note, we just wake up libevent with an event that a Session should be killed,
405
405
    It will search its list of thds for thd->killed ==  KILL_CONNECTION to
406
 
    find the THDs it should kill.
 
406
    find the Sessions it should kill.
407
407
    
408
408
    So we don't actually tell it which one and we don't actually use the
409
 
    THD being passed to us, but that's just a design detail that could change
 
409
    Session being passed to us, but that's just a design detail that could change
410
410
    later.
411
411
  */
412
412
  char c= 0;
418
418
  Close and delete a connection.
419
419
*/
420
420
 
421
 
static void libevent_connection_close(THD *thd)
 
421
static void libevent_connection_close(Session *thd)
422
422
{
423
 
  thd->killed= THD::KILL_CONNECTION;          // Avoid error messages
 
423
  thd->killed= Session::KILL_CONNECTION;          // Avoid error messages
424
424
 
425
425
  if (net_get_sd(&(thd->net)) >= 0)                  // not already closed
426
426
  {
436
436
 
437
437
 
438
438
/*
439
 
  Returns true if we should close and delete a THD connection.
 
439
  Returns true if we should close and delete a Session connection.
440
440
*/
441
441
 
442
 
static bool libevent_should_close_connection(THD* thd)
 
442
static bool libevent_should_close_connection(Session* thd)
443
443
{
444
444
  return net_should_close(&(thd->net)) ||
445
 
         thd->killed == THD::KILL_CONNECTION;
 
445
         thd->killed == Session::KILL_CONNECTION;
446
446
}
447
447
 
448
448
 
472
472
  
473
473
  for (;;)
474
474
  {
475
 
    THD *thd= NULL;
 
475
    Session *thd= NULL;
476
476
    (void) pthread_mutex_lock(&LOCK_event_loop);
477
477
    
478
478
    /* get thd(s) to process */
488
488
    }
489
489
    
490
490
    /* pop the first thd off the list */
491
 
    thd= (THD*)thds_need_processing->data;
 
491
    thd= (Session*)thds_need_processing->data;
492
492
    thds_need_processing= list_delete(thds_need_processing,
493
493
                                      thds_need_processing);
494
494
    
551
551
  instead it's queued for libevent processing or closed,
552
552
*/
553
553
 
554
 
static bool libevent_needs_immediate_processing(THD *thd)
 
554
static bool libevent_needs_immediate_processing(Session *thd)
555
555
{
556
556
  if (libevent_should_close_connection(thd))
557
557
  {
574
574
 
575
575
 
576
576
/*
577
 
  Adds a THD to queued for libevent processing.
 
577
  Adds a Session to queued for libevent processing.
578
578
  
579
579
  This call does not actually register the event with libevent.
580
 
  Instead, it places the THD onto a queue and signals libevent by writing
 
580
  Instead, it places the Session onto a queue and signals libevent by writing
581
581
  a byte into thd_add_pipe, which will cause our libevent_add_thd_callback to
582
 
  be invoked which will find the THD on the queue and add it to libevent.
 
582
  be invoked which will find the Session on the queue and add it to libevent.
583
583
*/
584
584
 
585
 
static void libevent_thd_add(THD* thd)
 
585
static void libevent_thd_add(Session* thd)
586
586
{
587
587
  char c=0;
588
588
  pthread_mutex_lock(&LOCK_thd_add);