rsMutex.cpp revision 12b14ae9fa34f4fd0bf21a2a4ac95a4864248fe9
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "rsMutex.h" 18 19using namespace android; 20using namespace android::renderscript; 21 22 23Mutex::Mutex() 24{ 25} 26 27Mutex::~Mutex() 28{ 29 pthread_mutex_destroy(&mMutex); 30} 31 32bool Mutex::init() 33{ 34 int status = pthread_mutex_init(&mMutex, NULL); 35 if (status) { 36 LOGE("Mutex::Mutex init failure"); 37 return false; 38 } 39 return true; 40} 41 42bool Mutex::lock() 43{ 44 int status; 45 status = pthread_mutex_lock(&mMutex); 46 if (status) { 47 LOGE("Mutex: error %i locking.", status); 48 return false; 49 } 50 return true; 51} 52 53bool Mutex::unlock() 54{ 55 int status; 56 status = pthread_mutex_unlock(&mMutex); 57 if (status) { 58 LOGE("Mutex error %i unlocking.", status); 59 return false; 60 } 61 return true; 62} 63 64 65