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