1cb69b360Sopenharmony_ci/* 2cb69b360Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3cb69b360Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb69b360Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb69b360Sopenharmony_ci * You may obtain a copy of the License at 6cb69b360Sopenharmony_ci * 7cb69b360Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb69b360Sopenharmony_ci * 9cb69b360Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb69b360Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb69b360Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb69b360Sopenharmony_ci * See the License for the specific language governing permissions and 13cb69b360Sopenharmony_ci * limitations under the License. 14cb69b360Sopenharmony_ci */ 15cb69b360Sopenharmony_ci 16cb69b360Sopenharmony_ci#ifndef POWERMGR_RUNNING_LOCK_ENTRY_H 17cb69b360Sopenharmony_ci#define POWERMGR_RUNNING_LOCK_ENTRY_H 18cb69b360Sopenharmony_ci 19cb69b360Sopenharmony_ci#include <common.h> 20cb69b360Sopenharmony_ci 21cb69b360Sopenharmony_ci#include "running_lock.h" 22cb69b360Sopenharmony_ci 23cb69b360Sopenharmony_ci#ifdef __cplusplus 24cb69b360Sopenharmony_ciextern "C" { 25cb69b360Sopenharmony_ci#endif // __cplusplus 26cb69b360Sopenharmony_ci 27cb69b360Sopenharmony_citypedef struct { 28cb69b360Sopenharmony_ci uint32_t pid; 29cb69b360Sopenharmony_ci uint64_t token; 30cb69b360Sopenharmony_ci} RunningLockIdentity; 31cb69b360Sopenharmony_ci 32cb69b360Sopenharmony_citypedef struct { 33cb69b360Sopenharmony_ci BOOL isHolding; 34cb69b360Sopenharmony_ci} RunningLockStatus; 35cb69b360Sopenharmony_ci 36cb69b360Sopenharmony_citypedef struct { 37cb69b360Sopenharmony_ci RunningLock lock; 38cb69b360Sopenharmony_ci RunningLockIdentity identity; 39cb69b360Sopenharmony_ci RunningLockStatus status; 40cb69b360Sopenharmony_ci} RunningLockEntry; 41cb69b360Sopenharmony_ci 42cb69b360Sopenharmony_cistatic inline RunningLockEntry *GetRunningLockEntry(const RunningLock *lock) 43cb69b360Sopenharmony_ci{ 44cb69b360Sopenharmony_ci return GET_OBJECT(lock, RunningLockEntry, lock); 45cb69b360Sopenharmony_ci} 46cb69b360Sopenharmony_ci 47cb69b360Sopenharmony_cistatic inline BOOL IsValidRunningLockEntry(RunningLockEntry *entry) 48cb69b360Sopenharmony_ci{ 49cb69b360Sopenharmony_ci return (entry != NULL) && ((entry->lock.type >= 0) && (entry->lock.type < RUNNINGLOCK_BUTT)) ? TRUE : FALSE; 50cb69b360Sopenharmony_ci} 51cb69b360Sopenharmony_ci 52cb69b360Sopenharmony_cistatic inline BOOL IsSameRunningLockIdentity(const RunningLockIdentity *a, const RunningLockIdentity *b) 53cb69b360Sopenharmony_ci{ 54cb69b360Sopenharmony_ci return ((a->pid == b->pid) && (a->token == b->token)) ? TRUE : FALSE; 55cb69b360Sopenharmony_ci} 56cb69b360Sopenharmony_ci 57cb69b360Sopenharmony_ci#ifdef __cplusplus 58cb69b360Sopenharmony_ci} 59cb69b360Sopenharmony_ci#endif // __cplusplus 60cb69b360Sopenharmony_ci#endif // POWERMGR_RUNNING_LOCK_ENTRY_H 61