|
reSIProcate/rutil
9694
|
00001 /* 00002 namespace std 00003 { 00004 typedef wchar_t wint_t; 00005 typedef unsigned int size_t; 00006 } 00007 00008 */ 00009 #include <cassert> 00010 #include <cerrno> 00011 #include "rutil/Mutex.hxx" 00012 00013 #if defined(WIN32) 00014 # include <windows.h> 00015 # include <winbase.h> 00016 #else 00017 # include <pthread.h> 00018 #endif 00019 00020 using namespace resip; 00021 00022 Mutex::Mutex() 00023 { 00024 #ifndef WIN32 00025 int rc = pthread_mutex_init(&mId,0); 00026 (void)rc; 00027 assert( rc == 0 ); 00028 #else 00029 // Note: Windows Critical sections are recursive in nature and perhaps 00030 // this implementation calls for a non-recursive implementation 00031 // (since there also exists a RecursiveMutex class). The effort 00032 // to make this non-recursive just doesn't make sense though. (SLG) 00033 InitializeCriticalSection(&mId); 00034 #endif 00035 } 00036 00037 00038 Mutex::~Mutex () 00039 { 00040 #ifndef WIN32 00041 int rc = pthread_mutex_destroy(&mId); 00042 (void)rc; 00043 assert( rc != EBUSY ); // currently locked 00044 assert( rc == 0 ); 00045 #else 00046 DeleteCriticalSection(&mId); 00047 #endif 00048 } 00049 00050 00051 void 00052 Mutex::lock() 00053 { 00054 #ifndef WIN32 00055 int rc = pthread_mutex_lock(&mId); 00056 (void)rc; 00057 assert( rc != EINVAL ); 00058 assert( rc != EDEADLK ); 00059 assert( rc == 0 ); 00060 #else 00061 EnterCriticalSection(&mId); 00062 #endif 00063 } 00064 00065 void 00066 Mutex::unlock() 00067 { 00068 #ifndef WIN32 00069 int rc = pthread_mutex_unlock(&mId); 00070 (void)rc; 00071 assert( rc != EINVAL ); 00072 assert( rc != EPERM ); 00073 assert( rc == 0 ); 00074 #else 00075 LeaveCriticalSection(&mId); 00076 #endif 00077 } 00078 00079 #ifndef WIN32 00080 pthread_mutex_t* 00081 Mutex::getId() const 00082 { 00083 return ( &mId ); 00084 } 00085 #endif 00086 00087 00088 /* ==================================================================== 00089 * The Vovida Software License, Version 1.0 00090 * 00091 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00092 * 00093 * Redistribution and use in source and binary forms, with or without 00094 * modification, are permitted provided that the following conditions 00095 * are met: 00096 * 00097 * 1. Redistributions of source code must retain the above copyright 00098 * notice, this list of conditions and the following disclaimer. 00099 * 00100 * 2. Redistributions in binary form must reproduce the above copyright 00101 * notice, this list of conditions and the following disclaimer in 00102 * the documentation and/or other materials provided with the 00103 * distribution. 00104 * 00105 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00106 * and "Vovida Open Communication Application Library (VOCAL)" must 00107 * not be used to endorse or promote products derived from this 00108 * software without prior written permission. For written 00109 * permission, please contact vocal@vovida.org. 00110 * 00111 * 4. Products derived from this software may not be called "VOCAL", nor 00112 * may "VOCAL" appear in their name, without prior written 00113 * permission of Vovida Networks, Inc. 00114 * 00115 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00116 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00117 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00118 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00119 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00120 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00121 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00122 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00123 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00124 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00125 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00126 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00127 * DAMAGE. 00128 * 00129 * ==================================================================== 00130 * 00131 * This software consists of voluntary contributions made by Vovida 00132 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00133 * Inc. For more information on Vovida Networks, Inc., please see 00134 * <http://www.vovida.org/>. 00135 * 00136 */
1.7.5.1