Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openmp_lock.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
8 /* This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This software 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 GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this software. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 */
23 
24 #ifndef OPENMP_LOCK_H
25 #define OPENMP_LOCK_H
26 
27 #include <hugin_config.h>
28 
29 namespace hugin_omp
30 {
31 
32 #ifdef HAVE_OPENMP
33 #include <omp.h>
34 
36 class Lock
37 {
38 public:
39  Lock() {omp_init_lock(&m_lock);}
40  ~Lock() {omp_destroy_lock(&m_lock);}
41 
42  void Set() {omp_set_lock(&m_lock);}
43  void Unset() {omp_unset_lock(&m_lock);}
44  bool Test() {return (omp_test_lock(&m_lock) != 0);}
45 private:
46  Lock(const Lock&);
47  Lock& operator=(const Lock&);
48  omp_lock_t m_lock;
49 };
50 #else
51 /* A dummy mutex that doesn't actually exclude anything,
52 * but as there is no parallelism either, no worries. */
53 class Lock
54 {
55 public:
56  void Set() {}
57  void Unset() {}
58  bool Test() { return false; }
59 };
60 #endif
61 
62  /* An exception-safe scoped lock-keeper. */
64 {
65 public:
68 private:
69  ScopedLock(const ScopedLock&);
72 };
73 
74 }; // namespace omp
75 #endif
ScopedLock(Lock &lock)
Definition: openmp_lock.h:66
static hugin_omp::Lock lock
ScopedLock & operator=(const ScopedLock &)