(file) Return to IPCWindows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.13 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.8  // 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 karl  1.6  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.8  // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.9  // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.13 // 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 kumpf 1.4  // 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 mike  1.2  // 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            // 
 21 kumpf 1.4  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.2  // 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 kumpf 1.4  // 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 mike  1.2  // 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: 
 35 a.arora 1.7  //         Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
 36 aruran.ms 1.11 //         Aruran, IBM (ashanmug@in.ibm.com) for BUG# 3518
 37 mike      1.2  //
 38                //%/////////////////////////////////////////////////////////////////////////////
 39                
 40                
 41                
 42                
 43                PEGASUS_NAMESPACE_BEGIN
 44                   
 45                Mutex::Mutex()
 46                {
 47                   _mutex.mut = CreateMutex(NULL, false, NULL);
 48                   _mutex.owner = (PEGASUS_THREAD_TYPE)0;
 49                }
 50                
 51                Mutex::Mutex(int mutex_type)
 52                {
 53                   _mutex.mut = CreateMutex(NULL, false, NULL);
 54                   _mutex.owner = (PEGASUS_THREAD_TYPE)0;
 55                }
 56                
 57                Mutex::Mutex(const Mutex & mutex)
 58 mike      1.2  {
 59                   DuplicateHandle(GetCurrentProcess(), mutex._mutex.mut, 
 60                		   GetCurrentProcess(), &(_mutex.mut), 
 61                		   0, TRUE, 
 62                		   DUPLICATE_SAME_ACCESS | MUTEX_ALL_ACCESS | SYNCHRONIZE);
 63                
 64                
 65                   _mutex.owner = (PEGASUS_THREAD_TYPE)0;
 66                }
 67                
 68                
 69                Mutex::~Mutex()
 70                {
 71                   WaitForSingleObject(_mutex.mut, INFINITE);
 72                   CloseHandle(_mutex.mut);
 73                }
 74                
 75                
 76                
 77                static const int SEM_VALUE_MAX = 0x0000ffff;
 78                Semaphore::Semaphore(Uint32 initial) 
 79 mike      1.2  {
 80                   if(initial > SEM_VALUE_MAX)
 81                      initial = SEM_VALUE_MAX - 1;
 82                   _count = initial;
 83                   _semaphore.owner = (PEGASUS_THREAD_TYPE)GetCurrentThreadId();
 84                   _semaphore.sem = CreateSemaphore(NULL, initial, SEM_VALUE_MAX, NULL);
 85                }
 86                
 87                Semaphore::~Semaphore()
 88                {
 89                   CloseHandle(_semaphore.sem);
 90                }
 91                
 92                //-----------------------------------------------------------------
 93                // Native implementation of Conditional semaphore object
 94                //-----------------------------------------------------------------
 95                
 96                #ifdef PEGASUS_CONDITIONAL_NATIVE
 97                
 98 mday      1.3  Condition::Condition(void) : _disallow(0)
 99 mike      1.2  { 
100 a.arora   1.7     _cond_mutex.reset(new Mutex());
101 mike      1.2     _destroy_mut = true;
102 tony      1.5  
103                    // Change from PulseEvent to SetEvent, this is part of 
104                    //    fix to avoid deadlock in CIMClient Constructor.
105                
106                    // Change 2nd parm to FALSE (create an auto-reset event)
107                
108                    _condition = CreateEvent( NULL, FALSE, FALSE, NULL);
109                
110 mday      1.3  
111 mike      1.2  } 
112                
113 aruran.ms 1.11 Condition::Condition(Mutex& mutex) : _disallow(0), _condition()
114 mike      1.2  {
115 aruran.ms 1.11    _cond_mutex.reset(&mutex);
116 mike      1.2     _destroy_mut = false;
117 tony      1.5  
118                    // Change from PulseEvent to SetEvent, this is part of 
119                    //    fix to avoid deadlock in CIMClient Constructor.
120                   
121                    // Change 2nd parm to FALSE (create an auto-reset event)
122                    _condition = CreateEvent( NULL, FALSE, FALSE, NULL);
123 mike      1.2  }
124                
125                
126                Condition::~Condition(void)
127                {
128                   // don't allow any new waiters
129                   _disallow++;
130                   
131 tony      1.5      // Change from PulseEvent to SetEvent, this is part of 
132                    //    fix to avoid deadlock in CIMClient Constructor.
133                    // Change from PulseEvent to SetEvent
134                    //PulseEvent(_condition);
135                    SetEvent(_condition);
136                
137                
138 mike      1.2     if(_destroy_mut == true)
139 a.arora   1.7        _cond_mutex.reset();
140                   else
141                      _cond_mutex.release();
142 tony      1.5  
143                    // Change from PulseEvent to SetEvent, this is part of 
144                    //    fix to avoid deadlock in CIMClient Constructor.
145                    // Change Added next line to cleanup handle
146                    CloseHandle(_condition);
147                
148 mike      1.2  }
149                
150                #endif // native conditional semaphore
151                //----------------------------------------------------------------- 
152                // END of native conditional semaphore implementation
153                //-----------------------------------------------------------------
154                
155                
156                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2