(file) Return to thread.h CVS log (file) (dir) Up to [OMI] / omi / omiclient

 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           #include <protocol/thread.h>
29           
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 mike  1.1         Mutex_Destroy(&m_self);
44               }
45           
46               void Lock()
47               {
48                   Mutex_Lock(&m_self);
49               }
50           
51               void Unlock()
52               {
53                   Mutex_Unlock(&m_self);
54               }
55           
56           private:
57               Mutex(const Mutex&);
58               Mutex& operator=(const Mutex&);
59               ::Mutex m_self;
60           };
61           
62           class AutoMutex
63           {
64 mike  1.1 public:
65           
66               AutoMutex(Mutex& m) : m_self(m)
67               {
68                   m_self.Lock();
69               }
70           
71               ~AutoMutex()
72               {
73                   m_self.Unlock();
74               }
75           
76           private:
77               AutoMutex();
78               Mutex& operator=(const Mutex&);
79               Mutex& m_self;
80           };
81           
82           MI_END_NAMESPACE
83           
84           #endif /* _mi_thread_h */

ViewCVS 0.9.2