Develop Biology
The language of life
ThreadSafe.cpp
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2021 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program 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
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
23
24namespace bio {
25
27//@formatter:off
28 #if BIO_CPP_VERSION < 11
29 #else
30 :
31 m_mutex(),
32 m_lock(m_mutex, std::defer_lock)
33 #endif
34 //@formatter:on
35{
36 //@formatter:off
37 #if BIO_CPP_VERSION < 11
38 #ifdef BIO_OS_IS_LINUX
39 pthread_mutexattr_t mutexattr;
40 pthread_mutexattr_init(&mutexattr);
41 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
42 pthread_mutex_init(&m_lock, &mutexattr);
43 #endif
44 #else
45 #endif
46 //@formatter:on
47}
48
50//@formatter:off
51 #if BIO_CPP_VERSION < 11
52 #else
53 :
54 m_mutex(),
55 m_lock(m_mutex, std::defer_lock)
56 #endif
57 //@formatter:on
58{
59 //@formatter:off
60 #if BIO_CPP_VERSION < 11
61 #ifdef BIO_OS_IS_LINUX
62 pthread_mutexattr_t mutexattr;
63 pthread_mutexattr_init(&mutexattr);
64 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
65 pthread_mutex_init(&m_lock, &mutexattr);
66 #endif
67 #else
68 #endif
69 //@formatter:on
70}
71
73{
74 //@formatter:off
75 #if BIO_CPP_VERSION < 11
76 #ifdef BIO_OS_IS_LINUX
77 pthread_mutex_destroy(&m_lock);
78 #endif
79 #else
80 #endif
81 //@formatter:on
82}
83
85{
86 //@formatter:off
87 #if BIO_CPP_VERSION < 11
88 #ifdef BIO_OS_IS_LINUX
89 pthread_mutex_lock(&m_lock);
90 #endif
91 #else
92 m_lock.lock();
93 #endif
94 //@formatter:on
95}
96
98{
99 //@formatter:off
100 #if BIO_CPP_VERSION < 11
101 #ifdef BIO_OS_IS_LINUX
102 pthread_mutex_unlock(&m_lock);
103 #endif
104 #else
105 m_lock.unlock();
106 #endif
107 //@formatter:on
108}
109
110} //bio namespaace
void LockThread() const
Definition: ThreadSafe.cpp:84
virtual ~ThreadSafe()
Definition: ThreadSafe.cpp:72
void UnlockThread() const
Definition: ThreadSafe.cpp:97
Definition: Cell.h:31