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
This commit is contained in:
Richard Frith-MacDonald 2016-06-21 17:47:15 +00:00
parent 88ece98e6c
commit 3bb76c9230

View file

@ -510,12 +510,15 @@ connectQuote(NSString *str)
if (extra != 0 && connection != 0) if (extra != 0 && connection != 0)
{ {
#if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) #if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
if (runLoop != nil) if (extra != 0 && runLoop != nil)
{ {
[runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) if (connection != 0)
type: ET_RDESC {
forMode: NSDefaultRunLoopMode [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
all: YES]; type: ET_RDESC
forMode: NSDefaultRunLoopMode
all: YES];
}
DESTROY(runLoop); DESTROY(runLoop);
} }
#endif #endif
@ -730,9 +733,17 @@ connectQuote(NSString *str)
{ {
[self execute: @"LISTEN ", name, nil]; [self execute: @"LISTEN ", name, nil];
#if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) #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) [runLoop addEvent: (void*)(uintptr_t)PQsocket(connection)
type: ET_RDESC type: ET_RDESC
watcher: self watcher: self
@ -1209,12 +1220,15 @@ static inline unsigned int trim(char *str, unsigned len)
- (void) backendUnlisten: (NSString*)name - (void) backendUnlisten: (NSString*)name
{ {
#if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__) #if defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
if (runLoop != nil) if (extra != 0 && runLoop != nil)
{ {
[runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection) if (connection != 0)
type: ET_RDESC {
forMode: NSDefaultRunLoopMode [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
all: YES]; type: ET_RDESC
forMode: NSDefaultRunLoopMode
all: YES];
}
DESTROY(runLoop); DESTROY(runLoop);
} }
#endif #endif