~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/test/expected/thread-alloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Processed by ecpg (regression mode) */
 
2
/* These include files are added by the preprocessor */
 
3
#include <ecpglib.h>
 
4
#include <ecpgerrno.h>
 
5
#include <sqlca.h>
 
6
/* End of automatic include section */
 
7
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
 
8
 
 
9
#line 1 "alloc.pgc"
 
10
#include <stdlib.h>
 
11
#include "ecpg_config.h"
 
12
 
 
13
#ifndef ENABLE_THREAD_SAFETY
 
14
int
 
15
main(void)
 
16
{
 
17
        printf("No threading enabled.\n");
 
18
        return 0;
 
19
}
 
20
#else
 
21
#ifdef WIN32
 
22
#define WIN32_LEAN_AND_MEAN
 
23
#include <windows.h>
 
24
#include <process.h>
 
25
#else
 
26
#include <pthread.h>
 
27
#endif
 
28
#include <stdio.h>
 
29
 
 
30
#define THREADS         16
 
31
#define REPEATS         50
 
32
 
 
33
 
 
34
#line 1 "sqlca.h"
 
35
#ifndef POSTGRES_SQLCA_H
 
36
#define POSTGRES_SQLCA_H
 
37
 
 
38
#ifndef PGDLLIMPORT
 
39
#if  defined(WIN32) || defined(__CYGWIN__)
 
40
#define PGDLLIMPORT __declspec (dllimport)
 
41
#else
 
42
#define PGDLLIMPORT
 
43
#endif   /* __CYGWIN__ */
 
44
#endif   /* PGDLLIMPORT */
 
45
 
 
46
#define SQLERRMC_LEN    150
 
47
 
 
48
#ifdef __cplusplus
 
49
extern          "C"
 
50
{
 
51
#endif
 
52
 
 
53
struct sqlca_t
 
54
{
 
55
        char            sqlcaid[8];
 
56
        long            sqlabc;
 
57
        long            sqlcode;
 
58
        struct
 
59
        {
 
60
                int                     sqlerrml;
 
61
                char            sqlerrmc[SQLERRMC_LEN];
 
62
        }                       sqlerrm;
 
63
        char            sqlerrp[8];
 
64
        long            sqlerrd[6];
 
65
        /* Element 0: empty                                             */
 
66
        /* 1: OID of processed tuple if applicable                      */
 
67
        /* 2: number of rows processed                          */
 
68
        /* after an INSERT, UPDATE or                           */
 
69
        /* DELETE statement                                     */
 
70
        /* 3: empty                                             */
 
71
        /* 4: empty                                             */
 
72
        /* 5: empty                                             */
 
73
        char            sqlwarn[8];
 
74
        /* Element 0: set to 'W' if at least one other is 'W'   */
 
75
        /* 1: if 'W' at least one character string              */
 
76
        /* value was truncated when it was                      */
 
77
        /* stored into a host variable.                         */
 
78
 
 
79
        /*
 
80
         * 2: if 'W' a (hopefully) non-fatal notice occurred
 
81
         */     /* 3: empty */
 
82
        /* 4: empty                                             */
 
83
        /* 5: empty                                             */
 
84
        /* 6: empty                                             */
 
85
        /* 7: empty                                             */
 
86
 
 
87
        char            sqlstate[5];
 
88
};
 
89
 
 
90
struct sqlca_t *ECPGget_sqlca(void);
 
91
 
 
92
#ifndef POSTGRES_ECPG_INTERNAL
 
93
#define sqlca (*ECPGget_sqlca())
 
94
#endif
 
95
 
 
96
#ifdef __cplusplus
 
97
}
 
98
#endif
 
99
 
 
100
#endif
 
101
 
 
102
#line 24 "alloc.pgc"
 
103
 
 
104
 
 
105
#line 1 "regression.h"
 
106
 
 
107
 
 
108
 
 
109
 
 
110
 
 
111
 
 
112
#line 25 "alloc.pgc"
 
113
 
 
114
 
 
115
/* exec sql whenever sqlerror  sqlprint ; */
 
116
#line 27 "alloc.pgc"
 
117
 
 
118
/* exec sql whenever not found  sqlprint ; */
 
119
#line 28 "alloc.pgc"
 
120
 
 
121
 
 
122
#ifdef WIN32
 
123
static unsigned __stdcall fn(void* arg)
 
124
#else
 
125
static void* fn(void* arg)
 
126
#endif
 
127
{
 
128
        int i;
 
129
 
 
130
        /* exec sql begin declare section */
 
131
          
 
132
         
 
133
           
 
134
        
 
135
#line 39 "alloc.pgc"
 
136
 int value ;
 
137
 
 
138
#line 40 "alloc.pgc"
 
139
 char name [ 100 ] ;
 
140
 
 
141
#line 41 "alloc.pgc"
 
142
 char ** r = NULL ;
 
143
/* exec sql end declare section */
 
144
#line 42 "alloc.pgc"
 
145
 
 
146
 
 
147
        value = (long)arg;
 
148
        sprintf(name, "Connection: %d", value);
 
149
 
 
150
        { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , name, 0); 
 
151
#line 47 "alloc.pgc"
 
152
 
 
153
if (sqlca.sqlcode < 0) sqlprint();}
 
154
#line 47 "alloc.pgc"
 
155
 
 
156
        { ECPGsetcommit(__LINE__, "on", NULL);
 
157
#line 48 "alloc.pgc"
 
158
 
 
159
if (sqlca.sqlcode < 0) sqlprint();}
 
160
#line 48 "alloc.pgc"
 
161
 
 
162
        for (i = 1; i <= REPEATS; ++i)
 
163
        {
 
164
                { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT, 
 
165
        ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char), 
 
166
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 
167
#line 51 "alloc.pgc"
 
168
 
 
169
if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
 
170
#line 51 "alloc.pgc"
 
171
 
 
172
if (sqlca.sqlcode < 0) sqlprint();}
 
173
#line 51 "alloc.pgc"
 
174
 
 
175
                free(r);
 
176
                r = NULL;
 
177
        }
 
178
        { ECPGdisconnect(__LINE__, name);
 
179
#line 55 "alloc.pgc"
 
180
 
 
181
if (sqlca.sqlcode < 0) sqlprint();}
 
182
#line 55 "alloc.pgc"
 
183
 
 
184
 
 
185
        return 0;
 
186
}
 
187
 
 
188
int main (int argc, char** argv)
 
189
{
 
190
        int i;
 
191
#ifdef WIN32
 
192
        HANDLE threads[THREADS];
 
193
#else
 
194
        pthread_t threads[THREADS];
 
195
#endif
 
196
 
 
197
#ifdef WIN32
 
198
        for (i = 0; i < THREADS; ++i)
 
199
        {
 
200
                unsigned id;
 
201
                threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
 
202
        }
 
203
 
 
204
        WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
 
205
        for (i = 0; i < THREADS; ++i)
 
206
                CloseHandle(threads[i]);
 
207
#else
 
208
        for (i = 0; i < THREADS; ++i)
 
209
                pthread_create(&threads[i], NULL, fn, (void *) (long) i);
 
210
        for (i = 0; i < THREADS; ++i)
 
211
                pthread_join(threads[i], NULL);
 
212
#endif
 
213
 
 
214
        return 0;
 
215
}
 
216
#endif
 
217