~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pool_of_threads/pool_of_threads.cc

  • Committer: Brian Aker
  • Date: 2009-03-11 22:01:46 UTC
  • mto: This revision was merged to the branch mainline in revision 930.
  • Revision ID: brian@tangent.org-20090311220146-7qenr20k6v0970jq
Push thread count out to the scheduler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using namespace std;
30
30
 
31
 
static uint32_t created_threads, killed_threads;
32
 
static bool kill_pool_threads;
 
31
static volatile uint32_t created_threads= 0;
 
32
static volatile bool kill_pool_threads= false;
33
33
 
34
34
static int deinit(void *);
35
35
 
95
95
 
96
96
static bool libevent_init(void)
97
97
{
98
 
  uint32_t i;
 
98
  uint32_t x;
99
99
 
100
100
  event_init();
101
101
 
102
 
  created_threads= 0;
103
 
  killed_threads= 0;
104
 
  kill_pool_threads= false;
105
 
 
106
102
  pthread_mutex_init(&LOCK_event_loop, NULL);
107
103
  pthread_mutex_init(&LOCK_session_add, NULL);
108
104
 
133
129
 
134
130
 }
135
131
  /* Set up the thread pool */
136
 
  created_threads= killed_threads= 0;
137
132
  pthread_mutex_lock(&LOCK_thread_count);
138
133
 
139
 
  for (i= 0; i < size; i++)
 
134
  for (x= 0; x < size; x++)
140
135
  {
141
136
    pthread_t thread;
142
137
    int error;
470
465
        break;
471
466
      }
472
467
    } while (libevent_needs_immediate_processing(session));
 
468
 
 
469
    if (kill_pool_threads) /* the flag that we should die has been set */
 
470
      goto thread_exit;
473
471
  }
474
472
 
475
473
thread_exit:
476
474
  (void) pthread_mutex_lock(&LOCK_thread_count);
477
 
  killed_threads++;
 
475
  created_threads--;
478
476
  pthread_cond_broadcast(&COND_thread_count);
479
477
  (void) pthread_mutex_unlock(&LOCK_thread_count);
480
478
  my_thread_end();
481
479
  pthread_exit(0);
482
 
  return(0);                               /* purify: deadcode */
 
480
 
 
481
  return NULL;                               /* purify: deadcode */
483
482
}
484
483
 
485
484
 
546
545
  (void) pthread_mutex_lock(&LOCK_thread_count);
547
546
 
548
547
  kill_pool_threads= true;
549
 
  while (killed_threads != created_threads)
 
548
  while (created_threads)
550
549
  {
551
550
    /* wake up the event loop */
552
551
    char c= 0;
569
568
  return 0;
570
569
}
571
570
 
 
571
static uint32_t count_of_threads(void)
 
572
{
 
573
  return created_threads;
 
574
}
 
575
 
572
576
static int init(void *p)
573
577
{
574
578
  scheduling_st* func= (scheduling_st *)p;
577
581
  func->max_threads= size;
578
582
  func->post_kill_notification= post_kill_notification;
579
583
  func->add_connection= add_connection;
 
584
  func->count= count_of_threads;
580
585
 
581
586
  return (int)libevent_init();
582
587
}