Add PQisthreadsafe() to libpq, to allow library applications to query
authorBruce Momjian
Tue, 23 May 2006 22:13:19 +0000 (22:13 +0000)
committerBruce Momjian
Tue, 23 May 2006 22:13:19 +0000 (22:13 +0000)
the thread-safety status of the library.

doc/src/sgml/libpq.sgml
src/interfaces/libpq/exports.txt
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/libpq-fe.h

index 0c24f2b773d84052f9d0a8d2c1821f3cba5b3360..229e9d5a28fef109467bbd7faa5ab87e5a2e87b9 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
  
   <application>libpq</application> - C Library
@@ -4196,11 +4196,32 @@ options when you compile your application code.  Refer to your
 system's documentation for information about how to build
 thread-enabled applications, or look in 
 src/Makefile.global for PTHREAD_CFLAGS
-and PTHREAD_LIBS.
+and PTHREAD_LIBS.  This function allows the querying of
+libpq's thread-safe status:
 
 
+
+
+PQisthreadsafePQisthreadsafe
+
+
+       Returns the thread safety status of the libpq
+       library.
+
+int PQisthreadsafe();
+
+
+
+
+       Returns 1 if the libpq is thead-safe and
+       0 if it is not.
+
+
+
+
+
 
-One restriction is that no two threads attempt to manipulate the same
+One thread restriction is that no two threads attempt to manipulate the same
 PGconn object at the same time. In particular, you cannot
 issue concurrent commands from different threads through the same
 connection object. (If you need to run concurrent commands, use
index 7fcd43b01aacc2b602236228ea35d1840513ae87..b50d062c0bc6eb70dc0bcb388c9377e53878bbc3 100644 (file)
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.8 2006/05/21 20:19:23 tgl Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.9 2006/05/23 22:13:19 momjian Exp $
 # Functions to be exported by libpq DLLs
 PQconnectdb               1
 PQsetdbLogin              2
@@ -128,3 +128,5 @@ PQregisterThreadLock      125
 PQescapeStringConn        126
 PQescapeByteaConn         127
 PQencryptPassword         128
+PQisthreadsafe            129
+
index 3139398946891fe07d015d5587c3d2889d08eb7b..7b999c853304cb11393e1a78f6f841abf98e197e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.183 2006/05/21 20:19:23 tgl Exp $
+ *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.184 2006/05/23 22:13:19 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2343,6 +2343,18 @@ PQisnonblocking(const PGconn *conn)
    return pqIsnonblocking(conn);
 }
 
+/* libpq is thread-safe? */
+int
+PQisthreadsafe(void)
+{
+#ifdef ENABLE_THREAD_SAFETY
+   return true;
+#else
+   return false;
+#endif
+}
+
+
 /* try to force data out, really only useful for non-blocking users */
 int
 PQflush(PGconn *conn)
index c309448bacf5cf52e57346f89d531257865b7132..3b824efe8526c65374cbdcd24ebd0117e8f407bb 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.128 2006/05/21 20:19:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.129 2006/05/23 22:13:19 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -366,6 +366,7 @@ extern int  PQendcopy(PGconn *conn);
 /* Set blocking/nonblocking connection to the backend */
 extern int PQsetnonblocking(PGconn *conn, int arg);
 extern int PQisnonblocking(const PGconn *conn);
+extern int PQisthreadsafe(void);
 
 /* Force the write buffer to be written (or at least try) */
 extern int PQflush(PGconn *conn);