~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-04-13 16:22:40 UTC
  • mfrom: (971.1.78 mordred)
  • Revision ID: brian@gaz-20090413162240-ugi3gvhofmcuglzl
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <drizzled/gettext.h>
18
18
#include <drizzled/error.h>
19
19
#include <drizzled/plugin/scheduler.h>
20
 
#include <drizzled/serialize/serialize.h>
21
20
#include <drizzled/connect.h>
22
21
#include <drizzled/sql_parse.h>
23
22
#include <drizzled/session.h>
31
30
static volatile bool kill_pool_threads= false;
32
31
 
33
32
static volatile uint32_t created_threads= 0;
34
 
static int deinit(void *);
 
33
static int deinit(PluginRegistry &registry);
35
34
 
36
35
static struct event session_add_event;
37
36
static struct event session_kill_event;
364
363
   if (event_add(&session_add_event, NULL) || event_add(&session_kill_event, NULL))
365
364
   {
366
365
     errmsg_printf(ERRMSG_LVL_ERROR, _("session_add_event event_add error in libevent_init\n"));
367
 
     deinit(NULL);
368
366
     return true;
369
367
  
370
368
   }
380
378
        errmsg_printf(ERRMSG_LVL_ERROR, _("Can't create completion port thread (error %d)"),
381
379
                        error);
382
380
        pthread_mutex_unlock(&LOCK_thread_count);
383
 
        deinit(NULL);                      // Cleanup
384
381
        return true;
385
382
      }
386
383
    }
394
391
  }
395
392
}; 
396
393
 
 
394
 
 
395
class PoolOfThreadsFactory : public SchedulerFactory
 
396
{
 
397
public:
 
398
  PoolOfThreadsFactory() : SchedulerFactory("pool_of_threads") {}
 
399
  ~PoolOfThreadsFactory() { if (scheduler != NULL) delete scheduler; }
 
400
  Scheduler *operator() ()
 
401
  {
 
402
    if (scheduler == NULL)
 
403
    {
 
404
      Pool_of_threads_scheduler *pot= new Pool_of_threads_scheduler(size);
 
405
      if (pot->libevent_init())
 
406
      {
 
407
        delete pot;
 
408
        return NULL;
 
409
      }
 
410
      scheduler= pot;
 
411
    }
 
412
    return scheduler;
 
413
  }
 
414
};
 
415
 
397
416
/*
398
417
  Close and delete a connection.
399
418
*/
588
607
}
589
608
 
590
609
 
 
610
static PoolOfThreadsFactory *factory= NULL;
591
611
 
592
 
static int init(void *p)
 
612
static int init(PluginRegistry &registry)
593
613
{
594
614
  assert(size != 0);
595
615
 
596
 
  void **plugin= static_cast<void **>(p);
597
 
 
598
 
  Pool_of_threads_scheduler *sched=
599
 
    new Pool_of_threads_scheduler(size);
600
 
  if (sched->libevent_init())
601
 
  {
602
 
    delete sched;
603
 
    return 1;
604
 
  }
605
 
 
606
 
  *plugin= static_cast<void *>(sched);
 
616
  factory= new PoolOfThreadsFactory();
 
617
  registry.add(factory);
607
618
 
608
619
  return 0;
609
620
}
612
623
  Wait until all pool threads have been deleted for clean shutdown
613
624
*/
614
625
 
615
 
static int deinit(void *p)
 
626
static int deinit(PluginRegistry &registry)
616
627
{
617
 
  Scheduler *sched= static_cast<Scheduler *>(p);
618
 
  delete sched;
619
 
 
 
628
  if (factory)
 
629
  {
 
630
    registry.remove(factory);
 
631
    delete factory;
 
632
  }
620
633
  return 0;
621
634
}
622
635
 
636
649
 
637
650
drizzle_declare_plugin(pool_of_threads)
638
651
{
639
 
  DRIZZLE_SCHEDULING_PLUGIN,
640
652
  "pool_of_threads",
641
653
  "0.1",
642
654
  "Brian Aker",