LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - alloc.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 19 19 100.0 %
Date: 2020-05-25 05:06:35 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13