cppthread 1.1.16
C++ Thread Library
life.cpp
Go to the documentation of this file.
1// Copyright (c) 2013-2025 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/cppthread
4// contact@m2osw.com
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
29// self
30//
31#include "cppthread/life.h"
32
33#include "cppthread/exception.h"
34#include "cppthread/thread.h"
35
36
37// last include
38//
39#include <snapdev/poison.h>
40
41
42
43
44namespace cppthread
45{
46
47
48
88 : f_thread(thread)
89{
90 if(f_thread == nullptr)
91 {
92 throw logic_error("life pointer is nullptr");
93 }
94 if(!f_thread->start())
95 {
96 // we cannot really just generate an error if the thread
97 // does not start because we do not offer a way for the
98 // user to know so we have to throw for now
99 throw not_started("somehow the thread was not started, an error should have been logged");
100 }
101}
102
103
112{
113 //log << log_level_t::debug
114 // << "stopping life..."
115 // << end;
116
117 f_thread->stop();
118
119 //log << log_level_t::debug
120 // << "life stopped!"
121 // << end;
122}
123
124
125
167} // namespace cppthread
168// vim: ts=4 sw=4 et
life(thread *const thread)
Initialize a "thread life" object.
Definition life.cpp:87
thread * f_thread
The pointer to the thread being managed.
Definition life.h:50
~life()
Make sure the thread stops.
Definition life.cpp:111
A thread object that ensures proper usage of system threads.
Definition thread.h:64
void stop(std::function< void(thread *)> callback=nullptr)
Stop the thread.
Definition thread.cpp:656
bool start()
Attempt to start the thread.
Definition thread.cpp:575
Exceptions for the thread environment.
Thread Runner and Managers.
Thread Runner and Managers.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.