lockvalidator.h revision 3cd31efc45d9b3b5118748be299da2f298307cdd
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * IPRT - Lock Validator.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * available from http://www.virtualbox.org. This file is free software;
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * you can redistribute it and/or modify it under the terms of the GNU
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * General Public License (GPL) as published by the Free Software
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * The contents of this file may alternatively be used under the terms
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * of the Common Development and Distribution License Version 1.0
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * VirtualBox OSE distribution, in which case the provisions of the
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * CDDL are applicable instead of those of the GPL.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * You may elect to license modified versions of this file under the
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * terms and conditions of either the GPL or the CDDL or both.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * additional information or have any questions.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/** @defgroup grp_ldr RTLockValidator - Lock Validator
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @ingroup grp_rt
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync/** Pointer to a record union.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @internal */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsynctypedef union RTLOCKVALRECUNION *PRTLOCKVALRECUNION;
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Source position.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The file where the lock was taken. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The function where the lock was taken. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Some ID indicating where the lock was taken, typically an address. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The line number in the file. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncAssertCompileSize(RTLOCKVALSRCPOS, HC_ARCH_BITS == 32 ? 16 : 32);
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync/* The pointer types are defined in iprt/types.h. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync/** @def RTLOCKVALSRCPOS_INIT
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Initializer for a RTLOCKVALSRCPOS variable.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pszFile The file name. Optional (NULL).
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param uLine The line number in that file. Optional (0).
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pszFunction The function. Optional (NULL).
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param uId Some location ID, normally the return address.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * Optional (NULL).
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync# define RTLOCKVALSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync# define RTLOCKVALSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync/** @def RTLOCKVALSRCPOS_INIT_DEBUG_API
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Initializer for a RTLOCKVALSRCPOS variable in a typicial debug API
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * variant. Assumes RT_SRC_POS_DECL and RTHCUINTPTR uId as arguments.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync RTLOCKVALSRCPOS_INIT(pszFile, iLine, pszFunction, uId)
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync/** @def RTLOCKVALSRCPOS_INIT_NORMAL_API
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Initializer for a RTLOCKVALSRCPOS variable in a normal API
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * variant. Assumes iprt/asm.h is included.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync RTLOCKVALSRCPOS_INIT(__FILE__, __LINE__, __PRETTY_FUNCTION__, (uintptr_t)ASMReturnAddress())
8077a3fb4024022d405598797d3ed75c667a912fvboxsync/** Pointer to a record of one ownership share. */
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Lock validator record core.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync /** The magic value indicating the record type. */
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync/** Pointer to a lock validator record core. */
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync/** Pointer to a const lock validator record core. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Record recording the exclusive ownership of a lock.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * This is typically part of the per-lock data structure when compiling with
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * the lock validator.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync /** Record core with RTLOCKVALRECEXCL_MAGIC as the magic value. */
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync /** Whether it's enabled or not. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Reserved. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Source position where the lock was taken. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync /** The current owner thread. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync /** Pointer to the lock record below us. Only accessed by the owner. */
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync /** Recursion count */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync /** The lock sub-class. */
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync /** The lock class. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync /** Pointer to the lock. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync /** The lock name. */
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync /** Pointer to the next sibling record.
8077a3fb4024022d405598797d3ed75c667a912fvboxsync * This is used to find the read side of a read-write lock. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncAssertCompileSize(RTLOCKVALRECEXCL, HC_ARCH_BITS == 32 ? 8 + 16 + 32 : 8 + 32 + 56);
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync/* The pointer type is defined in iprt/types.h. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * For recording the one ownership share.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync /** Record core with RTLOCKVALRECSHRDOWN_MAGIC as the magic value. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Recursion count */
3cd31efc45d9b3b5118748be299da2f298307cddvboxsync /** Static (true) or dynamic (false) allocated record. */
3cd31efc45d9b3b5118748be299da2f298307cddvboxsync /** Reserved. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The current owner thread. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Pointer to the lock record below us. Only accessed by the owner. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Pointer back to the shared record. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Reserved. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Source position where the lock was taken. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncAssertCompileSize(RTLOCKVALRECSHRDOWN, HC_ARCH_BITS == 32 ? 24 + 16 : 32 + 32);
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync/** Pointer to a RTLOCKVALRECSHRDOWN. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * Record recording the shared ownership of a lock.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * This is typically part of the per-lock data structure when compiling with
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * the lock validator.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync /** Record core with RTLOCKVALRECSHRD_MAGIC as the magic value. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The lock sub-class. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The lock class. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Pointer to the lock. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The lock name. */
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync /** Pointer to the next sibling record.
8077a3fb4024022d405598797d3ed75c667a912fvboxsync * This is used to find the write side of a read-write lock. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The number of entries in the table.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * Updated before inserting and after removal. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The index of the last entry (approximately). */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** The max table size. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Set if the table is being reallocated, clear if not.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * This is used together with rtLockValidatorSerializeDetectionEnter to make
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * sure there is exactly one thread doing the reallocation and that nobody is
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * using the table at that point. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync bool volatile fReallocating;
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync /** Whether it's enabled or not. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Alignment padding. */
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Pointer to a table containing pointers to records of all the owners. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync R3R0PTRTYPE(PRTLOCKVALRECSHRDOWN volatile *) papOwners;
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync /** Alignment padding. */
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncAssertCompileSize(RTLOCKVALRECSHRD, HC_ARCH_BITS == 32 ? 24 + 20 + 4 : 40 + 24);
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/** @name Special sub-class values.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * The range 16..UINT32_MAX is available to the user, the range 0..15 is
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * reserved for the lock validator.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/** Not allowed to be taken with any other locks in the same class.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * This is the recommended value. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/** Any order is allowed within the class. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/** The first user value. */
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Initialize a lock validator record.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Use RTLockValidatorRecExclDelete to deinitialize it.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pRec The record.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hClass The class. If NIL, the no lock order
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * validation will be performed on this lock.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param uSubClass The sub-class. This is used to define lock
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * order inside the same class. If you don't know,
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * then pass RTLOCKVALIDATOR_SUB_CLASS_NONE.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pszName The lock name (optional).
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hLock The lock handle.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRecExclInit(PRTLOCKVALRECEXCL pRec, RTLOCKVALIDATORCLASS hClass,
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync uint32_t uSubClass, const char *pszName, void *hLock);
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Uninitialize a lock validator record previously initialized by
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * RTLockRecValidatorInit.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pRec The record. Must be valid.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRecExclDelete(PRTLOCKVALRECEXCL pRec);
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Create and initialize a lock validator record.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Use RTLockValidatorRecExclDestroy to deinitialize and destroy the returned
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @return VINF_SUCCESS or VERR_NO_MEMORY.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param ppRec Where to return the record pointer.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hClass The class. If NIL, the no lock order
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * validation will be performed on this lock.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param uSubClass The sub-class. This is used to define lock
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * order inside the same class. If you don't know,
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * then pass RTLOCKVALIDATOR_SUB_CLASS_NONE.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pszName The lock name (optional).
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hLock The lock handle.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorRecExclCreate(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALIDATORCLASS hClass,
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync uint32_t uSubClass, const char *pszName, void *hLock);
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Deinitialize and destroy a record created by RTLockValidatorRecExclCreate.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param ppRec Pointer to the record pointer. Will be set to
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRecExclDestroy(PRTLOCKVALRECEXCL *ppRec);
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * Initialize a lock validator record for a shared lock.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * Use RTLockValidatorRecSharedDelete to deinitialize it.
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param pRec The shared lock record.
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param hClass The class. If NIL, the no lock order
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * validation will be performed on this lock.
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param uSubClass The sub-class. This is used to define lock
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * order inside the same class. If you don't know,
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * then pass RTLOCKVALIDATOR_SUB_CLASS_NONE.
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param pszName The lock name (optional).
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param hLock The lock handle.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRecSharedInit(PRTLOCKVALRECSHRD pRec, RTLOCKVALIDATORCLASS hClass,
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync uint32_t uSubClass, const char *pszName, void *hLock);
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * Uninitialize a lock validator record previously initialized by
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsync * RTLockValidatorRecSharedInit.
cb5363b6fa48f10b080cb6195f56c0823f7c0b0fvboxsync * @param pRec The shared lock record. Must be valid.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRecSharedDelete(PRTLOCKVALRECSHRD pRec);
8077a3fb4024022d405598797d3ed75c667a912fvboxsync * Makes the two records siblings.
8077a3fb4024022d405598797d3ed75c667a912fvboxsync * @returns VINF_SUCCESS on success, VERR_SEM_LV_INVALID_PARAMETER if either of
8077a3fb4024022d405598797d3ed75c667a912fvboxsync * the records are invalid.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @param pRec1 Record 1.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @param pRec2 Record 2.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorRecMakeSiblings(PRTLOCKVALRECCORE pRec1, PRTLOCKVALRECCORE pRec2);
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * Check the locking order.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * This is called by routines implementing lock acquisition.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @retval VINF_SUCCESS on success.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_WRONG_ORDER if the order is wrong. Will have done all
08870164da59f90379b1ea9b5a2476296c362217vboxsync * necessary whining and breakpointing before returning.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pRec The validator record.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hThread The handle of the calling thread. If not known,
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * pass NIL_RTTHREAD and this method will figure it
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALRECEXCL pRec, RTTHREAD hThread, PCRTLOCKVALSRCPOS pSrcPos);
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * Do deadlock detection before blocking on a lock.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VINF_SUCCESS
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_DEADLOCK if blocking would deadlock. Gone thru the
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_NESTED if the semaphore isn't recursive and hThread is
08870164da59f90379b1ea9b5a2476296c362217vboxsync * already the owner. Gone thru the motions.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync * @param pRec The validator record we're blocing on.
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync * @param hThread The current thread. Shall not be NIL_RTTHREAD!
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync * @param enmState The sleep state.
a2b66e2b8b92cf2d0706078798036035cb9fa94dvboxsync * @param fRecursiveOk Whether it's ok to recurse.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckBlocking(PRTLOCKVALRECEXCL pRec, RTTHREAD hThread,
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Do order checking and deadlock detection before blocking on a read/write lock
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * for exclusive (write) access.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_DEADLOCK if blocking would deadlock. Gone thru the
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_NESTED if the semaphore isn't recursive and hThread is
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * already the owner. Gone thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pWrite The validator record for the writer.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pRead The validator record for the readers.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param hThread The current thread. Shall not be NIL_RTTHREAD!
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param enmState The sleep state.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param fRecursiveOk Whether it's ok to recurse.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckWriteOrderBlocking(PRTLOCKVALRECEXCL pWrite, PRTLOCKVALRECSHRD pRead,
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync RTTHREAD hThread, RTTHREADSTATE enmState, bool fRecursiveOk,
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Do order checking and deadlock detection before blocking on a read/write lock
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * for shared (read) access.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_DEADLOCK if blocking would deadlock. Gone thru the
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_NESTED if the semaphore isn't recursive and hThread is
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * already the owner. Gone thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pRead The validator record for the readers.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pWrite The validator record for the writer.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param hThread The current thread. Shall not be NIL_RTTHREAD!
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param enmState The sleep state.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param fRecursiveOk Whether it's ok to recurse.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckReadOrderBlocking(PRTLOCKVALRECSHRD pRead, PRTLOCKVALRECEXCL pWrite,
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync RTTHREAD hThread, RTTHREADSTATE enmState, bool fRecursiveOk,
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Check the exit order and release (unset) the ownership.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * This is called by routines implementing releasing the lock.
c68a3984216eaa85ae7144b3b0d9b168276dbcf3vboxsync * @retval VINF_SUCCESS on success.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_WRONG_RELEASE_ORDER if the order is wrong. Will have
08870164da59f90379b1ea9b5a2476296c362217vboxsync * done all necessary whining and breakpointing before returning.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @param pRec The validator record.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckAndRelease(PRTLOCKVALRECEXCL pRec);
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Check the exit order and release (unset) the shared ownership.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * This is called by routines implementing releasing the read/write lock.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS on success.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_WRONG_RELEASE_ORDER if the order is wrong. Will have
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * done all necessary whining and breakpointing before returning.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pRead The validator record.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param hThread The handle of the calling thread.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorCheckAndReleaseReadOwner(PRTLOCKVALRECSHRD pRead, RTTHREAD hThread);
08870164da59f90379b1ea9b5a2476296c362217vboxsync * Checks and records a lock recursion.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VINF_SUCCESS on success.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_NESTED if the semaphore class forbids recursion. Gone
08870164da59f90379b1ea9b5a2476296c362217vboxsync * thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_WRONG_ORDER if the locking order is wrong. Gone thru
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * the motions.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
c68a3984216eaa85ae7144b3b0d9b168276dbcf3vboxsync * @param pRec The validator record.
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALRECEXCL pRec, PCRTLOCKVALSRCPOS pSrcPos);
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Checks and records a lock unwind (releasing one recursion).
08870164da59f90379b1ea9b5a2476296c362217vboxsync * This should be coupled with called to RTLockValidatorRecordRecursion.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS on success.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_WRONG_RELEASE_ORDER if the release order is wrong. Gone
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * @param pRec The validator record.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorUnwindRecursion(PRTLOCKVALRECEXCL pRec);
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Checks and records a read/write lock read recursion done by the writer.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * This should be coupled with called to
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * RTLockValidatorUnwindReadWriteRecursion.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS on success.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_NESTED if the semaphore class forbids recursion. Gone
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_WRONG_ORDER if the locking order is wrong. Gone thru
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pRead The validator record for the readers.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pWrite The validator record for the writer.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorRecordReadWriteRecursion(PRTLOCKVALRECEXCL pWrite, PRTLOCKVALRECSHRD pRead, PCRTLOCKVALSRCPOS pSrcPos);
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * Checks and records a read/write lock read unwind done by the writer.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * This should be coupled with called to
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * RTLockValidatorRecordReadWriteRecursion.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VINF_SUCCESS on success.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_WRONG_RELEASE_ORDER if the release order is wrong. Gone
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * thru the motions.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @retval VERR_SEM_LV_INVALID_PARAMETER if the input is invalid.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pRead The validator record for the readers.
2f8244f574b4b9f99af99b7472984f3e60ea93d0vboxsync * @param pWrite The validator record for the writer.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(int) RTLockValidatorUnwindReadWriteRecursion(PRTLOCKVALRECEXCL pWrite, PRTLOCKVALRECSHRD pRead);
08870164da59f90379b1ea9b5a2476296c362217vboxsync * Record the specified thread as lock owner and increment the write lock count.
08870164da59f90379b1ea9b5a2476296c362217vboxsync * This function is typically called after acquiring the lock.
04e639b004793691f051abcd5b3c811c6b6b6f86vboxsync * @returns hThread resolved. Can return NIL_RTHREAD iff we fail to adopt the
04e639b004793691f051abcd5b3c811c6b6b6f86vboxsync * alien thread or if pRec is invalid.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pRec The validator record.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param hThread The handle of the calling thread. If not known,
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * pass NIL_RTTHREAD and this method will figure it
4b0369e0c9bcae37f2801e0f7b92509bbbaf4becvboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALRECEXCL pRec, RTTHREAD hThread, PCRTLOCKVALSRCPOS pSrcPos);
08870164da59f90379b1ea9b5a2476296c362217vboxsync * Clear the lock ownership and decrement the write lock count.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * This is typically called before release the lock.
04e639b004793691f051abcd5b3c811c6b6b6f86vboxsync * @returns The thread handle of the previous owner. NIL_RTTHREAD if the record
04e639b004793691f051abcd5b3c811c6b6b6f86vboxsync * is invalid or didn't have any owner.
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync * @param pRec The validator record.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(RTTHREAD) RTLockValidatorUnsetOwner(PRTLOCKVALRECEXCL pRec);
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * Adds an owner to a shared locking record.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * Takes recursion into account. This function is typically called after
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * acquiring the lock.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * @param pRead The validator record.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * @param hThread The thread to add.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * @param pSrcPos The source position of the lock operation.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorAddReadOwner(PRTLOCKVALRECSHRD pRead, RTTHREAD hThread, PCRTLOCKVALSRCPOS pSrcPos);
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * Removes an owner from a shared locking record.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * Takes recursion into account. This function is typically called before
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * releaseing the lock.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * @param pRead The validator record.
f73c807e7ef6a1a6c10ec5cd9b36ee835cfaa241vboxsync * @param hThread The thread to to remove.
eaae6c3ce81916ccc4e74af4b55972ba956cf5c8vboxsyncRTDECL(void) RTLockValidatorRemoveReadOwner(PRTLOCKVALRECSHRD pRead, RTTHREAD hThread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Gets the number of write locks and critical sections the specified
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * thread owns.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * This number does not include any nested lock/critect entries.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Note that it probably will return 0 for non-strict builds since
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * release builds doesn't do unnecessary diagnostic counting like this.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @returns Number of locks on success (0+) and VERR_INVALID_HANDLER on failure
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The thread we're inquiring about.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @remarks Will only work for strict builds.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(int32_t) RTLockValidatorWriteLockGetCount(RTTHREAD Thread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Works the THREADINT::cWriteLocks member, mostly internal.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The current thread.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(void) RTLockValidatorWriteLockInc(RTTHREAD Thread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Works the THREADINT::cWriteLocks member, mostly internal.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The current thread.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(void) RTLockValidatorWriteLockDec(RTTHREAD Thread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Gets the number of read locks the specified thread owns.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Note that nesting read lock entry will be included in the
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * total sum. And that it probably will return 0 for non-strict
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * builds since release builds doesn't do unnecessary diagnostic
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * counting like this.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @returns Number of read locks on success (0+) and VERR_INVALID_HANDLER on failure
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The thread we're inquiring about.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(int32_t) RTLockValidatorReadLockGetCount(RTTHREAD Thread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Works the THREADINT::cReadLocks member.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The current thread.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(void) RTLockValidatorReadLockInc(RTTHREAD Thread);
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * Works the THREADINT::cReadLocks member.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsync * @param Thread The current thread.
f0dd841cb99154da8ec0a31cae2f89044895a23fvboxsyncRTDECL(void) RTLockValidatorReadLockDec(RTTHREAD Thread);
5d1fc7f6c660e826d7f81c580fbf4278dd44c6bdvboxsync/*RTDECL(int) RTLockValidatorClassCreate();*/
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync * Enables / disables the lock validator for new locks.
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync * @returns The old setting.
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync * @param fEnabled The new setting.
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsyncRTDECL(bool) RTLockValidatorSetEnabled(bool fEnabled);
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync * Is the lock validator enabled?
c0ae9fb031e70c0e5f4098a46ab11262097c88f9vboxsync * @returns True if enabled, false if not.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Controls whether the lock validator should be quiet or noisy (default).
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @returns The old setting.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @param fQuiet The new setting.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Is the lock validator quiet or noisy?
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @returns True if it is quiet, false if noisy.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Makes the lock validator panic (default) or not.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @returns The old setting.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @param fPanic The new setting.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsyncRTDECL(bool) RTLockValidatorSetMayPanic(bool fPanic);
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * Can the lock validator cause panic.
2b14f26c96a20e40e9a0c9e3c41b41315f6c6e96vboxsync * @returns True if it can, false if not.