Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Functions

thread-descriptor.c File Reference

#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
Include dependency graph for thread-descriptor.c:

Go to the source code of this file.

Data Structures

struct  sqlca_t

Defines

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
#define THREADS   16
#define REPEATS   50000
#define PGDLLIMPORT
#define SQLERRMC_LEN   150
#define sqlca   (*ECPGget_sqlca())

Functions

struct sqlca_tECPGget_sqlca (void)
static void * fn (void *arg)
int main ()

Define Documentation

#define ECPGdebug (   X,
  Y 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file thread-descriptor.c.

#define PGDLLIMPORT

Definition at line 33 of file thread-descriptor.c.

#define REPEATS   50000

Definition at line 22 of file thread-descriptor.c.

#define sqlca   (*ECPGget_sqlca())

Definition at line 84 of file thread-descriptor.c.

Referenced by fn().

#define SQLERRMC_LEN   150

Definition at line 37 of file thread-descriptor.c.

#define THREADS   16

Definition at line 21 of file thread-descriptor.c.


Function Documentation

struct sqlca_t* ECPGget_sqlca ( void   )  [read]

Definition at line 135 of file misc.c.

References ecpg_init_sqlca(), malloc, NULL, pthread_getspecific(), and pthread_setspecific().

Referenced by ecpg_execute(), ecpg_get_data(), ECPG_informix_reset_sqlca(), ecpg_init(), ecpg_log(), ecpg_raise(), ecpg_raise_backend(), ECPGallocate_desc(), ECPGconnect(), ECPGdeallocate_desc(), ECPGdisconnect(), ECPGget_desc(), ECPGget_desc_header(), ECPGnoticeReceiver(), ECPGset_var(), and sqlprint().

{
#ifdef ENABLE_THREAD_SAFETY
    struct sqlca_t *sqlca;

    pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);

    sqlca = pthread_getspecific(sqlca_key);
    if (sqlca == NULL)
    {
        sqlca = malloc(sizeof(struct sqlca_t));
        ecpg_init_sqlca(sqlca);
        pthread_setspecific(sqlca_key, sqlca);
    }
    return (sqlca);
#else
    return (&sqlca);
#endif
}

static void* fn ( void *  arg  )  [static]

Definition at line 105 of file thread-descriptor.c.

References ECPGallocate_desc(), ECPGdeallocate_desc(), i, sqlca, and sqlprint().

Referenced by _ArchiveEntry(), main(), and open_walfile().

{
    int i;

    for (i = 1; i <= REPEATS; ++i)
    {
        ECPGallocate_desc(__LINE__, "mydesc");
#line 29 "descriptor.pgc"

if (sqlca.sqlcode < 0) sqlprint();
#line 29 "descriptor.pgc"

        ECPGdeallocate_desc(__LINE__, "mydesc");
#line 30 "descriptor.pgc"

if (sqlca.sqlcode < 0) sqlprint();
#line 30 "descriptor.pgc"

    }

    return 0;
}

int main ( void   ) 

Definition at line 129 of file thread-descriptor.c.

References fn(), i, NULL, pthread_create, pthread_join, and TRUE.

{
#ifdef ENABLE_THREAD_SAFETY
    int i;
#ifdef WIN32
    HANDLE threads[THREADS];
#else
    pthread_t threads[THREADS];
#endif

#ifdef WIN32
    for (i = 0; i < THREADS; ++i)
    {
        unsigned id;
        threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
    }

    WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
    for (i = 0; i < THREADS; ++i)
        CloseHandle(threads[i]);
#else
    for (i = 0; i < THREADS; ++i)
        pthread_create(&threads[i], NULL, fn, NULL);
    for (i = 0; i < THREADS; ++i)
        pthread_join(threads[i], NULL);
#endif
#else
    fn(NULL);
#endif

    return 0;
}