diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am index 6b64b35f7..fbfbed33e 100644 --- a/src/backend/Makefile.am +++ b/src/backend/Makefile.am @@ -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 diff --git a/src/backend/thread-wrapper.hpp b/src/backend/thread-wrapper.hpp index 81e8cc83a..43cf9cab1 100644 --- a/src/backend/thread-wrapper.hpp +++ b/src/backend/thread-wrapper.hpp @@ -33,6 +33,7 @@ extern "C" { #include "backend/threads.h" } +#include "backend/threadpool-init.hpp" #include #include diff --git a/src/backend/threadpool-init.cpp b/src/backend/threadpool-init.cpp new file mode 100644 index 000000000..0f4bdaf90 --- /dev/null +++ b/src/backend/threadpool-init.cpp @@ -0,0 +1,49 @@ +/* + ThreadpoolInit - pull up the Thread management automagically at application initialisation + + Copyright (C) Lumiera.org + 2010, Hermann Vosseler + + 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(); + } +} + diff --git a/src/backend/threadpool-init.hpp b/src/backend/threadpool-init.hpp new file mode 100644 index 000000000..aebdb00aa --- /dev/null +++ b/src/backend/threadpool-init.hpp @@ -0,0 +1,59 @@ +/* + THREADPOOL-INIT.hpp - pull up the Thread management automagically at application initialisation + + + Copyright (C) Lumiera.org + 2010, Hermann Vosseler + + 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 */ diff --git a/tests/lib/thread-wrapper-join-test.cpp b/tests/lib/thread-wrapper-join-test.cpp index 6e5b4a65e..0237fb63e 100644 --- a/tests/lib/thread-wrapper-join-test.cpp +++ b/tests/lib/thread-wrapper-join-test.cpp @@ -120,16 +120,6 @@ namespace test { VERIFY_ERROR(SPECIAL, newThread.join() ); } - - - - public: - ThreadWrapperJoin_test() - { lumiera_threadpool_init(); } - - ~ThreadWrapperJoin_test() - { lumiera_threadpool_destroy(); } - }; diff --git a/tests/lib/thread-wrapper-test.cpp b/tests/lib/thread-wrapper-test.cpp index 76cbdfc54..b05a7d5c3 100644 --- a/tests/lib/thread-wrapper-test.cpp +++ b/tests/lib/thread-wrapper-test.cpp @@ -56,8 +56,7 @@ namespace backend { struct TestThread : Thread - , Sync // 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 // 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(); } - };