1 /** 2 * Copyright (C) 2022 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 #ifndef IMS_MEDIA_CONDITION_H 18 #define IMS_MEDIA_CONDITION_H 19 20 #include <stdint.h> 21 #include <pthread.h> 22 23 class ImsMediaCondition 24 { 25 public: 26 ImsMediaCondition(); 27 ~ImsMediaCondition(); 28 29 /** 30 * @brief Wait the current thread 31 * 32 */ 33 void wait(); 34 35 /** 36 * @brief Wait the current thread until the timer expired 37 * 38 * @param time The relative time in milliseconds unit 39 * @return true Returned when the timer expires 40 * @return false Returned when the thread is stopped by signal 41 */ 42 bool wait_timeout(int64_t time); 43 void signal(); 44 void reset(); 45 46 private: 47 void IncCount(uint32_t* pnCount); 48 49 pthread_mutex_t* mMutex; 50 pthread_cond_t* mCondition; 51 uint32_t mWaitFlag; 52 uint32_t mSignalFlag; 53 uint32_t mWaitCount; 54 uint32_t mSignalCount; 55 }; 56 57 #endif // IMS_MEDIA_CONDITION_H 58