1 | /* $Id: lockvalidator.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Internal RTLockValidator header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_INTERNAL_lockvalidator_h
|
---|
38 | #define IPRT_INCLUDED_INTERNAL_lockvalidator_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/types.h>
|
---|
44 | #include <iprt/lockvalidator.h>
|
---|
45 |
|
---|
46 | RT_C_DECLS_BEGIN
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Record used only on the lock stack for recording the stack and source
|
---|
51 | * position of a recursive lock acquisition.
|
---|
52 | */
|
---|
53 | typedef struct RTLOCKVALRECNEST
|
---|
54 | {
|
---|
55 | RTLOCKVALRECCORE Core;
|
---|
56 | /** The recursion level at this point in the stack. */
|
---|
57 | uint32_t cRecursion;
|
---|
58 | /** Pointer to the next record on the stack. */
|
---|
59 | PRTLOCKVALRECUNION volatile pDown;
|
---|
60 | /** Pointer to the first recursion. */
|
---|
61 | PRTLOCKVALRECUNION volatile pRec;
|
---|
62 | /** Pointer to the next free record when in the
|
---|
63 | * RTLOCKVALPERTHREAD::pFreeNestRecs list. */
|
---|
64 | struct RTLOCKVALRECNEST *pNextFree;
|
---|
65 | /** The source position. */
|
---|
66 | RTLOCKVALSRCPOS SrcPos;
|
---|
67 | } RTLOCKVALRECNEST;
|
---|
68 | /** Pointer to a recursion record. */
|
---|
69 | typedef RTLOCKVALRECNEST *PRTLOCKVALRECNEST;
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Record union for simplifying internal processing.
|
---|
74 | */
|
---|
75 | typedef union RTLOCKVALRECUNION
|
---|
76 | {
|
---|
77 | RTLOCKVALRECCORE Core;
|
---|
78 | RTLOCKVALRECEXCL Excl;
|
---|
79 | RTLOCKVALRECSHRD Shared;
|
---|
80 | RTLOCKVALRECSHRDOWN ShrdOwner;
|
---|
81 | RTLOCKVALRECNEST Nest;
|
---|
82 | } RTLOCKVALRECUNION;
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Per thread data for the lock validator.
|
---|
87 | *
|
---|
88 | * This is part of the RTTHREADINT structure.
|
---|
89 | */
|
---|
90 | typedef struct RTLOCKVALPERTHREAD
|
---|
91 | {
|
---|
92 | /** Where we are blocking. */
|
---|
93 | RTLOCKVALSRCPOS SrcPos;
|
---|
94 | /** Top of the lock stack. */
|
---|
95 | PRTLOCKVALRECUNION volatile pStackTop;
|
---|
96 | /** List of free recursion (nesting) record. */
|
---|
97 | PRTLOCKVALRECNEST pFreeNestRecs;
|
---|
98 | /** What we're blocking on.
|
---|
99 | * The lock validator sets this, RTThreadUnblock clears it. */
|
---|
100 | PRTLOCKVALRECUNION volatile pRec;
|
---|
101 | /** The state in which pRec that goes with pRec.
|
---|
102 | * RTThreadUnblocking uses this to figure out when to clear pRec. */
|
---|
103 | RTTHREADSTATE volatile enmRecState;
|
---|
104 | /** The thread is running inside the lock validator. */
|
---|
105 | bool volatile fInValidator;
|
---|
106 | /** Reserved for alignment purposes. */
|
---|
107 | bool afReserved[3];
|
---|
108 | /** Number of registered write locks, mutexes and critsects that this thread owns. */
|
---|
109 | int32_t volatile cWriteLocks;
|
---|
110 | /** Number of registered read locks that this thread owns, nesting included. */
|
---|
111 | int32_t volatile cReadLocks;
|
---|
112 | /** Bitmap indicating which entires are free (set) and allocated (clear). */
|
---|
113 | uint32_t volatile bmFreeShrdOwners;
|
---|
114 | /** Reserved for alignment purposes. */
|
---|
115 | uint32_t u32Reserved;
|
---|
116 | /** Statically allocated shared owner records */
|
---|
117 | RTLOCKVALRECSHRDOWN aShrdOwners[32];
|
---|
118 | } RTLOCKVALPERTHREAD;
|
---|
119 |
|
---|
120 |
|
---|
121 | DECLHIDDEN(void) rtLockValidatorInitPerThread(RTLOCKVALPERTHREAD *pPerThread);
|
---|
122 | DECLHIDDEN(void) rtLockValidatorDeletePerThread(RTLOCKVALPERTHREAD *pPerThread);
|
---|
123 | DECLHIDDEN(void) rtLockValidatorSerializeDestructEnter(void);
|
---|
124 | DECLHIDDEN(void) rtLockValidatorSerializeDestructLeave(void);
|
---|
125 |
|
---|
126 | RT_C_DECLS_END
|
---|
127 |
|
---|
128 | #endif /* !IPRT_INCLUDED_INTERNAL_lockvalidator_h */
|
---|
129 |
|
---|