GME  13
Mutexes.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: Mutexes.cpp 734985 2009-01-16 12:21:14Z johns $
00020  */
00021 
00022 
00023 
00024 // ---------------------------------------------------------------------------
00025 //  Includes
00026 // ---------------------------------------------------------------------------
00027 #include <xercesc/util/XercesDefs.hpp>
00028 #include <xercesc/util/PlatformUtils.hpp>
00029 #include <xercesc/util/Mutexes.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 // ---------------------------------------------------------------------------
00034 //  XMLMutex: Constructors and Destructor
00035 // ---------------------------------------------------------------------------
00036 XMLMutex::XMLMutex(MemoryManager* const manager) :
00037 
00038     fHandle(0),
00039     fManager(manager)
00040 {
00041     // Ask the per-platform driver to make us a mutex
00042     fHandle = XMLPlatformUtils::makeMutex(manager);
00043 }
00044 
00045 
00046 XMLMutex::~XMLMutex()
00047 {
00048     if (fHandle)
00049     {
00050         XMLPlatformUtils::closeMutex(fHandle, fManager);
00051         fHandle = 0;
00052     }
00053 }
00054 
00055 
00056 // ---------------------------------------------------------------------------
00057 //  XMLMutex: Lock control methods
00058 // ---------------------------------------------------------------------------
00059 void XMLMutex::lock()
00060 {
00061     XMLPlatformUtils::lockMutex(fHandle);
00062 }
00063 
00064 void XMLMutex::unlock()
00065 {
00066     XMLPlatformUtils::unlockMutex(fHandle);
00067 }
00068 
00069 
00070 
00071 // ---------------------------------------------------------------------------
00072 //  XMLMutexLock: Constructors and Destructor
00073 // ---------------------------------------------------------------------------
00074 XMLMutexLock::XMLMutexLock(XMLMutex* const toLock) :
00075 
00076     fToLock(toLock)
00077 {
00078     fToLock->lock();
00079 }
00080 
00081 
00082 XMLMutexLock::~XMLMutexLock()
00083 {
00084     fToLock->unlock();
00085 }
00086 
00087 XERCES_CPP_NAMESPACE_END