Small runloop tidyup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22702 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-03-24 10:59:00 +00:00
parent e3f9f6025c
commit 9f5d3f0298
5 changed files with 62 additions and 46 deletions

View file

@ -1,3 +1,10 @@
2006-03-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSRunLoopCtxt.h:
* Source/unix/GSRunLoopCtxt.m:
* Source/win32/GSRunLoopCtxt.m:
Tidy/improve removal of triggered watchers from outer contexts.
2006-03-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/unix/GSRunLoopWatcher.m: deleted

View file

@ -804,7 +804,11 @@ GSIMapAddKey(GSIMapTable map, GSIMapKey key)
}
#endif
static INLINE void
/**
* Removes the item for the specified key from the map.
* If the key was present, returns YES, otherwise returns NO.
*/
static INLINE BOOL
GSIMapRemoveKey(GSIMapTable map, GSIMapKey key)
{
GSIMapBucket bucket = GSIMapBucketForKey(map, key);
@ -815,7 +819,9 @@ GSIMapRemoveKey(GSIMapTable map, GSIMapKey key)
{
GSIMapRemoveNodeFromMap(map, bucket, node);
GSIMapFreeNode(map, node);
return YES;
}
return NO;
}
static INLINE void

View file

@ -30,6 +30,7 @@ typedef struct{
#endif
@class NSString;
@class GSRunLoopWatcher;
@interface GSRunLoopCtxt : NSObject
{
@ -59,7 +60,7 @@ typedef struct{
#endif
}
- (void) endEvent: (void*)data
type: (RunLoopEventType)type;
for: (GSRunLoopWatcher*)watcher;
- (void) endPoll;
- (id) initWithMode: (NSString*)theMode extra: (void*)e;
- (BOOL) pollUntil: (int)milliseconds within: (NSArray*)contexts;

View file

@ -102,12 +102,26 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
* loop and once by the outer one.
*/
- (void) endEvent: (void*)data
type: (RunLoopEventType)type
for: (GSRunLoopWatcher*)watcher
{
if (completed == NO)
{
switch (type)
unsigned i = GSIArrayCount(_trigger);
while (i-- > 0)
{
GSIArrayItem item = GSIArrayItemAtIndex(_trigger, i);
if (item.obj == (id)watcher)
{
GSIArrayRemoveItemAtIndex(_trigger, i);
return;
}
}
switch (watcher->type)
{
case ET_RPORT:
case ET_RDESC:
NSMapRemove(_rfdMap, data);
break;
@ -118,22 +132,10 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
NSMapRemove(_efdMap, data);
break;
case ET_TRIGGER:
{
unsigned i = GSIArrayCount(_trigger);
while (i-- > 0)
{
GSIArrayItem item = GSIArrayItemAtIndex(_trigger, i);
if (item.obj == (id)data)
{
GSIArrayRemoveItemAtIndex(_trigger, i);
}
}
}
// Already handled
break;
default:
NSLog(@"Ending an event of unexpected type (%d)", type);
NSLog(@"Ending an event of unexpected type (%d)", watcher->type);
break;
}
}
@ -430,7 +432,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (c != self)
{
[c endEvent: (void*)watcher type: ET_TRIGGER];
[c endEvent: (void*)watcher for: watcher];
}
}
/*
@ -505,7 +507,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (c != self)
{
[c endEvent: (void*)(intptr_t)fd type: ET_EDESC];
[c endEvent: (void*)(intptr_t)fd for: watcher];
}
}
/*
@ -537,7 +539,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (c != self)
{
[c endEvent: (void*)(intptr_t)fd type: ET_WDESC];
[c endEvent: (void*)(intptr_t)fd for: watcher];
}
}
/*
@ -569,7 +571,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (c != self)
{
[c endEvent: (void*)(intptr_t)fd type: ET_RDESC];
[c endEvent: (void*)(intptr_t)fd for: watcher];
}
}
/*
@ -811,7 +813,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (c != self)
{
[c endEvent: (void*)watcher type: ET_TRIGGER];
[c endEvent: (void*)watcher for: watcher];
}
}
/*
@ -873,7 +875,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (c != self)
[c endEvent: (void*)(intptr_t)fdIndex type: ET_EDESC];
[c endEvent: (void*)(intptr_t)fdIndex for: watcher];
}
/*
* The watcher is still valid - so call its receivers
@ -905,7 +907,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (c != self)
[c endEvent: (void*)(intptr_t)fdIndex type: ET_WDESC];
[c endEvent: (void*)(intptr_t)fdIndex for: watcher];
}
/*
* The watcher is still valid - so call its receivers
@ -937,7 +939,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (c != self)
[c endEvent: (void*)(intptr_t)fdIndex type: ET_RDESC];
[c endEvent: (void*)(intptr_t)fdIndex for: watcher];
}
/*
* The watcher is still valid - so call its receivers

View file

@ -79,12 +79,24 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
* loop and once by the outer one.
*/
- (void) endEvent: (void*)data
type: (RunLoopEventType)type
for: (GSRunLoopWatcher)*watcher
{
if (completed == NO)
{
switch (type)
unsigned i = GSIArrayCount(_trigger);
while (i-- > 0)
{
GSIArrayItem item = GSIArrayItemAtIndex(_trigger, i);
if (item.obj == (id)watcher)
{
GSIArrayRemoveItemAtIndex(_trigger, i);
}
}
switch (watcher->type)
{
case ET_RPORT:
case ET_HANDLE:
NSMapRemove(handleMap, data);
break;
@ -92,22 +104,10 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
NSMapRemove(winMsgMap, data);
break;
case ET_TRIGGER:
{
unsigned i = GSIArrayCount(_trigger);
while (i-- > 0)
{
GSIArrayItem item = GSIArrayItemAtIndex(_trigger, i);
if (item.obj == (id)data)
{
GSIArrayRemoveItemAtIndex(_trigger, i);
}
}
}
// Already handled
break;
default:
NSLog(@"Ending an event of unexpected type (%d)", type);
NSLog(@"Ending an event of unexpected type (%d)", watcher->type);
break;
}
}
@ -202,7 +202,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
if (c != self)
{
[c endEvent: (void*)handle type: ET_WINMSG];
[c endEvent: (void*)handle for: watcher];
}
}
handled = YES;
@ -244,7 +244,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
if (c != self)
{
[c endEvent: (void*)handle type: ET_WINMSG];
[c endEvent: (void*)handle for: watcher];
}
}
handled = YES;
@ -471,7 +471,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
if (c != self)
{
[c endEvent: (void*)watcher type: ET_TRIGGER];
[c endEvent: (void*)watcher for: watcher];
}
}
/*
@ -521,7 +521,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
if (c != self)
{
[c endEvent: (void*)handle type: ET_HANDLE];
[c endEvent: (void*)handle for: watcher];
}
}
/*