paul@197 | 1 | /* |
paul@197 | 2 | * Accountable object support. |
paul@197 | 3 | * |
paul@197 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@197 | 5 | * |
paul@197 | 6 | * This program is free software; you can redistribute it and/or |
paul@197 | 7 | * modify it under the terms of the GNU General Public License as |
paul@197 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@197 | 9 | * the License, or (at your option) any later version. |
paul@197 | 10 | * |
paul@197 | 11 | * This program is distributed in the hope that it will be useful, |
paul@197 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@197 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@197 | 14 | * GNU General Public License for more details. |
paul@197 | 15 | * |
paul@197 | 16 | * You should have received a copy of the GNU General Public License |
paul@197 | 17 | * along with this program; if not, write to the Free Software |
paul@197 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@197 | 19 | * Boston, MA 02110-1301, USA |
paul@197 | 20 | */ |
paul@197 | 21 | |
paul@197 | 22 | #include "accountable.h" |
paul@197 | 23 | |
paul@197 | 24 | |
paul@197 | 25 | |
paul@197 | 26 | Accountable::~Accountable() |
paul@197 | 27 | { |
paul@197 | 28 | } |
paul@197 | 29 | |
paul@197 | 30 | /* Attach to the object. */ |
paul@197 | 31 | |
paul@197 | 32 | void Accountable::attach() |
paul@197 | 33 | { |
paul@197 | 34 | std::lock_guard<std::mutex> guard(_attached_lock); |
paul@197 | 35 | |
paul@197 | 36 | _attached += 1; |
paul@197 | 37 | } |
paul@197 | 38 | |
paul@197 | 39 | /* Detach from the object. */ |
paul@197 | 40 | |
paul@197 | 41 | unsigned int Accountable::detach() |
paul@197 | 42 | { |
paul@197 | 43 | std::lock_guard<std::mutex> guard(_attached_lock); |
paul@197 | 44 | |
paul@197 | 45 | if (_attached) |
paul@197 | 46 | _attached -= 1; |
paul@197 | 47 | |
paul@197 | 48 | return _attached; |
paul@197 | 49 | } |
paul@197 | 50 | |
paul@197 | 51 | // vim: tabstop=4 expandtab shiftwidth=4 |