rsMutex.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "rsMutex.h"
  17. namespace android {
  18. namespace renderscript {
  19. Mutex::Mutex() {
  20. }
  21. Mutex::~Mutex() {
  22. pthread_mutex_destroy(&mMutex);
  23. }
  24. bool Mutex::init() {
  25. int status = pthread_mutex_init(&mMutex, nullptr);
  26. if (status) {
  27. ALOGE("Mutex::Mutex init failure");
  28. return false;
  29. }
  30. return true;
  31. }
  32. bool Mutex::lock() {
  33. int status;
  34. status = pthread_mutex_lock(&mMutex);
  35. if (status) {
  36. ALOGE("Mutex: error %i locking.", status);
  37. return false;
  38. }
  39. return true;
  40. }
  41. bool Mutex::unlock() {
  42. int status;
  43. status = pthread_mutex_unlock(&mMutex);
  44. if (status) {
  45. ALOGE("Mutex error %i unlocking.", status);
  46. return false;
  47. }
  48. return true;
  49. }
  50. } // namespace renderscript
  51. } // namespace android