1 /* $Id: lockvalidator.h $ */
3 * IPRT - Internal RTLockValidator header.
7 * Copyright (C) 2006-2016 Oracle Corporation
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.
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.
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.
27 #ifndef ___iprt_internal_lockvalidator_h
28 #define ___iprt_internal_lockvalidator_h
30 #include <iprt/types.h>
31 #include <iprt/lockvalidator.h>
37 * Record used only on the lock stack for recording the stack and source
38 * position of a recursive lock acquisition.
40 typedef struct RTLOCKVALRECNEST
42 RTLOCKVALRECCORE Core
;
43 /** The recursion level at this point in the stack. */
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
;
55 /** Pointer to a recursion record. */
56 typedef RTLOCKVALRECNEST
*PRTLOCKVALRECNEST
;
60 * Record union for simplifying internal processing.
62 typedef union RTLOCKVALRECUNION
64 RTLOCKVALRECCORE Core
;
65 RTLOCKVALRECEXCL Excl
;
66 RTLOCKVALRECSHRD Shared
;
67 RTLOCKVALRECSHRDOWN ShrdOwner
;
68 RTLOCKVALRECNEST Nest
;
73 * Per thread data for the lock validator.
75 * This is part of the RTTHREADINT structure.
77 typedef struct RTLOCKVALPERTHREAD
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. */
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
;
108 DECLHIDDEN(void) rtLockValidatorInitPerThread(RTLOCKVALPERTHREAD
*pPerThread
);
109 DECLHIDDEN(void) rtLockValidatorDeletePerThread(RTLOCKVALPERTHREAD
*pPerThread
);
110 DECLHIDDEN(void) rtLockValidatorSerializeDestructEnter(void);
111 DECLHIDDEN(void) rtLockValidatorSerializeDestructLeave(void);