blob: 40671d598a63c75f20ea70c087843a573e667960 [file] [log] [blame]
Jason Sams12b14ae2010-03-18 11:39:44 -07001/*
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
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080019namespace android {
20namespace renderscript {
Jason Sams12b14ae2010-03-18 11:39:44 -070021
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080022Mutex::Mutex() {
Jason Sams12b14ae2010-03-18 11:39:44 -070023}
24
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080025Mutex::~Mutex() {
Jason Sams12b14ae2010-03-18 11:39:44 -070026 pthread_mutex_destroy(&mMutex);
27}
28
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080029bool Mutex::init() {
Chris Wailes44bef6f2014-08-12 13:51:10 -070030 int status = pthread_mutex_init(&mMutex, nullptr);
Jason Sams12b14ae2010-03-18 11:39:44 -070031 if (status) {
Steve Blockaf12ac62012-01-06 19:20:56 +000032 ALOGE("Mutex::Mutex init failure");
Jason Sams12b14ae2010-03-18 11:39:44 -070033 return false;
34 }
35 return true;
36}
37
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080038bool Mutex::lock() {
Jason Sams12b14ae2010-03-18 11:39:44 -070039 int status;
40 status = pthread_mutex_lock(&mMutex);
41 if (status) {
Steve Blockaf12ac62012-01-06 19:20:56 +000042 ALOGE("Mutex: error %i locking.", status);
Jason Sams12b14ae2010-03-18 11:39:44 -070043 return false;
44 }
45 return true;
46}
47
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080048bool Mutex::unlock() {
Jason Sams12b14ae2010-03-18 11:39:44 -070049 int status;
50 status = pthread_mutex_unlock(&mMutex);
51 if (status) {
Steve Blockaf12ac62012-01-06 19:20:56 +000052 ALOGE("Mutex error %i unlocking.", status);
Jason Sams12b14ae2010-03-18 11:39:44 -070053 return false;
54 }
55 return true;
56}
57
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080058} // namespace renderscript
59} // namespace android