WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
los_lockdep.h
浏览该文件的文档.
1/* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2022. All rights reserved.
3 * Description: Lock Dependency Check.
4 * Author: Huawei LiteOS Team
5 * Create: 2018-10-18
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without specific prior written
15 * permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * --------------------------------------------------------------------------- */
28
34#ifndef _LOS_LOCKDEP_H
35#define _LOS_LOCKDEP_H
36
37#include "los_config.h"
38#include "los_typedef.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43
44 /* lockdep supported lock type */
46#ifdef LOSCFG_KERNEL_SPINDEP
47 LOCK_SPIN,
48#endif
49#ifdef LOSCFG_KERNEL_MUXDEP
50 LOCK_MUTEX,
51#endif
52#ifdef LOSCFG_KERNEL_SEMDEP
53 LOCK_SEM,
54#endif
55#ifdef LOSCFG_PTHREAD_MUXDEP
56 LOCK_PTHREAD,
57#endif
59};
60
61/* Define the structure of deadlock detection entity */
62typedef struct {
63 enum LockType type; /* lock type */
64 UINT32 id; /* semaphore or mutex id */
65 CHAR *name; /* spinlock name */
66 UINT32 cpuId; /* the cpu id when the lock is obtained. */
67 VOID *owner; /* the pointer to the lock owner's task control block. */
69
70#ifdef LOSCFG_KERNEL_LOCKDEP
71
72/* This Macro is used to obtain the pointer to a lock check entity using a corresponding parameter */
73#define LOCKDEP_GET_ADDR(lockDep, index) ((lockDep)->heldLocks[(index)].lockAddr)
74
75/* The max num that a task holding lock */
76#define MAX_LOCK_DEPTH 16U
77
78enum LockDepErrType {
79 LOCKDEP_SUCCESS = 0,
80 LOCKDEP_ERR_DOUBLE_LOCK,
81 LOCKDEP_ERR_DEAD_LOCK,
82 LOCKDEP_ERR_UNLOCK_WITHOUT_LOCK,
83 LOCKDEP_ERR_OVERFLOW,
84 LOCKDEP_ERR_MAX,
85};
86
87typedef struct {
88 VOID *lockPtr;
89 VOID *lockAddr;
90 UINT64 waitTime;
91 UINT64 holdTime;
92} HeldLocks;
93
94typedef struct {
95 VOID *waitLock;
96 INT32 lockDepth;
97 HeldLocks heldLocks[MAX_LOCK_DEPTH];
98} LockDep;
99#endif
100
101/* Note: The following functions are for internal use only. */
102
103/* This API is used to init dead lock */
105
106/* This API is used to deinitialize dead lock */
108
109/* This API is used to check dead lock */
111
112/* This API is used to trace when a lock locked */
114
115/* This API is used to trace when a lock unlocked */
117
118#ifdef LOSCFG_KERNEL_SPINDEP
119extern VOID OsLockdepClearSpinlocks(VOID);
120#define LOCKDEP_CHECK_INIT(lock) do { \
121 OsLockDepCheckInit(LOCK_SPIN, &lock->lockCheck, 0); \
122 lock->lockCheck.name = "spinlock"; \
123} while (0)
124#define LOCKDEP_CHECK_IN(lock) OsLockDepCheckIn(LOCK_SPIN, &lock->lockCheck, 0)
125#define LOCKDEP_RECORD(lock) OsLockDepRecord(LOCK_SPIN, &lock->lockCheck, 0)
126#define LOCKDEP_CHECK_OUT(lock) OsLockDepCheckOut(LOCK_SPIN, &lock->lockCheck, 0)
127#define LOCKDEP_CLEAR_LOCKS() OsLockdepClearSpinlocks()
128#else
129#define LOCKDEP_CHECK_INIT(lock)
130#define LOCKDEP_CHECK_IN(lock)
131#define LOCKDEP_RECORD(lock)
132#define LOCKDEP_CHECK_OUT(lock)
133#define LOCKDEP_CLEAR_LOCKS()
134#endif
135
136#ifdef __cplusplus
137}
138#endif /* __cplusplus */
139#endif /* _LOS_LOCKDEP_H */
LockType
Definition los_lockdep.h:45
@ LOCK_TYPE_MAX
Definition los_lockdep.h:58
void OsLockDepRecord(enum LockType type, LosLockCheck *lock, UINT32 id)
void OsLockDepCheckDeInit(enum LockType type, LosLockCheck *lock, UINT32 id)
void OsLockDepCheckIn(enum LockType type, LosLockCheck *lock, UINT32 id)
void OsLockDepCheckOut(enum LockType type, LosLockCheck *lock, UINT32 id)
void OsLockDepCheckInit(enum LockType type, LosLockCheck *lock, UINT32 id)
signed int INT32
Definition los_typedef.h:55
unsigned long long UINT64
Definition los_typedef.h:72
#define VOID
Definition los_typedef.h:88
unsigned int UINT32
Definition los_typedef.h:52
char CHAR
Definition los_typedef.h:58
osal_u8 type
Definition oal_net.h:0
Definition los_lockdep.h:62
CHAR * name
Definition los_lockdep.h:65
enum LockType type
Definition los_lockdep.h:63
void * owner
Definition los_lockdep.h:67
UINT32 id
Definition los_lockdep.h:64
UINT32 cpuId
Definition los_lockdep.h:66