|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
4: Governed by the TrueCrypt License 2.4 the full text of which is contained
5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
7: */
8:
9: #include <pthread.h>
10: #include "Platform/Mutex.h"
11: #include "Platform/SystemException.h"
12:
13: namespace TrueCrypt
14: {
15: Mutex::Mutex ()
16: {
17: pthread_mutexattr_t attributes;
18:
19: int status = pthread_mutexattr_init (&attributes);
20: if (status != 0)
21: throw SystemException (SRC_POS, status);
22:
23: status = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
24: if (status != 0)
25: throw SystemException (SRC_POS, status);
26:
27: status = pthread_mutex_init (&SystemMutex, &attributes);
28: if (status != 0)
29: throw SystemException (SRC_POS, status);
30:
31: Initialized = true;
32: }
33:
34: Mutex::~Mutex ()
35: {
36: Initialized = false;
37: int status = pthread_mutex_destroy (&SystemMutex);
38: if (status != 0)
39: throw SystemException (SRC_POS, status);
40: }
41:
42: void Mutex::Lock ()
43: {
44: assert (Initialized);
45: int status = pthread_mutex_lock (&SystemMutex);
46: if (status != 0)
47: throw SystemException (SRC_POS, status);
48: }
49:
50: void Mutex::Unlock ()
51: {
52: int status = pthread_mutex_unlock (&SystemMutex);
53: if (status != 0)
54: throw SystemException (SRC_POS, status);
55: }
56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.