1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FSM_COMMON_H 17 #define FSM_COMMON_H 18 19 #include <cstdarg> 20 #include <pthread.h> 21 #include <stdint.h> 22 #include "media_log.h" 23 #include "player_define.h" 24 25 const char * const MOD_NAME_FSM = "FSM"; 26 27 #define FSM_RETURN_IF_NULL(condition) \ 28 do { \ 29 if ((condition) == nullptr) { \ 30 MEDIA_ERR_LOG("" #condition " is NULL error"); \ 31 return HI_FAILURE; \ 32 } \ 33 } while (0) 34 35 #define FSM_RETURN_IF_HANDLE_NOT_EXIST(checkFunc, handle) \ 36 do { \ 37 if (!checkFunc((handle))) { \ 38 MEDIA_ERR_LOG("invalid FSM handle not exist \n"); \ 39 return HI_FAILURE; \ 40 } \ 41 } while (0) 42 43 #define FSM_LOCK(mutex) \ 44 do { \ 45 (void)pthread_mutex_lock(&(mutex)); \ 46 } while (0) 47 48 #define FSM_UNLOCK(mutex) \ 49 do { \ 50 (void)pthread_mutex_unlock(&(mutex)); \ 51 } while (0) 52 53 #define FSM_COND_WAIT(cond, mutex) \ 54 do { \ 55 (void)pthread_cond_wait(&(cond), &(mutex)); \ 56 } while (0) 57 58 #define FSM_COND_SIGNAL(cond) \ 59 do { \ 60 (void)pthread_cond_signal(&(cond)); \ 61 } while (0) 62 63 uint64_t FsmGetCurTimeUs(); 64 65 void FsmCondInitRelative(pthread_cond_t &cond); 66 67 int32_t FsmCondTimewait(pthread_cond_t &cond, pthread_mutex_t &mutex, uint32_t delayUs); 68 69 #endif /* FSM_COMMON_H */ 70