LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - descriptor.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 12 12 100.0 %
Date: 2024-04-18 04:11:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifdef WIN32
       2             : #define WIN32_LEAN_AND_MEAN
       3             : #include <windows.h>
       4             : #include <process.h>
       5             : #include <locale.h>
       6             : #else
       7             : #include <pthread.h>
       8             : #endif
       9             : #include <stdio.h>
      10             : 
      11             : #define THREADS     16
      12             : #define REPEATS     50000
      13             : 
      14             : EXEC SQL include sqlca;
      15             : EXEC SQL whenever sqlerror sqlprint;
      16             : EXEC SQL whenever not found sqlprint;
      17             : 
      18             : #if defined(WIN32)
      19             : static unsigned __stdcall fn(void* arg)
      20             : #else
      21          64 : static void* fn(void* arg)
      22             : #endif
      23             : {
      24             :     int i;
      25             : 
      26     3200064 :     for (i = 1; i <= REPEATS; ++i)
      27             :     {
      28     3200000 :         EXEC SQL ALLOCATE DESCRIPTOR mydesc;
      29     3200000 :         EXEC SQL DEALLOCATE DESCRIPTOR mydesc;
      30     3200000 :     }
      31             : 
      32          64 :     return 0;
      33             : }
      34             : 
      35           4 : int main ()
      36             : {
      37             :     int i;
      38             : #ifdef WIN32
      39             :     HANDLE threads[THREADS];
      40             : #else
      41             :     pthread_t threads[THREADS];
      42             : #endif
      43             : 
      44             : #ifdef WIN32
      45             :     for (i = 0; i < THREADS; ++i)
      46             :     {
      47             :         unsigned id;
      48             :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
      49             :     }
      50             : 
      51             :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      52             :     for (i = 0; i < THREADS; ++i)
      53             :         CloseHandle(threads[i]);
      54             : #else
      55          68 :     for (i = 0; i < THREADS; ++i)
      56          64 :         pthread_create(&threads[i], NULL, fn, NULL);
      57          68 :     for (i = 0; i < THREADS; ++i)
      58          64 :         pthread_join(threads[i], NULL);
      59             : #endif
      60             : 
      61           4 :     return 0;
      62             : }

Generated by: LCOV version 1.14