LCOV - differential code coverage report
Current view: top level - src/port - pgsleep.c (source / functions) Coverage Total Hit GIC GNC CBC ECB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 100.0 % 6 6 3 2 1 2 3
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 1 1 1 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 [..60] days: 100.0 % 2 2 2
Legend: Lines: hit not hit (240..) days: 100.0 % 4 4 3 1 2
Function coverage date bins:
(240..) days: 100.0 % 1 1 1

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * pgsleep.c
                                  4                 :  *     Portable delay handling.
                                  5                 :  *
                                  6                 :  *
                                  7                 :  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
                                  8                 :  *
                                  9                 :  * src/port/pgsleep.c
                                 10                 :  *
                                 11                 :  *-------------------------------------------------------------------------
                                 12                 :  */
                                 13                 : #include "c.h"
                                 14                 : 
                                 15                 : #include <time.h>
                                 16                 : 
                                 17                 : /*
                                 18                 :  * In a Windows backend, we don't use this implementation, but rather
                                 19                 :  * the signal-aware version in src/backend/port/win32/signal.c.
                                 20                 :  */
                                 21                 : #if defined(FRONTEND) || !defined(WIN32)
                                 22                 : 
                                 23                 : /*
                                 24                 :  * pg_usleep --- delay the specified number of microseconds.
                                 25                 :  *
                                 26                 :  * NOTE: Although the delay is specified in microseconds, older Unixen and
                                 27                 :  * Windows use periodic kernel ticks to wake up, which might increase the delay
                                 28                 :  * time significantly.  We've observed delay increases as large as 20
                                 29                 :  * milliseconds on supported platforms.
                                 30                 :  *
                                 31                 :  * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds.
                                 32                 :  *
                                 33                 :  * CAUTION: It's not a good idea to use long sleeps in the backend.  They will
                                 34                 :  * silently return early if a signal is caught, but that doesn't include
                                 35                 :  * latches being set on most OSes, and even signal handlers that set MyLatch
                                 36                 :  * might happen to run before the sleep begins, allowing the full delay.
                                 37                 :  * Better practice is to use WaitLatch() with a timeout, so that backends
                                 38                 :  * respond to latches and signals promptly.
                                 39                 :  */
                                 40                 : void
 6998 tgl                        41 GIC        5748 : pg_usleep(long microsec)
 6998 tgl                        42 ECB             : {
 6998 tgl                        43 CBC        5748 :     if (microsec > 0)
 6998 tgl                        44 ECB             :     {
                                 45                 : #ifndef WIN32
                                 46                 :         struct timespec delay;
                                 47                 : 
 6998 tgl                        48 GIC        5748 :         delay.tv_sec = microsec / 1000000L;
   25 tmunro                     49 GNC        5748 :         delay.tv_nsec = (microsec % 1000000L) * 1000;
                                 50            5748 :         (void) nanosleep(&delay, NULL);
                                 51                 : #else
                                 52                 :         SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
                                 53                 : #endif
                                 54                 :     }
 6998 tgl                        55 GIC        5748 : }
                                 56                 : 
                                 57                 : #endif                          /* defined(FRONTEND) || !defined(WIN32) */
        

Generated by: LCOV version v1.16-55-g56c0a2a