1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _mi_thread_h
26 #define _mi_thread_h
27
|
28 krisbash 1.4 #include <pal/thread.h>
|
29 mike 1.1
30 MI_BEGIN_NAMESPACE
31
32 class Mutex
33 {
34 public:
35
36 Mutex()
37 {
38 Mutex_Init(&m_self);
39 }
40
41 ~Mutex()
42 {
43 Mutex_Destroy(&m_self);
44 }
45
|
46 krisbash 1.4 _Requires_lock_not_held_(&m_self)
47 _Acquires_lock_(&m_self)
|
48 mike 1.1 void Lock()
49 {
50 Mutex_Lock(&m_self);
51 }
52
|
53 krisbash 1.4 _Requires_lock_held_(&m_self)
54 _Releases_lock_(&m_self)
|
55 mike 1.1 void Unlock()
56 {
57 Mutex_Unlock(&m_self);
58 }
59
60 private:
61 Mutex(const Mutex&);
62 Mutex& operator=(const Mutex&);
63 ::Mutex m_self;
64 };
65
66 class AutoMutex
67 {
68 public:
69
70 AutoMutex(Mutex& m) : m_self(m)
71 {
72 m_self.Lock();
73 }
74
|
75 krisbash 1.4 _Requires_lock_held_(m_self)
76 _Releases_lock_(m_self)
|
77 mike 1.1 ~AutoMutex()
78 {
79 m_self.Unlock();
80 }
81
82 private:
83 AutoMutex();
84 Mutex& operator=(const Mutex&);
85 Mutex& m_self;
86 };
87
88 MI_END_NAMESPACE
89
90 #endif /* _mi_thread_h */
|