LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - alloc.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 19 19 100.0 %
Date: 2024-11-21 09:14:53 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             : #ifdef WIN32
       6             : #define WIN32_LEAN_AND_MEAN
       7             : #include <windows.h>
       8             : #include <process.h>
       9             : #include <locale.h>
      10             : #else
      11             : #include <pthread.h>
      12             : #endif
      13             : #include <stdio.h>
      14             : 
      15             : #define THREADS     16
      16             : #define REPEATS     50
      17             : 
      18             : exec sql include sqlca;
      19             : exec sql include ../regression;
      20             : 
      21             : exec sql whenever sqlerror sqlprint;
      22             : exec sql whenever not found sqlprint;
      23             : 
      24             : #ifdef WIN32
      25             : static unsigned __stdcall fn(void* arg)
      26             : #else
      27          64 : static void* fn(void* arg)
      28             : #endif
      29             : {
      30             :     int i;
      31             : 
      32             :     EXEC SQL BEGIN DECLARE SECTION;
      33             :     int  value;
      34             :     char name[100];
      35          64 :     char **r = NULL;
      36             :     EXEC SQL END DECLARE SECTION;
      37             : 
      38          64 :     value = (intptr_t) arg;
      39          64 :     sprintf(name, "Connection: %d", value);
      40             : 
      41          64 :     EXEC SQL CONNECT TO REGRESSDB1 AS :name;
      42          64 :     EXEC SQL SET AUTOCOMMIT TO ON;
      43        3264 :     for (i = 1; i <= REPEATS; ++i)
      44             :     {
      45        3200 :         EXEC SQL SELECT relname INTO :r FROM pg_class WHERE relname = 'pg_class';
      46        3200 :         free(r);
      47        3200 :         r = NULL;
      48             :     }
      49          64 :     EXEC SQL DISCONNECT :name;
      50          64 : 
      51          64 :     return 0;
      52             : }
      53             : 
      54           4 : int main ()
      55             : {
      56             :     intptr_t i;
      57             : #ifdef WIN32
      58             :     HANDLE threads[THREADS];
      59             : #else
      60             :     pthread_t threads[THREADS];
      61             : #endif
      62             : 
      63             : #ifdef WIN32
      64             :     for (i = 0; i < THREADS; ++i)
      65             :     {
      66             :         unsigned id;
      67             :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
      68             :     }
      69             : 
      70             :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      71             :     for (i = 0; i < THREADS; ++i)
      72             :         CloseHandle(threads[i]);
      73             : #else
      74          68 :     for (i = 0; i < THREADS; ++i)
      75          64 :         pthread_create(&threads[i], NULL, fn, (void *) i);
      76          68 :     for (i = 0; i < THREADS; ++i)
      77          64 :         pthread_join(threads[i], NULL);
      78             : #endif
      79             : 
      80           4 :     return 0;
      81             : }

Generated by: LCOV version 1.14