|
55 | 55 | #ifdef HAVE_SYS_TIME_H |
56 | 56 | #include <sys/time.h> |
57 | 57 | #endif |
58 | | -#ifdef HAVE_POLL_F |
59 | | -#include <poll.h> |
60 | | -#endif |
61 | 58 | #include <math.h> |
62 | 59 | #include <time.h> |
63 | 60 |
|
|
72 | 69 |
|
73 | 70 | static NSDate *theFuture = nil; |
74 | 71 |
|
75 | | -@interface NSObject (OptionalPortRunLoop) |
76 | | -- (void) getFds: (NSInteger*)fds count: (NSInteger*)count; |
77 | | -@end |
78 | | - |
79 | 72 |
|
80 | 73 |
|
81 | 74 | /* |
@@ -436,6 +429,13 @@ - (void) receivedEvent: (void*)data |
436 | 429 |
|
437 | 430 | #endif |
438 | 431 |
|
| 432 | +typedef struct { |
| 433 | + void *sharedContextInfo; |
| 434 | +} RunLoopInternal; |
| 435 | + |
| 436 | +#define internal ((RunLoopInternal*)_internal) |
| 437 | + |
| 438 | + |
439 | 439 | @interface NSRunLoop (Private) |
440 | 440 |
|
441 | 441 | - (void) _addWatcher: (GSRunLoopWatcher*)item |
@@ -464,7 +464,8 @@ - (void) _addWatcher: (GSRunLoopWatcher*) item forMode: (NSString*)mode |
464 | 464 | context = NSMapGet(_contextMap, mode); |
465 | 465 | if (context == nil) |
466 | 466 | { |
467 | | - context = [[GSRunLoopCtxt alloc] initWithMode: mode extra: _extra]; |
| 467 | + context = [[GSRunLoopCtxt alloc] initWithMode: mode |
| 468 | + extra: &internal->sharedContextInfo]; |
468 | 469 | NSMapInsert(_contextMap, context->mode, context); |
469 | 470 | RELEASE(context); |
470 | 471 | } |
@@ -594,17 +595,14 @@ - (GSRunLoopWatcher*) _getWatcher: (void*)data |
594 | 595 |
|
595 | 596 | - (id) _init |
596 | 597 | { |
597 | | - self = [super init]; |
598 | | - if (self != nil) |
| 598 | + if (nil != (self = [super init])) |
599 | 599 | { |
600 | 600 | _contextStack = [NSMutableArray new]; |
601 | 601 | _contextMap = NSCreateMapTable (NSNonRetainedObjectMapKeyCallBacks, |
602 | 602 | NSObjectMapValueCallBacks, 0); |
603 | 603 | _timedPerformers = [[NSMutableArray alloc] initWithCapacity: 8]; |
604 | | -#ifdef HAVE_POLL_F |
605 | | - _extra = NSZoneMalloc(NSDefaultMallocZone(), sizeof(pollextra)); |
606 | | - memset(_extra, '\0', sizeof(pollextra)); |
607 | | -#endif |
| 604 | + _internal = (RunLoopInternal*) |
| 605 | + NSZoneCalloc(NSDefaultMallocZone(), 1, sizeof(RunLoopInternal)); |
608 | 606 | } |
609 | 607 | return self; |
610 | 608 | } |
@@ -850,15 +848,11 @@ - (id) init |
850 | 848 |
|
851 | 849 | - (void) dealloc |
852 | 850 | { |
853 | | -#ifdef HAVE_POLL_F |
854 | | - if (_extra != 0) |
855 | | - { |
856 | | - pollextra *e = (pollextra*)_extra; |
857 | | - if (e->index != 0) |
858 | | - NSZoneFree(NSDefaultMallocZone(), e->index); |
859 | | - NSZoneFree(NSDefaultMallocZone(), e); |
| 851 | + if (internal) |
| 852 | + { |
| 853 | + NSZoneFree(NSDefaultMallocZone(), internal); |
| 854 | + _internal = NULL; |
860 | 855 | } |
861 | | -#endif |
862 | 856 | RELEASE(_contextStack); |
863 | 857 | if (_contextMap != 0) |
864 | 858 | { |
@@ -924,7 +918,8 @@ - (void) addTimer: (NSTimer*)timer |
924 | 918 | context = NSMapGet(_contextMap, mode); |
925 | 919 | if (context == nil) |
926 | 920 | { |
927 | | - context = [[GSRunLoopCtxt alloc] initWithMode: mode extra: _extra]; |
| 921 | + context = [[GSRunLoopCtxt alloc] initWithMode: mode |
| 922 | + extra: &internal->sharedContextInfo]; |
928 | 923 | NSMapInsert(_contextMap, context->mode, context); |
929 | 924 | RELEASE(context); |
930 | 925 | } |
@@ -1550,7 +1545,7 @@ - (void) performSelector: (SEL)aSelector |
1550 | 1545 | if (context == nil) |
1551 | 1546 | { |
1552 | 1547 | context = [[GSRunLoopCtxt alloc] initWithMode: mode |
1553 | | - extra: _extra]; |
| 1548 | + extra: &internal->sharedContextInfo]; |
1554 | 1549 | NSMapInsert(_contextMap, context->mode, context); |
1555 | 1550 | RELEASE(context); |
1556 | 1551 | } |
|
0 commit comments