LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - descriptor.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 9 9 100.0 %
Date: 2019-09-19 17:07:13 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13