Fawkes API Fawkes Development Version
test_thread.cpp
1/***************************************************************************
2 * test_thread.cpp - Thread to test SyncPoints
3 *
4 * Created: Thu Mar 05 15:15:42 2015
5 * Copyright 2015 Till Hofmann
6 ****************************************************************************/
7
8/* This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
17 *
18 * Read the full text in the LICENSE.GPL file in the doc directory.
19 */
20
21#include "test_thread.h"
22
23#include <stdlib.h>
24#include <unistd.h>
25
26using namespace fawkes;
27
28/** @class SyncPointTestThread "test_thread.h"
29 * Thread to test SyncPoints.
30 * This thread has the blocked timing aspect and belongs to a wakeup hook.
31 * It simply prints its name.
32 * @author Till Hofmann
33 */
34
35/** Constructor.
36 * @param name the name of the thread
37 * @param hook the hook this thread belongs to
38 */
39
41: Thread(name, Thread::OPMODE_WAITFORWAKEUP), BlockedTimingAspect(hook), hook_(hook)
42{
43}
44
45void
47{
48}
49
50void
52{
53}
54
55void
57{
58 usleep(random() % 100000);
59 logger->log_info("SyncPointTestThread",
60 "In hook %s",
61 BlockedTimingAspect::blocked_timing_hook_to_string(hook_));
62}
virtual void loop()
Code to execute in the thread.
Definition: test_thread.cpp:56
virtual void init()
Initialize the thread.
Definition: test_thread.cpp:46
SyncPointTestThread(const char *name, BlockedTimingAspect::WakeupHook hook)
Constructor.
Definition: test_thread.cpp:40
virtual void finalize()
Finalize the thread.
Definition: test_thread.cpp:51
Thread aspect to use blocked timing.
WakeupHook
Type to define at which hook the thread is woken up.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.