STE-Industries: utilities testing
Mutex.cpp
Go to the documentation of this file.
1
14
# include "
Graphic.h
"
15
# include "
SystemException.h
"
16
# include "
Mutex.h
"
17
18
namespace
GraphicSpace
19
{
20
30
31
Mutex::Mutex
(
void
) noexcept: Active(
false
), MutexData()
32
{
33
}
34
45
46
Mutex::~Mutex
(
void
) noexcept(
false
)
47
{
48
if
(Active)
49
Finalize();
50
}
51
66
67
void
Mutex::Initialize
(
void
) noexcept(
false
)
68
{
69
if
(Active)
70
throw
SystemException
(
SystemExceptionType
::
71
INVALID_MUTEX_OPERATION
);
72
if
(pthread_mutex_init(&MutexData,
nullptr
) != MUTEX_INIT_OK)
73
throw
SystemException
(
SystemExceptionType
::
74
MUTEX_INITIALIZATION_FAILED
);
75
Active =
true
;
76
}
77
92
93
void
Mutex::Finalize
(
void
) noexcept(
false
)
94
{
95
if
(not Active)
96
throw
SystemException
(
SystemExceptionType
::
97
INVALID_MUTEX_OPERATION
);
98
if
(pthread_mutex_destroy(&MutexData) != MUTEX_DESTROY_OK)
99
throw
SystemException
(
SystemExceptionType
::
100
MUTEX_DESTROY_FAILED
);
101
Active =
false
;
102
}
103
117
118
void
Mutex::Lock
(
void
) noexcept(
false
)
119
{
120
if
(not Active)
121
throw
SystemException
(
SystemExceptionType
::
122
INVALID_MUTEX_OPERATION
);
123
if
(pthread_mutex_lock(&MutexData) != MUTEX_LOCK_OK)
124
throw
SystemException
(
SystemExceptionType::MUTEX_LOCK_FAILED
);
125
}
126
141
142
void
Mutex::Unlock
(
void
) noexcept(
false
)
143
{
144
if
(not Active)
145
throw
SystemException
(
SystemExceptionType
::
146
INVALID_MUTEX_OPERATION
);
147
if
(pthread_mutex_unlock(&MutexData) != MUTEX_UNLOCK_OK)
148
throw
SystemException
(
SystemExceptionType::MUTEX_UNLOCK_FAILED
);
149
}
150
151
}
GraphicSpace::SystemException
Definition:
SystemException.h:72
GraphicSpace::SystemExceptionType::MUTEX_LOCK_FAILED
@ MUTEX_LOCK_FAILED
GraphicSpace::SystemExceptionType::MUTEX_DESTROY_FAILED
@ MUTEX_DESTROY_FAILED
Graphic.h
GraphicSpace::SystemExceptionType::INVALID_MUTEX_OPERATION
@ INVALID_MUTEX_OPERATION
GraphicSpace::SystemExceptionType::MUTEX_UNLOCK_FAILED
@ MUTEX_UNLOCK_FAILED
GraphicSpace::Mutex::Unlock
void Unlock(void) noexcept(false)
Definition:
Mutex.cpp:142
GraphicSpace::Mutex::~Mutex
~Mutex(void) noexcept(false)
Definition:
Mutex.cpp:46
GraphicSpace::Mutex::Mutex
Mutex(void) noexcept
Definition:
Mutex.cpp:31
GraphicSpace::Mutex::Initialize
void Initialize(void) noexcept(false)
Definition:
Mutex.cpp:67
GraphicSpace::SystemExceptionType
SystemExceptionType
Definition:
SystemException.h:34
Mutex.h
SystemException.h
GraphicSpace::Mutex::Lock
void Lock(void) noexcept(false)
Definition:
Mutex.cpp:118
GraphicSpace
Definition:
Bitmap.cpp:29
GraphicSpace::Mutex::Finalize
void Finalize(void) noexcept(false)
Definition:
Mutex.cpp:93
GraphicSpace::SystemExceptionType::MUTEX_INITIALIZATION_FAILED
@ MUTEX_INITIALIZATION_FAILED
Desktop
Termite
Source
Mutex.cpp
Generated on Thu Mar 14 2024 10:18:16 for STE-Industries: utilities testing by
1.8.17