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

Generated by: LCOV version 1.13