automatically start the threadpool on demand, similar to NoBug

but the difference is: threadpool comes up application init i.e. at the begin of main(),
while NoBug comes up in static init already.
This commit is contained in:
Fischlurch 2010-01-24 15:48:48 +01:00
parent 93af4ed017
commit ede06e63d5
6 changed files with 111 additions and 20 deletions

View file

@ -34,6 +34,7 @@ liblumierabackend_la_SOURCES = \
$(liblumierabackend_la_srcdir)/mmap.c \
$(liblumierabackend_la_srcdir)/mmapings.c \
$(liblumierabackend_la_srcdir)/mmapcache.c \
$(liblumierabackend_la_srcdir)/threadpool-init.cpp \
$(liblumierabackend_la_srcdir)/enginefacade.cpp \
$(liblumierabackend_la_srcdir)/scriptrunnerfacade.cpp \
$(liblumierabackend_la_srcdir)/netnodefacade.cpp

View file

@ -33,6 +33,7 @@
extern "C" {
#include "backend/threads.h"
}
#include "backend/threadpool-init.hpp"
#include <tr1/functional>
#include <boost/noncopyable.hpp>

View file

@ -0,0 +1,49 @@
/*
ThreadpoolInit - pull up the Thread management automagically at application initialisation
Copyright (C) Lumiera.org
2010, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "backend/threadpool-init.hpp"
namespace lumiera {
void
initialise_Threadpool ()
{
lumiera_threadpool_init();
////////////////////////////////////////////////////////////////////////TODO: a better way to detect Alpha/beta builds
#ifdef DEBUG
static uint callCount = 0;
ASSERT ( 0 == callCount++ );
#endif
}
void
shutdown_Threadpool ()
{
lumiera_threadpool_destroy();
}
}

View file

@ -0,0 +1,59 @@
/*
THREADPOOL-INIT.hpp - pull up the Thread management automagically at application initialisation
Copyright (C) Lumiera.org
2010, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file threadpool-init.hpp
** Automatically bring up the Threading management and Threadpool in the backend.
** This works by registering a lifecycle callback, which is activated at the start
** of main or when running the testsuite. Similarly, a shutdown hook is registered.
**
** @todo as of 1/10 it is not clear if this will be the final solution.
** Alternatively, we may rely on a subsystem "backend" or "threadpool"
**
** @see threads.h
** @see thread-wrapper.hpp
**
*/
#ifndef BACKEND_THREADPOOL_INIT_H
#define BACKEND_THREADPOOL_INIT_H
#include "include/lifecycle.h"
extern "C" {
#include "backend/threads.h"
}
namespace lumiera {
void initialise_Threadpool ();
void shutdown_Threadpool ();
namespace {
LifecycleHook trigger_1_ (ON_GLOBAL_INIT, &initialise_Threadpool);
LifecycleHook trigger_2_ (ON_GLOBAL_SHUTDOWN, &shutdown_Threadpool);
} }
#endif /* BACKEND_THREADPOOL_INIT_H */

View file

@ -120,16 +120,6 @@ namespace test {
VERIFY_ERROR(SPECIAL, newThread.join() );
}
public:
ThreadWrapperJoin_test()
{ lumiera_threadpool_init(); }
~ThreadWrapperJoin_test()
{ lumiera_threadpool_destroy(); }
};

View file

@ -56,8 +56,7 @@ namespace backend {
struct TestThread
: Thread
, Sync<NonrecursiveLock_NoWait> // note: Thread isnt derived from sync anymore, if we want to lock values this needs to be done at per client base
// an alternative would be to use the threads .sync() and lumiera_thread_sync() where approbiate
, Sync<NonrecursiveLock_NoWait> // using dedicated locking for this test
{
TestThread()
: Thread("test Thread creation",
@ -106,14 +105,6 @@ namespace backend {
ASSERT (0 < sum);
ASSERT (sum==checksum);
}
public:
ThreadWrapper_test()
{ lumiera_threadpool_init(); }
~ThreadWrapper_test()
{ lumiera_threadpool_destroy(); }
};