From 3bb76c9230be21d10979e412db6ea1c0ae115b78 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 21 Jun 2016 17:47:15 +0000 Subject: [PATCH] Only allow observers to be added from one runloop/thread at a time. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@39900 72102866-910b-0410-8b05-ffd578937521 --- Postgres.m | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Postgres.m b/Postgres.m index 3b8302b..9869652 100644 --- a/Postgres.m +++ b/Postgres.m @@ -510,12 +510,15 @@ connectQuote(NSString *str) if (extra != 0 && connection != 0) { #if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) - if (runLoop != nil) + if (extra != 0 && runLoop != nil) { - [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) - type: ET_RDESC - forMode: NSDefaultRunLoopMode - all: YES]; + if (connection != 0) + { + [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) + type: ET_RDESC + forMode: NSDefaultRunLoopMode + all: YES]; + } DESTROY(runLoop); } #endif @@ -730,9 +733,17 @@ connectQuote(NSString *str) { [self execute: @"LISTEN ", name, nil]; #if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) - if (nil == runLoop && 0 != connection) + if (extra != 0 && connection != 0) { - ASSIGN(runLoop, [NSRunLoop currentRunLoop]); + 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 @@ static inline unsigned int trim(char *str, unsigned len) - (void) backendUnlisten: (NSString*)name { #if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) - if (runLoop != nil) + if (extra != 0 && runLoop != nil) { - [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) - type: ET_RDESC - forMode: NSDefaultRunLoopMode - all: YES]; + if (connection != 0) + { + [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) + type: ET_RDESC + forMode: NSDefaultRunLoopMode + all: YES]; + } DESTROY(runLoop); } #endif