LCOV - code coverage report
Current view: top level - src/include/storage - spin.h (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 9 9
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 2 2

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * spin.h
       4                 :             :  *     API for spinlocks.
       5                 :             :  *
       6                 :             :  *
       7                 :             :  *  The interface to spinlocks is defined by the typedef "slock_t" and
       8                 :             :  *  these functions:
       9                 :             :  *
      10                 :             :  *  void SpinLockInit(volatile slock_t *lock)
      11                 :             :  *      Initialize a spinlock (to the unlocked state).
      12                 :             :  *
      13                 :             :  *  void SpinLockAcquire(volatile slock_t *lock)
      14                 :             :  *      Acquire a spinlock, waiting if necessary.
      15                 :             :  *      Time out and abort() if unable to acquire the lock in a
      16                 :             :  *      "reasonable" amount of time --- typically ~ 1 minute.
      17                 :             :  *
      18                 :             :  *  void SpinLockRelease(volatile slock_t *lock)
      19                 :             :  *      Unlock a previously acquired lock.
      20                 :             :  *
      21                 :             :  *  Load and store operations in calling code are guaranteed not to be
      22                 :             :  *  reordered with respect to these operations, because they include a
      23                 :             :  *  compiler barrier.  (Before PostgreSQL 9.5, callers needed to use a
      24                 :             :  *  volatile qualifier to access data protected by spinlocks.)
      25                 :             :  *
      26                 :             :  *  Keep in mind the coding rule that spinlocks must not be held for more
      27                 :             :  *  than a few instructions.  In particular, we assume it is not possible
      28                 :             :  *  for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so
      29                 :             :  *  it is not necessary to do HOLD/RESUME_INTERRUPTS() in these functions.
      30                 :             :  *
      31                 :             :  *  These functions are implemented in terms of hardware-dependent macros
      32                 :             :  *  supplied by s_lock.h.  There is not currently any extra functionality
      33                 :             :  *  added by this header, but there has been in the past and may someday
      34                 :             :  *  be again.
      35                 :             :  *
      36                 :             :  *
      37                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
      38                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
      39                 :             :  *
      40                 :             :  * src/include/storage/spin.h
      41                 :             :  *
      42                 :             :  *-------------------------------------------------------------------------
      43                 :             :  */
      44                 :             : #ifndef SPIN_H
      45                 :             : #define SPIN_H
      46                 :             : 
      47                 :             : #include "storage/s_lock.h"
      48                 :             : 
      49                 :             : static inline void
      50                 :    20234891 : SpinLockInit(volatile slock_t *lock)
      51                 :             : {
      52                 :    20234891 :     S_INIT_LOCK(lock);
      53                 :    20234891 : }
      54                 :             : 
      55                 :             : static inline void
      56                 :    78328739 : SpinLockAcquire(volatile slock_t *lock)
      57                 :             : {
      58         [ +  + ]:    78328739 :     S_LOCK(lock);
      59                 :    78328739 : }
      60                 :             : 
      61                 :             : static inline void
      62                 :    78328739 : SpinLockRelease(volatile slock_t *lock)
      63                 :             : {
      64                 :    78328739 :     S_UNLOCK(lock);
      65                 :    78328739 : }
      66                 :             : 
      67                 :             : #endif                          /* SPIN_H */
        

Generated by: LCOV version 2.0-1