Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c1d4551

Browse files
committed
Add PQisthreadsafe() to libpq, to allow library applications to query
the thread-safety status of the library.
1 parent 7f52e0c commit c1d4551

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.210 2006/05/21 20:19:23 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.211 2006/05/23 22:13:19 momjian Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -4196,11 +4196,32 @@ options when you compile your application code. Refer to your
41964196
system's documentation for information about how to build
41974197
thread-enabled applications, or look in
41984198
<filename>src/Makefile.global</filename> for <literal>PTHREAD_CFLAGS</>
4199-
and <literal>PTHREAD_LIBS</>.
4199+
and <literal>PTHREAD_LIBS</>. This function allows the querying of
4200+
<application>libpq</application>'s thread-safe status:
42004201
</para>
42014202

4203+
<variablelist>
4204+
<varlistentry>
4205+
<term><function>PQisthreadsafe</function><indexterm><primary>PQisthreadsafe</></></term>
4206+
<listitem>
4207+
<para>
4208+
Returns the thread safety status of the <application>libpq</application>
4209+
library.
4210+
<synopsis>
4211+
int PQisthreadsafe();
4212+
</synopsis>
4213+
</para>
4214+
4215+
<para>
4216+
Returns 1 if the <application>libpq</application> is thead-safe and
4217+
0 if it is not.
4218+
</para>
4219+
</listitem>
4220+
</varlistentry>
4221+
</variablelist>
4222+
42024223
<para>
4203-
One restriction is that no two threads attempt to manipulate the same
4224+
One thread restriction is that no two threads attempt to manipulate the same
42044225
<structname>PGconn</> object at the same time. In particular, you cannot
42054226
issue concurrent commands from different threads through the same
42064227
connection object. (If you need to run concurrent commands, use

src/interfaces/libpq/exports.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.8 2006/05/21 20:19:23 tgl Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.9 2006/05/23 22:13:19 momjian Exp $
22
# Functions to be exported by libpq DLLs
33
PQconnectdb 1
44
PQsetdbLogin 2
@@ -128,3 +128,5 @@ PQregisterThreadLock 125
128128
PQescapeStringConn 126
129129
PQescapeByteaConn 127
130130
PQencryptPassword 128
131+
PQisthreadsafe 129
132+

src/interfaces/libpq/fe-exec.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.183 2006/05/21 20:19:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.184 2006/05/23 22:13:19 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2343,6 +2343,18 @@ PQisnonblocking(const PGconn *conn)
23432343
return pqIsnonblocking(conn);
23442344
}
23452345

2346+
/* libpq is thread-safe? */
2347+
int
2348+
PQisthreadsafe(void)
2349+
{
2350+
#ifdef ENABLE_THREAD_SAFETY
2351+
return true;
2352+
#else
2353+
return false;
2354+
#endif
2355+
}
2356+
2357+
23462358
/* try to force data out, really only useful for non-blocking users */
23472359
int
23482360
PQflush(PGconn *conn)

src/interfaces/libpq/libpq-fe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.128 2006/05/21 20:19:23 tgl Exp $
10+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.129 2006/05/23 22:13:19 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -366,6 +366,7 @@ extern int PQendcopy(PGconn *conn);
366366
/* Set blocking/nonblocking connection to the backend */
367367
extern int PQsetnonblocking(PGconn *conn, int arg);
368368
extern int PQisnonblocking(const PGconn *conn);
369+
extern int PQisthreadsafe(void);
369370

370371
/* Force the write buffer to be written (or at least try) */
371372
extern int PQflush(PGconn *conn);

0 commit comments

Comments
 (0)