1 karl 1.3 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.3 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.3 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Mike Day (mdday@us.ibm.com)
33 //
34 // Modified By: Markus Mueller
35 // Ramnath Ravindran (Ramnath.Ravindran@compaq.com)
36 // David Eger (dteger@us.ibm.com)
37 // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
38 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
39 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
40 // David Dillard, VERITAS Software Corp.
41 // (david.dillard@veritas.com)
42 mike 1.2 // Aruran, IBM (ashanmug@in.ibm.com) for BUG# 3518
43 //
44 //%/////////////////////////////////////////////////////////////////////////////
45
46 #ifndef Pegasus_Mutex_h
47 #define Pegasus_Mutex_h
48
49 #include <Pegasus/Common/Config.h>
50 #include <Pegasus/Common/Linkage.h>
51 #include <Pegasus/Common/IPCTypes.h>
|
52 mike 1.4 #include <Pegasus/Common/Magic.h>
|
53 mike 1.2
54 PEGASUS_NAMESPACE_BEGIN
55
56 class PEGASUS_COMMON_LINKAGE Mutex
57 {
58 public:
59
60 Mutex();
61 Mutex(int type);
62
63 ~Mutex();
64
65 // block until gaining the lock - throw a deadlock
66 // exception if process already holds the lock
67 // @exception Deadlock
68 // @exception WaitFailed
|
69 mike 1.4 void lock(PEGASUS_THREAD_TYPE caller = pegasus_thread_self());
|
70 mike 1.2
71 // try to gain the lock - lock succeeds immediately if the
72 // mutex is not already locked. throws an exception and returns
73 // immediately if the mutex is currently locked.
74 // @exception Deadlock
75 // @exception AlreadyLocked
76 // @exception WaitFailed
|
77 mike 1.4 void try_lock(PEGASUS_THREAD_TYPE caller = pegasus_thread_self());
|
78 mike 1.2
79 // wait for milliseconds and throw an exception then return if the wait
80 // expires without gaining the lock. Otherwise return without throwing an
81 // exception.
82 // @exception Deadlock
83 // @exception TimeOut
84 // @exception WaitFailed
|
85 mike 1.4 void timed_lock(
86 Uint32 milliseconds,
87 PEGASUS_THREAD_TYPE caller = pegasus_thread_self());
|
88 mike 1.2
89 // unlock the semaphore
90 // @exception Permission
91 void unlock();
92
93 inline PEGASUS_THREAD_TYPE get_owner() { return(_mutex.owner); }
94
95 private:
96 inline void _set_owner(PEGASUS_THREAD_TYPE owner) { _mutex.owner = owner; }
97 PEGASUS_MUTEX_HANDLE _mutex;
98 PEGASUS_MUTEX_HANDLE & _get_handle()
99 {
100 return _mutex;
101 }
102
103 // Hide the assignment operator to avoid implicit use of the default
104 // assignment operator. Do not use this method.
105 Mutex& operator=(const Mutex& original) {return *this;}
106
107 // Hide the copy constructor to avoid implicit use of the default
108 // copy constructor. Do not use this method.
109 mike 1.2 Mutex(const Mutex& _mutex);
110
111 friend class Condition;
|
112 mike 1.4
113 Magic<0x57D11485> _magic;
|
114 mike 1.2 };
115
116 PEGASUS_NAMESPACE_END
117
118 #endif /* Pegasus_Mutex_h */
|