rsMutex.cpp revision afb743aca56c18beb7ab924e75cb6e070ef3e55a
13330b203039dea366d4981db1408a460134b2d2cMathias Agopian/*
23330b203039dea366d4981db1408a460134b2d2cMathias Agopian * Copyright (C) 2009 The Android Open Source Project
33330b203039dea366d4981db1408a460134b2d2cMathias Agopian *
43330b203039dea366d4981db1408a460134b2d2cMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
53330b203039dea366d4981db1408a460134b2d2cMathias Agopian * you may not use this file except in compliance with the License.
63330b203039dea366d4981db1408a460134b2d2cMathias Agopian * You may obtain a copy of the License at
73330b203039dea366d4981db1408a460134b2d2cMathias Agopian *
83330b203039dea366d4981db1408a460134b2d2cMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
93330b203039dea366d4981db1408a460134b2d2cMathias Agopian *
103330b203039dea366d4981db1408a460134b2d2cMathias Agopian * Unless required by applicable law or agreed to in writing, software
113330b203039dea366d4981db1408a460134b2d2cMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
123330b203039dea366d4981db1408a460134b2d2cMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133330b203039dea366d4981db1408a460134b2d2cMathias Agopian * See the License for the specific language governing permissions and
143330b203039dea366d4981db1408a460134b2d2cMathias Agopian * limitations under the License.
153330b203039dea366d4981db1408a460134b2d2cMathias Agopian */
163330b203039dea366d4981db1408a460134b2d2cMathias Agopian
1798e71ddaede9a0bfb681fd237bec1f66c6c53193Mathias Agopian#include "rsMutex.h"
1898e71ddaede9a0bfb681fd237bec1f66c6c53193Mathias Agopian
193330b203039dea366d4981db1408a460134b2d2cMathias Agopianusing namespace android;
203330b203039dea366d4981db1408a460134b2d2cMathias Agopianusing namespace android::renderscript;
213330b203039dea366d4981db1408a460134b2d2cMathias Agopian
223330b203039dea366d4981db1408a460134b2d2cMathias Agopian
233330b203039dea366d4981db1408a460134b2d2cMathias AgopianMutex::Mutex() {
243330b203039dea366d4981db1408a460134b2d2cMathias Agopian}
253330b203039dea366d4981db1408a460134b2d2cMathias Agopian
263330b203039dea366d4981db1408a460134b2d2cMathias AgopianMutex::~Mutex() {
273330b203039dea366d4981db1408a460134b2d2cMathias Agopian    pthread_mutex_destroy(&mMutex);
283330b203039dea366d4981db1408a460134b2d2cMathias Agopian}
293330b203039dea366d4981db1408a460134b2d2cMathias Agopian
303330b203039dea366d4981db1408a460134b2d2cMathias Agopianbool Mutex::init() {
313330b203039dea366d4981db1408a460134b2d2cMathias Agopian    int status = pthread_mutex_init(&mMutex, NULL);
323330b203039dea366d4981db1408a460134b2d2cMathias Agopian    if (status) {
333330b203039dea366d4981db1408a460134b2d2cMathias Agopian        LOGE("Mutex::Mutex init failure");
34697526bc9e44ce61c88614f98387ae8bbf0a187eIliyan Malchev        return false;
353330b203039dea366d4981db1408a460134b2d2cMathias Agopian    }
363330b203039dea366d4981db1408a460134b2d2cMathias Agopian    return true;
37b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza}
38b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza
39b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stozabool Mutex::lock() {
40b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza    int status;
41b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza    status = pthread_mutex_lock(&mMutex);
42b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza    if (status) {
43b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza        LOGE("Mutex: error %i locking.", status);
443330b203039dea366d4981db1408a460134b2d2cMathias Agopian        return false;
4554ba51dff21de666c5ae3bf3abd4f0634ebb0676Mathias Agopian    }
46b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza    return true;
47b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza}
483330b203039dea366d4981db1408a460134b2d2cMathias Agopian
493330b203039dea366d4981db1408a460134b2d2cMathias Agopianbool Mutex::unlock() {
503330b203039dea366d4981db1408a460134b2d2cMathias Agopian    int status;
513330b203039dea366d4981db1408a460134b2d2cMathias Agopian    status = pthread_mutex_unlock(&mMutex);
523330b203039dea366d4981db1408a460134b2d2cMathias Agopian    if (status) {
533330b203039dea366d4981db1408a460134b2d2cMathias Agopian        LOGE("Mutex error %i unlocking.", status);
543330b203039dea366d4981db1408a460134b2d2cMathias Agopian        return false;
553330b203039dea366d4981db1408a460134b2d2cMathias Agopian    }
563330b203039dea366d4981db1408a460134b2d2cMathias Agopian    return true;
573330b203039dea366d4981db1408a460134b2d2cMathias Agopian}
5854ba51dff21de666c5ae3bf3abd4f0634ebb0676Mathias Agopian
59b1363d37fc6a661508fad106eb7698c5850a6c17Dan Stoza
603330b203039dea366d4981db1408a460134b2d2cMathias Agopian