blob: fb372c417b88cb7d3e182a7e41becd5a9656e2da [file] [log] [blame]
/* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef MUTEX_INC_HEADER
#include <pthread.h>
#endif
#ifdef MUTEX_INC_MEMBER
public:
friend class CondVar;
private:
pthread_mutex_t mLock;
pthread_mutexattr_t mLockAttr;
#endif
#ifdef MUTEX_INC_IMPL
inline Mutex::Mutex()
{
pthread_mutexattr_init(&mLockAttr);
pthread_mutexattr_settype(&mLockAttr,PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mLock,&mLockAttr);
}
inline Mutex::~Mutex()
{
pthread_mutex_destroy(&mLock);
pthread_mutexattr_destroy(&mLockAttr);
}
inline status_t Mutex::lock()
{
if(pthread_mutex_lock(&mLock)==0)
return CAPU_OK;
else
return CAPU_ERROR;
}
inline status_t Mutex::unlock()
{
if(pthread_mutex_unlock(&mLock)==0)
return CAPU_OK;
else
return CAPU_ERROR;
}
inline bool Mutex::trylock()
{
if(pthread_mutex_trylock(&mLock)==0)
return true;
else
return false;
}
#endif