LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - prep.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 26 26 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 query[256] = "INSERT INTO T VALUES ( ? )";
      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        3264 :     for (i = 1; i <= REPEATS; ++i)
      51             :     {
      52        3200 :         EXEC SQL PREPARE I FROM :query;
      53        3200 :         EXEC SQL EXECUTE I USING :value;
      54        3200 :     }
      55          64 :     EXEC SQL DEALLOCATE I;
      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           4 :     EXEC SQL CONNECT TO REGRESSDB1;
      71           4 :     EXEC SQL SET AUTOCOMMIT TO ON;
      72           4 :     EXEC SQL DROP TABLE IF EXISTS T;
      73           4 :     EXEC SQL CREATE TABLE T ( i int );
      74           4 :     EXEC SQL DISCONNECT;
      75           4 : 
      76             : #ifdef WIN32
      77             :     for (i = 0; i < THREADS; ++i)
      78             :     {
      79             :         unsigned id;
      80             :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
      81             :     }
      82             : 
      83             :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      84             :     for (i = 0; i < THREADS; ++i)
      85             :         CloseHandle(threads[i]);
      86             : #else
      87          68 :     for (i = 0; i < THREADS; ++i)
      88          64 :         pthread_create(&threads[i], NULL, fn, (void *) (long) i);
      89          68 :     for (i = 0; i < THREADS; ++i)
      90          64 :         pthread_join(threads[i], NULL);
      91             : #endif
      92             : 
      93           4 :     return 0;
      94             : }
      95             : #endif

Generated by: LCOV version 1.13