VirtualBox

Changeset 40806 in vbox for trunk/include


Ignore:
Timestamp:
Apr 6, 2012 9:05:19 PM (13 years ago)
Author:
vboxsync
Message:

RTSpinlock: Redid the interface, eliminating NoInts and Tmp. Whether a spinlock is interrupt safe or not is now defined at creation time, preventing stupid bugs arrising from calling the wrong acquire and/or release methods somewhere. The saved flags are stored in the spinlock strucutre, eliminating the annoying Tmp variable. Needs testing on each platform before fixing the build burn.

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r40668 r40806  
    12211221# define RTSortIsSorted                                 RT_MANGLER(RTSortIsSorted)
    12221222# define RTSpinlockAcquire                              RT_MANGLER(RTSpinlockAcquire)
    1223 # define RTSpinlockAcquireNoInts                        RT_MANGLER(RTSpinlockAcquireNoInts)
    12241223# define RTSpinlockCreate                               RT_MANGLER(RTSpinlockCreate)
    12251224# define RTSpinlockDestroy                              RT_MANGLER(RTSpinlockDestroy)
    12261225# define RTSpinlockRelease                              RT_MANGLER(RTSpinlockRelease)
    1227 # define RTSpinlockReleaseNoInts                        RT_MANGLER(RTSpinlockReleaseNoInts)
    12281226# define RTStrAAppendExNVTag                            RT_MANGLER(RTStrAAppendExNVTag)
    12291227# define RTStrAAppendNTag                               RT_MANGLER(RTStrAAppendNTag)
  • trunk/include/iprt/spinlock.h

    r28800 r40806  
    3939
    4040/**
    41  * Temporary spinlock state variable.
    42  * All members are undefined and highly platform specific.
    43  */
    44 typedef struct RTSPINLOCKTMP
    45 {
    46 #ifdef IN_RING0
    47 # ifdef RT_OS_LINUX
    48     /** The saved [R|E]FLAGS. */
    49     unsigned long   flFlags;
    50 #  define RTSPINLOCKTMP_INITIALIZER { 0 }
    51 
    52 # elif defined(RT_OS_WINDOWS)
    53     /** The saved [R|E]FLAGS. */
    54     RTCCUINTREG     uFlags;
    55     /** The KIRQL. */
    56     unsigned char   uchIrqL;
    57 #  define RTSPINLOCKTMP_INITIALIZER { 0, 0 }
    58 
    59 # elif defined(__L4__)
    60     /** The saved [R|E]FLAGS. */
    61     unsigned long   flFlags;
    62 #  define RTSPINLOCKTMP_INITIALIZER { 0 }
    63 
    64 # elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
    65     /** The saved [R|E]FLAGS. */
    66     RTCCUINTREG     uFlags;
    67 #  define RTSPINLOCKTMP_INITIALIZER { 0 }
    68 
    69 # elif defined(RT_OS_OS2)
    70     /** The saved [R|E]FLAGS. (dummy) */
    71     RTCCUINTREG     uFlags;
    72 #  define RTSPINLOCKTMP_INITIALIZER { 0 }
    73 
    74 # else
    75 #  error "PORTME\n"
    76     /** The saved [R|E]FLAGS. */
    77     RTCCUINTREG     uFlags;
    78 # endif
    79 
    80 #else /* !IN_RING0 */
    81     /** The saved [R|E]FLAGS. (dummy) */
    82     RTCCUINTREG     uFlags;
    83 # define RTSPINLOCKTMP_INITIALIZER { 0 }
    84 #endif /* !IN_RING0 */
    85 } RTSPINLOCKTMP;
    86 /** Pointer to a temporary spinlock state variable. */
    87 typedef RTSPINLOCKTMP *PRTSPINLOCKTMP;
    88 /** Pointer to a const temporary spinlock state variable. */
    89 typedef const RTSPINLOCKTMP *PCRTSPINLOCKTMP;
    90 
    91 /** @def RTSPINLOCKTMP_INITIALIZER
    92  * What to assign to a RTSPINLOCKTMP at definition.
    93  */
    94 #ifdef DOXYGEN_RUNNING
    95 # define RTSPINLOCKTMP_INITIALIZER
    96 #endif
    97 
    98 
    99 
    100 /**
    10141 * Creates a spinlock.
    10242 *
    10343 * @returns iprt status code.
    10444 * @param   pSpinlock   Where to store the spinlock handle.
     45 * @param   fFlags      Creation flags, see RTSPINLOCK_FLAGS_XXX.
     46 * @param   pszName     Spinlock name, for debugging purposes.  String lifetime
     47 *                      must be the same as the lock as it won't be copied.
    10548 */
    106 RTDECL(int)  RTSpinlockCreate(PRTSPINLOCK pSpinlock);
     49RTDECL(int)  RTSpinlockCreate(PRTSPINLOCK pSpinlock, uint32_t fFlags, const char *pszName);
     50
     51/** @name RTSPINLOCK_FLAGS_XXX
     52 * @{ */
     53/** Disable interrupts when taking the spinlock, making it interrupt safe
     54 * (sans NMI of course).
     55 *
     56 * This is generally the safest option, though it isn't really required unless
     57 * the data being protect is also accessed from interrupt handler context. */
     58#define RTSPINLOCK_FLAGS_INTERRUPT_SAFE     RT_BIT(1)
     59/** No need to disable interrupts, the protect code/data is not used by
     60 * interrupt handlers. */
     61#define RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE   RT_BIT(2)
     62/** @}  */
    10763
    10864/**
     
    11672/**
    11773 * Acquires the spinlock.
    118  * Interrupts are disabled upon return.
    11974 *
    12075 * @param   Spinlock    The spinlock to acquire.
    12176 * @param   pTmp        Where to save the state.
    12277 */
    123 RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
     78RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock);
    12479
    12580/**
     
    12984 * @param   pTmp        The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
    13085 */
    131 RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
     86RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock);
    13287
    133 /**
    134  * Acquires the spinlock.
    135  *
    136  * @param   Spinlock    The spinlock to acquire.
    137  * @param   pTmp        Where to save the state.
    138  */
    139 RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
    140 
    141 /**
    142  * Releases the spinlock.
    143  *
    144  * @param   Spinlock    The spinlock to acquire.
    145  * @param   pTmp        The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
    146  */
    147 RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
     88/* Temporarily, only for checking the spinlock creation flags. */
     89RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock);
    14890
    14991
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette