Line data Source code
1 : /*
2 : * (C) Copyright 2010 Marek Dopiera
3 : *
4 : * This file is part of CoherentDB.
5 : *
6 : * CoherentDB is free software: you can redistribute it and/or modify it
7 : * under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation, either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * CoherentDB is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public
17 : * License along with CoherentDB. If not, see
18 : * http://www.gnu.org/licenses/.
19 : */
20 :
21 : #include <util/thread.h>
22 :
23 : namespace coherent {
24 : namespace util {
25 :
26 : using namespace boost;
27 :
28 36 : completion::completion() : completed(false)
29 : {
30 36 : }
31 :
32 36 : void completion::wait()
33 : {
34 72 : mutex::scoped_lock lock(this->mutex);
35 72 : while (!this->completed)
36 36 : this->cond_var.wait(lock);
37 36 : }
38 :
39 36 : void completion::complete()
40 : {
41 72 : mutex::scoped_lock lock(this->mutex);
42 36 : this->completed = true;
43 36 : this->cond_var.notify_all();
44 36 : }
45 :
46 0 : void completion::reset()
47 : {
48 0 : this->completed = false;
49 0 : }
50 :
51 : } // namespace util
52 6 : } // namespace coherent
53 :
|