Fawkes API  Fawkes Development Version
thread_producer.cpp
1 
2 /***************************************************************************
3  * thread_producer.cpp - Thread producer aspect for Fawkes
4  *
5  * Created: Tue Nov 20 11:26:24 2007
6  * Copyright 2006-2010 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <aspect/thread_producer.h>
25 
26 namespace fawkes {
27 
28 /** @class ThreadProducerAspect <aspect/thread_producer.h>
29  * Aspect for thread producing threads.
30  * Some threads have to be started by a plugin after it is loaded. Thus
31  * they produce threads while they run. They may also stop this thread
32  * at any one time. To have all these threads registered with a central
33  * instance for easier instrumentation and performance assessment these
34  * threads should be registered with a central thread collector.
35  *
36  * Additionally the threads that are produced can have aspects that are
37  * then initialized by the thread collector (if running inside Fawkes).
38  * Note that initializing an aspect may fail and then an exception is
39  * thrown to indicate the error. You have to catch this exception and
40  * you may never start a thread in that case or unpredictable behavior
41  * will happen.
42  *
43  * This is possible with the ThreadProducerAspect. With this aspect you
44  * get access to a thread collector instance to register threads with.
45  *
46  * Remember to unregister the produced threads if they are cancelled,
47  * joined or even deleted!
48  *
49  * @ingroup Aspects
50  * @author Tim Niemueller
51  */
52 
53 /** @var ThreadCollector * ThreadProducerAspect::thread_collector
54  * Thread collector.
55  * Use this thread collector to register/unregister threads as they are
56  * created/deleted. It is set when the thread starts.
57  */
58 
59 /** Constructor. */
61 {
62  add_aspect("ThreadProducerAspect");
63 }
64 
65 /** Virtual empty destructor. */
67 {
68 }
69 
70 /** Init thread producer aspect.
71  * This set the thread collector.
72  * It is guaranteed that this is called for a thread with the ThreadProducerAspect
73  * before start is called (when running regularly inside Fawkes).
74  * @param collector thread collector
75  */
76 void
78 {
79  thread_collector = collector;
80 }
81 
82 } // end namespace fawkes
fawkes::ThreadCollector
Definition: thread_collector.h:40
fawkes::Aspect::add_aspect
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:55
fawkes::ThreadProducerAspect::~ThreadProducerAspect
virtual ~ThreadProducerAspect()
Virtual empty destructor.
Definition: thread_producer.cpp:72
fawkes::ThreadProducerAspect::init_ThreadProducerAspect
void init_ThreadProducerAspect(ThreadCollector *collector)
Init thread producer aspect.
Definition: thread_producer.cpp:83
fawkes::ThreadProducerAspect::thread_collector
ThreadCollector * thread_collector
Definition: thread_producer.h:53
fawkes
fawkes::ThreadProducerAspect::ThreadProducerAspect
ThreadProducerAspect()
Constructor.
Definition: thread_producer.cpp:66