~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: 2010-09-15 20:24:31 UTC
  • mto: (1766.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1767.
  • Revision ID: brian@tangent.org-20100915202431-wbrrl4vg6rzjvdiu
Adding opt for optional schedulers and making them --plugin-add only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
  char c;
210
210
  int count= 0;
211
211
 
212
 
  pthread_mutex_lock(&LOCK_session_add);
 
212
  LOCK_session_add.lock();
213
213
  while (! sessions_need_adding.empty())
214
214
  {
215
215
    /*
216
216
     Pop the first session off the queue 
217
217
    */
218
218
    Session* session= sessions_need_adding.front();
219
 
    pthread_mutex_unlock(&LOCK_session_add);
 
219
    LOCK_session_add.unlock();
220
220
 
221
221
    session_scheduler *sched= static_cast<session_scheduler *>(session->scheduler_arg);
222
222
    assert(sched);
244
244
      }
245
245
    }
246
246
 
247
 
    pthread_mutex_lock(&LOCK_session_add);
 
247
    LOCK_session_add.lock();
248
248
    /*
249
249
     Pop until this session is already processed
250
250
    */
260
260
    count++;
261
261
  }
262
262
  assert(count == 1);
263
 
  pthread_mutex_unlock(&LOCK_session_add);
 
263
  LOCK_session_add.unlock();
264
264
}
265
265
 
266
266
/**
336
336
  for (;;)
337
337
  {
338
338
    Session *session= NULL;
339
 
    (void) pthread_mutex_lock(&LOCK_event_loop);
 
339
    LOCK_event_loop.lock();
340
340
 
341
341
    /* get session(s) to process */
342
342
    while (sessions_need_processing.empty())
344
344
      if (kill_pool_threads)
345
345
      {
346
346
        /* the flag that we should die has been set */
347
 
        (void) pthread_mutex_unlock(&LOCK_event_loop);
 
347
        LOCK_event_loop.unlock();
348
348
        goto thread_exit;
349
349
      }
350
350
      event_loop(EVLOOP_ONCE);
355
355
    sessions_need_processing.pop();
356
356
    session_scheduler *sched= (session_scheduler *)session->scheduler_arg;
357
357
 
358
 
    (void) pthread_mutex_unlock(&LOCK_event_loop);
 
358
    LOCK_event_loop.lock();
359
359
 
360
360
    /* now we process the connection (session) */
361
361
 
471
471
void PoolOfThreadsScheduler::sessionAddToQueue(session_scheduler *sched)
472
472
{
473
473
  char c= 0;
474
 
  pthread_mutex_lock(&LOCK_session_add);
 
474
  boost::mutex::scoped_lock(LOCK_session_add);
475
475
  if (sessions_need_adding.empty())
476
476
  {
477
477
    /* notify libevent */
480
480
  }
481
481
  /* queue for libevent */
482
482
  sessions_need_adding.push(sched->session);
483
 
  pthread_mutex_unlock(&LOCK_session_add);
484
483
}
485
484
 
486
485
 
492
491
  (void) pthread_attr_init(&attr);
493
492
  (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
494
493
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
495
 
 
496
 
  pthread_mutex_init(&LOCK_session_add, NULL);
497
 
  pthread_mutex_init(&LOCK_event_loop, NULL);
498
 
 
499
494
}
500
495
 
501
496
 
524
519
  close(session_kill_pipe[0]);
525
520
  close(session_kill_pipe[1]);
526
521
 
527
 
  (void) pthread_mutex_destroy(&LOCK_event_loop);
528
 
  (void) pthread_mutex_destroy(&LOCK_session_add);
529
522
  (void) pthread_attr_destroy(&attr);
530
523
}
531
524