1 /* 2 * 3 * Copyright 2021-2022 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 #pragma once 19 20 #include <pthread.h> 21 22 class NfcHalThreadMutex { 23 public: 24 NfcHalThreadMutex(); 25 virtual ~NfcHalThreadMutex(); 26 void lock(); 27 void unlock(); 28 operator pthread_mutex_t*() { return &mMutex; } 29 30 private: 31 pthread_mutex_t mMutex; 32 }; 33 34 class NfcHalThreadCondVar : public NfcHalThreadMutex { 35 public: 36 NfcHalThreadCondVar(); 37 virtual ~NfcHalThreadCondVar(); 38 void signal(); 39 void wait(); 40 void timedWait(struct timespec* time); 41 operator pthread_cond_t*() { return &mCondVar; } 42 operator pthread_mutex_t*() { 43 return NfcHalThreadMutex::operator pthread_mutex_t*(); 44 } 45 46 private: 47 pthread_cond_t mCondVar; 48 }; 49 50 class NfcHalAutoThreadMutex { 51 public: 52 NfcHalAutoThreadMutex(NfcHalThreadMutex& m); 53 virtual ~NfcHalAutoThreadMutex(); 54 operator NfcHalThreadMutex&() { return mm; } 55 operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; } 56 57 private: 58 NfcHalThreadMutex& mm; 59 }; 60