1 /*
2  *
3  *  Copyright 2021-2023 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 timedWait(struct timespec* time);
40   operator pthread_cond_t*() { return &mCondVar; }
41   operator pthread_mutex_t*() {
42     return NfcHalThreadMutex::operator pthread_mutex_t*();
43   }
44 
45  private:
46   pthread_cond_t mCondVar;
47 };
48 
49 class NfcHalAutoThreadMutex {
50  public:
51   NfcHalAutoThreadMutex(NfcHalThreadMutex& m);
52   virtual ~NfcHalAutoThreadMutex();
53   operator NfcHalThreadMutex&() { return mm; }
54 
55  private:
56   NfcHalThreadMutex& mm;
57 };
58