Author: rfm
Date: Tue Jun 21 19:47:15 2016
New Revision: 39900

URL: http://svn.gna.org/viewcvs/gnustep?rev=39900&view=rev
Log:
Only allow observers to be added from one runloop/thread at a time.

Modified:
    libs/sqlclient/trunk/Postgres.m

Modified: libs/sqlclient/trunk/Postgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=39900&r1=39899&r2=39900&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m     (original)
+++ libs/sqlclient/trunk/Postgres.m     Tue Jun 21 19:47:15 2016
@@ -510,12 +510,15 @@
   if (extra != 0 && connection != 0)
     {
 #if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
-      if (runLoop != nil)
-        {
-          [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
-                          type: ET_RDESC
-                       forMode: NSDefaultRunLoopMode
-                           all: YES];
+      if (extra != 0 && runLoop != nil)
+        {
+          if (connection != 0)
+            {
+              [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+                              type: ET_RDESC
+                           forMode: NSDefaultRunLoopMode
+                               all: YES];
+            }
           DESTROY(runLoop);
         }
 #endif
@@ -730,9 +733,17 @@
 {
   [self execute: @"LISTEN ", name, nil];
 #if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
-  if (nil == runLoop && 0 != connection)
-    {
-      ASSIGN(runLoop, [NSRunLoop currentRunLoop]);
+  if (extra != 0 && connection != 0)
+    {
+      if (nil == runLoop)
+        {
+          ASSIGN(runLoop, [NSRunLoop currentRunLoop]);
+        }
+      else if ([NSRunLoop currentRunLoop] != runLoop)
+        {
+          [NSException raise: NSInternalInconsistencyException
+            format: @"Observer added to the same client from another runloop"];
+        }
       [runLoop addEvent: (void*)(uintptr_t)PQsocket(connection)
                    type: ET_RDESC
                 watcher: self
@@ -1209,12 +1220,15 @@
 - (void) backendUnlisten: (NSString*)name
 {
 #if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
-  if (runLoop != nil)
-    {
-      [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
-                      type: ET_RDESC
-                   forMode: NSDefaultRunLoopMode
-                       all: YES];
+  if (extra != 0 && runLoop != nil)
+    {
+      if (connection != 0)
+        {
+          [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+                          type: ET_RDESC
+                       forMode: NSDefaultRunLoopMode
+                           all: YES];
+        }
       DESTROY(runLoop);
     }
 #endif


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to