Permalink
Browse files

New message queue system. Work in progress.

  • Loading branch information...
1 parent 6def6c7 commit 9ee90ee04eb3299175c9dbdc59d40df86a16a929 @emsquared emsquared committed Jul 29, 2012
@@ -73,6 +73,8 @@
@property (nonatomic, strong) NSDictionary *bundlesForUserInput;
@property (nonatomic, strong) NSDictionary *bundlesForServerInput;
@property (nonatomic, strong) NSDictionary *bundlesWithOutputRules;
+@property (nonatomic, assign) dispatch_queue_t frontmostViewMessageQueue;
+@property (nonatomic, assign) dispatch_queue_t backgroundViewMessageQueue;
- (void)setup:(IRCWorldConfig *)seed;
- (void)setupTree;
@@ -56,7 +56,6 @@ typedef BOOL (^TVCLogMessageBlock)(void);
@property (nonatomic, strong) WebScriptObject *js;
@property (nonatomic, assign) BOOL bottom;
@property (nonatomic, assign) BOOL loaded;
-@property (nonatomic, assign) BOOL queueInProgress;
@property (nonatomic, assign) BOOL viewingBottom;
@property (nonatomic, assign) BOOL scrollBottom;
@property (nonatomic, assign) BOOL becameVisible;
@@ -68,9 +67,10 @@ typedef BOOL (^TVCLogMessageBlock)(void);
@property (nonatomic, assign) NSInteger lineNumber;
@property (nonatomic, assign) NSInteger loadingImages;
@property (nonatomic, assign) NSInteger lastVisitedHighlight;
-@property (nonatomic, strong) NSMutableArray *messageQueue;
@property (nonatomic, strong) NSMutableArray *highlightedLineNumbers;
-@property (nonatomic, assign) dispatch_queue_t messageQueueDispatch;
+
+@property (strong) NSMutableArray *messageQueue;
+@property (assign) BOOL queueInProgress;
- (void)setUp;
- (void)restorePosition;
@@ -85,8 +85,7 @@ typedef BOOL (^TVCLogMessageBlock)(void);
- (void)moveToTop;
- (void)moveToBottom;
-- (void)destroyViewLoop;
-- (void)createViewLoop;
+- (void)runMessageQueueLoop; // Only Textual should call this.
- (void)setTopic:(NSString *)topic;
@@ -42,7 +42,7 @@ @implementation NSScreen (TXScreenHelper)
- (BOOL)runningInHighResolutionMode
{
if ([self respondsToSelector:@selector(backingScaleFactor)]) {
- CGFloat scale = [self performSelector:@selector(backingScaleFactor)];
+ CGFloat scale = [self backingScaleFactor];
return (scale == 2.0f);
}
View
@@ -52,6 +52,11 @@ - (id)init
{
if ((self = [super init])) {
self.clients = [NSMutableArray new];
+
+ self.frontmostViewMessageQueue = dispatch_queue_create("frontmostViewMessageQueue", NULL);
+ self.backgroundViewMessageQueue = dispatch_queue_create("backgroundViewMessageQueue", NULL);
+
+ [self runMessageQueueLoop];
}
return self;
@@ -60,6 +65,12 @@ - (id)init
- (void)dealloc
{
[NSBundle deallocBundlesFromMemory:self];
+
+ dispatch_release(self.frontmostViewMessageQueue);
+ self.frontmostViewMessageQueue = nil;
+
+ dispatch_release(self.backgroundViewMessageQueue);
+ self.backgroundViewMessageQueue = nil;
}
- (void)setup:(IRCWorldConfig *)seed
@@ -75,8 +86,6 @@ - (void)setup:(IRCWorldConfig *)seed
}
[self.config.clients removeAllObjects];
-
- [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(monitorView:) userInfo:nil repeats:YES];
}
- (void)setupTree
@@ -145,6 +154,71 @@ - (void)setChannelMenuItem:(NSMenuItem *)item
}
#pragma mark -
+#pragma mark View Run Loop
+
+- (void)runMessageQueueLoop
+{
+ /* Loop active view. */
+ dispatch_async(self.frontmostViewMessageQueue, ^{
+ while (1 == 1) {
+ IRCTreeItem *active = self.selected;
+
+ if (PointerIsNotEmpty(active)) {
+ if (active.log.queueInProgress == NO) {
+ [active.log runMessageQueueLoop];
+ }
+ }
+ }
+ });
+
+ /* Loop background views. */
+ dispatch_async(self.backgroundViewMessageQueue, ^{
+ while (1 == 1) {
+ IRCTreeItem *active = self.selected;
+
+ if (PointerIsNotEmpty(active)) {
+ NSMutableArray *viewArray = [NSMutableArray array];
+
+ for (IRCClient *c in self.clients) {
+ [viewArray addPointer:(__bridge void *)(c.log)];
+
+ for (IRCChannel *u in c.channels) {
+ [viewArray addPointer:(__bridge void *)(u.log)];
+ }
+ }
+
+ NSArray *sortedViews = [viewArray sortedArrayUsingComparator:^NSComparisonResult(NSValue *a, NSValue *b) {
+ TVCLogController *la = [a pointerValue];
+ TVCLogController *lb = [a pointerValue];
+
+ return (la.messageQueue.count < lb.messageQueue.count);
+ }];
+
+ for (NSValue *pntr in sortedViews) {
+ TVCLogController *log = [pntr pointerValue];
+
+ if (NSDissimilarObjects(log, active.log)) {
+ if (log.queueInProgress == NO) {
+ if (log.messageQueue.count >= 25) {
+ static dispatch_once_t once;
+
+ /* Not 100% sure dispatch_once is
+ designed to do something like this. */
+ dispatch_once(&once, ^{
+ [log runMessageQueueLoop];
+ });
+ } else {
+ [log runMessageQueueLoop];
+ }
+ }
+ }
+ }
+ }
+ }
+ });
+}
+
+#pragma mark -
#pragma mark Properties
- (IRCClient *)selectedClient
@@ -174,21 +248,6 @@ - (IRCChannel *)selectedChannelOn:(IRCClient *)c
#pragma mark -
#pragma mark Utilities
-- (void)monitorView:(NSTimer *)timer
-{
- for (IRCClient *u in self.clients) {
- if (u.log.queueInProgress == NO) {
- [u.log destroyViewLoop];
- }
-
- for (IRCChannel *c in u.channels) {
- if (c.log.queueInProgress == NO) {
- [c.log destroyViewLoop];
- }
- }
- }
-}
-
- (void)resetLoadedBundles
{
self.allLoadedBundles = [NSArray new];
@@ -60,9 +60,6 @@ - (id)init
- (void)dealloc
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
-
- self.queueInProgress = NO;
- [self destroyViewLoop];
}
#pragma mark -
@@ -123,59 +120,30 @@ - (void)setUp
self.queueInProgress = NO;
}
-- (void)destroyViewLoop
+- (void)runMessageQueueLoop
{
- if (self.queueInProgress) {
- return;
- }
+ self.queueInProgress = YES;
- if (PointerIsNotEmpty(self.messageQueueDispatch)) {
- dispatch_release(self.messageQueueDispatch);
- self.messageQueueDispatch = NULL;
- }
-}
-
-- (void)createViewLoop
-{
- if (self.queueInProgress) {
- return;
- } else {
- self.queueInProgress = YES;
- }
-
- if (PointerIsEmpty(self.messageQueueDispatch)) {
- NSString *uuid = [NSString stringWithUUID];
-
- self.messageQueueDispatch = dispatch_queue_create([uuid UTF8String], NULL);
- }
-
- dispatch_async(self.messageQueueDispatch, ^{
- [self messageQueueLoop];
- });
-}
-
-- (void)messageQueueLoop
-{
while (NSObjectIsNotEmpty(self.messageQueue)) {
- if (self.channel) {
- [NSThread sleepForTimeInterval:[TPCPreferences viewLoopChannelDelay]];
- } else {
- [NSThread sleepForTimeInterval:[TPCPreferences viewLoopConsoleDelay]];
- }
-
- if ([self.view isLoading] == NO) {
- dispatch_async(dispatch_get_main_queue(), ^{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([self.view isLoading] == NO) {
if (NSObjectIsNotEmpty(self.messageQueue)) {
BOOL srslt = ((TVCLogMessageBlock)(self.messageQueue)[0])();
-
- if (srslt) {
+
+ if (srslt) {
[self.messageQueue removeObjectAtIndex:0];
}
}
- });
+ }
+ });
+
+ if (self.channel) {
+ [NSThread sleepForTimeInterval:[TPCPreferences viewLoopChannelDelay]];
+ } else {
+ [NSThread sleepForTimeInterval:[TPCPreferences viewLoopConsoleDelay]];
}
}
-
+
self.queueInProgress = NO;
}
@@ -278,8 +246,6 @@ - (void)setTopic:(NSString *)topic
} copy];
[self.messageQueue safeAddObject:messageBlock];
-
- [self createViewLoop];
}
- (void)moveToTop
@@ -382,8 +348,6 @@ - (void)mark
} copy];
[self.messageQueue safeAddObject:messageBlock];
-
- [self createViewLoop];
}
- (void)unmark
@@ -408,8 +372,6 @@ - (void)unmark
} copy];
[self.messageQueue safeAddObject:messageBlock];
-
- [self createViewLoop];
}
- (void)goToMark
@@ -910,8 +872,6 @@ - (void)writeLine:(id)line attributes:(NSMutableDictionary *)attrs
} copy];
[self.messageQueue safeAddObject:messageBlock];
-
- [self createViewLoop];
}
- (NSString *)initialDocument:(NSString *)topic
@@ -73,8 +73,7 @@
4C46CCCB1580469E00846B64 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C46CCC21580469E00846B64 /* WebKit.framework */; };
4C52379415C18F6700414852 /* Style Default Templates in Resources */ = {isa = PBXBuildFile; fileRef = 4C52379215C18F6700414852 /* Style Default Templates */; };
4C52379515C18F6700414852 /* Styles in Resources */ = {isa = PBXBuildFile; fileRef = 4C52379315C18F6700414852 /* Styles */; };
- 4C5A6DBF15C39B1900143574 /* NSScreenHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5A6DBE15C39B1900143574 /* NSScreenHelper.h */; };
- 4C5A6DC115C39BD600143574 /* NSScreenHelper.m in Headers */ = {isa = PBXBuildFile; fileRef = 4C5A6DC015C39BD600143574 /* NSScreenHelper.m */; };
+ 4C5A6DBF15C39B1900143574 /* NSScreenHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C5A6DBE15C39B1900143574 /* NSScreenHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
4C63C6B61592F0B0009F1635 /* TPWTB_Alerts.tif in Resources */ = {isa = PBXBuildFile; fileRef = 4C63C6B01592F0B0009F1635 /* TPWTB_Alerts.tif */; };
4C63C6B71592F0B0009F1635 /* TPWTB_Alerts@2x.tif in Resources */ = {isa = PBXBuildFile; fileRef = 4C63C6B11592F0B0009F1635 /* TPWTB_Alerts@2x.tif */; };
4C63C6BC1592F360009F1635 /* TPWTB_Extensions.tif in Resources */ = {isa = PBXBuildFile; fileRef = 4C63C6BA1592F360009F1635 /* TPWTB_Extensions.tif */; };
@@ -384,6 +383,7 @@
4CCF2F291580481E006FFE21 /* FormattingColor_15.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CCF2F181580481E006FFE21 /* FormattingColor_15.png */; };
4CCF2F9915804BC9006FFE21 /* core.js in Copy JavaScript Files */ = {isa = PBXBuildFile; fileRef = 4CCF2F5315804888006FFE21 /* core.js */; };
4CCF2F9D15804BF8006FFE21 /* Growl.framework in Copy Additional Frameworks */ = {isa = PBXBuildFile; fileRef = 4CCF2EE1158046F9006FFE21 /* Growl.framework */; };
+ 4CD63F3015C59C5B00E8DE92 /* NSScreenHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5A6DC015C39BD600143574 /* NSScreenHelper.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -1731,6 +1731,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4C5A6DBF15C39B1900143574 /* NSScreenHelper.h in Headers */,
4C3D0B7C159490C800567623 /* TPCPreferencesMigrationAssistant.h in Headers */,
4C6ED7F315901579001AD200 /* TVCMainWindowSegmentedControl.h in Headers */,
4C8AF74B158EB6CA0026668C /* AGKeychain.h in Headers */,
@@ -1854,8 +1855,6 @@
4C211D5315BF1FCE00E218DA /* GRMustacheTemplateDelegate.h in Headers */,
4C211D5415BF1FCE00E218DA /* GRMustacheTemplateRepository.h in Headers */,
4C211D5515BF1FCE00E218DA /* GRMustacheVersion.h in Headers */,
- 4C5A6DBF15C39B1900143574 /* NSScreenHelper.h in Headers */,
- 4C5A6DC115C39BD600143574 /* NSScreenHelper.m in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2111,6 +2110,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4CD63F3015C59C5B00E8DE92 /* NSScreenHelper.m in Sources */,
4C8AF609158E99520026668C /* TXGlobalModels.m in Sources */,
4C8AF60A158E99520026668C /* TXMasterController.m in Sources */,
4C8AF60B158E99520026668C /* TXMenuController.m in Sources */,
View
@@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
- <string>12131</string>
+ <string>12148</string>
<key>TXBundleBuildReference</key>
- <string>2.1.1-265-g29feb95-appstore</string>
+ <string>2.1.1-266-g6def6c7-appstore</string>
</dict>
</plist>
Oops, something went wrong.

0 comments on commit 9ee90ee

Please sign in to comment.