cppthread 1.1.16
C++ Thread Library
guard.h
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#pragma once
20
34namespace cppthread
35{
36
37
38class mutex;
39
40
41class guard
42{
43public:
44 guard(mutex & m);
45 guard(guard const & rhs) = delete;
46 ~guard();
47
48 guard & operator = (guard const & rhs) = delete;
49
50 void unlock(bool done = true);
51 void lock();
52 bool is_locked() const;
53
54private:
55 bool f_locked = false;
56 mutex * f_mutex = nullptr;
57};
58
59
60
61} // namespace cppthread
62// vim: ts=4 sw=4 et
Lock a mutex in an RAII manner.
Definition guard.h:42
guard & operator=(guard const &rhs)=delete
The assignment operator is deleted.
~guard()
Ensure that the mutex was unlocked.
Definition guard.cpp:108
bool is_locked() const
This function returns whether the guard is current locked.
Definition guard.cpp:236
void unlock(bool done=true)
Unlock this mutex.
Definition guard.cpp:142
void lock()
Relock this mutex.
Definition guard.cpp:203
mutex * f_mutex
The mutex used by the guard class.
Definition guard.h:56
bool f_locked
Whether the guard is currently in effect.
Definition guard.h:55
guard(guard const &rhs)=delete
The copy operator is deleted.
A mutex object to ensures atomicity.
Definition mutex.h:55

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.