LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - alloc.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 19 19 100.0 %
Date: 2019-06-19 14:06:47 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include "ecpg_config.h"
       3             : 
       4             : #ifndef ENABLE_THREAD_SAFETY
       5             : int
       6             : main(void)
       7             : {
       8             :     printf("No threading enabled.\n");
       9             :     return 0;
      10             : }
      11             : #else
      12             : #ifdef WIN32
      13             : #define WIN32_LEAN_AND_MEAN
      14             : #include <windows.h>
      15             : #include <process.h>
      16             : #include <locale.h>
      17             : #else
      18             : #include <pthread.h>
      19             : #endif
      20             : #include <stdio.h>
      21             : 
      22             : #define THREADS     16
      23             : #define REPEATS     50
      24             : 
      25             : exec sql include sqlca;
      26             : exec sql include ../regression;
      27             : 
      28             : exec sql whenever sqlerror sqlprint;
      29             : exec sql whenever not found sqlprint;
      30             : 
      31             : #ifdef WIN32
      32             : static unsigned __stdcall fn(void* arg)
      33             : #else
      34          64 : static void* fn(void* arg)
      35             : #endif
      36             : {
      37             :     int i;
      38             : 
      39             :     EXEC SQL BEGIN DECLARE SECTION;
      40             :     int  value;
      41             :     char name[100];
      42          64 :     char **r = NULL;
      43             :     EXEC SQL END DECLARE SECTION;
      44             : 
      45          64 :     value = (long)arg;
      46          64 :     sprintf(name, "Connection: %d", value);
      47             : 
      48          64 :     EXEC SQL CONNECT TO REGRESSDB1 AS :name;
      49          64 :     EXEC SQL SET AUTOCOMMIT TO ON;
      50        3260 :     for (i = 1; i <= REPEATS; ++i)
      51             :     {
      52        3198 :         EXEC SQL SELECT relname INTO :r FROM pg_class WHERE relname = 'pg_class';
      53        3190 :         free(r);
      54        3196 :         r = NULL;
      55             :     }
      56          64 :     EXEC SQL DISCONNECT :name;
      57          64 : 
      58          64 :     return 0;
      59             : }
      60             : 
      61           4 : int main ()
      62             : {
      63             :     int i;
      64             : #ifdef WIN32
      65             :     HANDLE threads[THREADS];
      66             : #else
      67             :     pthread_t threads[THREADS];
      68             : #endif
      69             : 
      70             : #ifdef WIN32
      71             :     for (i = 0; i < THREADS; ++i)
      72             :     {
      73             :         unsigned id;
      74             :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
      75             :     }
      76             : 
      77             :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      78             :     for (i = 0; i < THREADS; ++i)
      79             :         CloseHandle(threads[i]);
      80             : #else
      81          68 :     for (i = 0; i < THREADS; ++i)
      82          64 :         pthread_create(&threads[i], NULL, fn, (void *) (long) i);
      83          68 :     for (i = 0; i < THREADS; ++i)
      84          64 :         pthread_join(threads[i], NULL);
      85             : #endif
      86             : 
      87           4 :     return 0;
      88             : }
      89             : #endif

Generated by: LCOV version 1.13