Deprecate inProcessCommandQueue related code

We are guarding against re-entrant calls in the app controller now so
the inProcessCommandQueue related code is now obsolete.
This commit is contained in:
Bjorn Winckler
2009-04-05 19:56:21 +02:00
parent 6961a51e9a
commit 28de969ae3
7 changed files with 18 additions and 109 deletions
+1 -1
View File
@@ -1180,10 +1180,10 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
NSNumber *key = [NSNumber numberWithUnsignedInt:identifier];
NSArray *q = [inputQueues objectForKey:key];
if (q) {
NSLog(@"[%s] Appending queue id=%d", _cmd, identifier);
q = [q arrayByAddingObjectsFromArray:queue];
[inputQueues setObject:q forKey:key];
NSLog(@"[%s] Appending queue id=%d", _cmd, identifier);
#if 0 // More debug logging info
unsigned i, count = [q count];
for (i = 0; i < count; i += 2) {
+2 -11
View File
@@ -502,10 +502,11 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
[self insertVimStateMessage];
@try {
//NSLog(@"[%s] Flushing (count=%d)", _cmd, [outputQueue count]);
[appProxy processInput:outputQueue forIdentifier:identifier];
}
@catch (NSException *e) {
NSLog(@"Exception caught when processing command queue: \"%@\"", e);
NSLog(@"[%s] Exception caught: \"%@\"", _cmd, e);
NSLog(@"outputQueue(len:%d)=%@", [outputQueue count]/2,
outputQueue);
if (![connection isValid]) {
@@ -1105,16 +1106,6 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
[inputQueue addObject:(data ? (id)data : [NSNull null])];
}
- (oneway void)processInputAndData:(in bycopy NSArray *)messages
{
// This is just a convenience method that allows the frontend to delay
// sending messages.
int i, count = [messages count];
for (i = 1; i < count; i+=2)
[self processInput:[[messages objectAtIndex:i-1] intValue]
data:[messages objectAtIndex:i]];
}
- (id)evaluateExpressionCocoa:(in bycopy NSString *)expr
errorString:(out bycopy NSString **)errstr
{
-3
View File
@@ -25,9 +25,6 @@
BOOL isInitialized;
MMWindowController *windowController;
id backendProxy;
BOOL inProcessCommandQueue;
NSMutableArray *sendQueue;
NSMutableArray *receiveQueue;
NSMenu *mainMenu;
NSMutableArray *popupMenuItems;
NSToolbar *toolbar;
+10 -85
View File
@@ -16,7 +16,7 @@
* MMVimController does not deal with visual presentation. Essentially it
* should be able to run with no window present.
*
* Output from the backend is received in processCommandQueue:. Input is sent
* Output from the backend is received in processInputQueue:. Input is sent
* to the backend via sendMessage:data: or addVimInput:. The latter allows
* execution of arbitrary strings in the Vim process, much like the Vim script
* function remote_send() does. The messages that may be passed between
@@ -49,10 +49,6 @@ static NSTimeInterval MMBackendProxyRequestTimeout = 0;
// Timeout used for setDialogReturn:.
static NSTimeInterval MMSetDialogReturnTimeout = 1.0;
// Maximum number of items in the receiveQueue. (It is hard to predict what
// consequences changing this number will have.)
static int MMReceiveQueueCap = 100;
static BOOL isUnsafeMessage(int msgid);
static unsigned identifierCounter = 1;
@@ -67,7 +63,7 @@ static unsigned identifierCounter = 1;
@interface MMVimController (Private)
- (void)doProcessCommandQueue:(NSArray *)queue;
- (void)doProcessInputQueue:(NSArray *)queue;
- (void)handleMessage:(int)msgid data:(NSData *)data;
- (void)savePanelDidEnd:(NSSavePanel *)panel code:(int)code
context:(void *)context;
@@ -115,8 +111,6 @@ static unsigned identifierCounter = 1;
windowController =
[[MMWindowController alloc] initWithVimController:self];
backendProxy = [backend retain];
sendQueue = [NSMutableArray new];
receiveQueue = [NSMutableArray new];
popupMenuItems = [[NSMutableArray alloc] init];
toolbarItemDict = [[NSMutableDictionary alloc] init];
pid = processIdentifier;
@@ -173,8 +167,6 @@ static unsigned identifierCounter = 1;
[serverName release]; serverName = nil;
[backendProxy release]; backendProxy = nil;
[sendQueue release]; sendQueue = nil;
[receiveQueue release]; receiveQueue = nil;
[toolbarItemDict release]; toolbarItemDict = nil;
[toolbar release]; toolbar = nil;
@@ -331,21 +323,11 @@ static unsigned identifierCounter = 1;
- (void)sendMessage:(int)msgid data:(NSData *)data
{
//NSLog(@"sendMessage:%s (isInitialized=%d inProcessCommandQueue=%d)",
// MessageStrings[msgid], isInitialized, inProcessCommandQueue);
//NSLog(@"sendMessage:%s (isInitialized=%d)",
// MessageStrings[msgid], isInitialized);
if (!isInitialized) return;
if (inProcessCommandQueue) {
//NSLog(@"In process command queue; delaying message send.");
[sendQueue addObject:[NSNumber numberWithInt:msgid]];
if (data)
[sendQueue addObject:data];
else
[sendQueue addObject:[NSNull null]];
return;
}
@try {
[backendProxy processInput:msgid data:data];
}
@@ -363,7 +345,7 @@ static unsigned identifierCounter = 1;
// ball forever. In almost all circumstances sendMessage:data: should be
// used instead.
if (!isInitialized || inProcessCommandQueue)
if (!isInitialized)
return NO;
if (timeout < 0) timeout = 0;
@@ -448,65 +430,8 @@ static unsigned identifierCounter = 1;
{
if (!isInitialized) return;
if (inProcessCommandQueue) {
// NOTE! If a synchronous DO call is made during
// doProcessCommandQueue: below it may happen that this method is
// called a second time while the synchronous message is waiting for a
// reply (could also happen if doProcessCommandQueue: enters a modal
// loop, see comment below). Since this method cannot be considered
// reentrant, we queue the input and return immediately.
//
// If doProcessCommandQueue: enters a modal loop (happens e.g. on
// ShowPopupMenuMsgID) then the receiveQueue could grow to become
// arbitrarily large because DO calls still get processed. To avoid
// this we set a cap on the size of the queue and simply clear it if it
// becomes too large. (That is messages will be dropped and hence Vim
// and MacVim will at least temporarily be out of sync.)
if ([receiveQueue count] >= MMReceiveQueueCap)
[receiveQueue removeAllObjects];
[receiveQueue addObject:queue];
return;
}
inProcessCommandQueue = YES;
[self doProcessCommandQueue:queue];
int i;
for (i = 0; i < [receiveQueue count]; ++i) {
// Note that doProcessCommandQueue: may cause the receiveQueue to grow
// or get cleared (due to cap being hit). Make sure to retain the item
// to process or it may get released from under us.
NSArray *q = [[receiveQueue objectAtIndex:i] retain];
[self doProcessCommandQueue:q];
[q release];
}
// We assume that the remaining calls make no synchronous DO calls. If
// that did happen anyway, the command queue could get processed out of
// order.
// See comment below why this is called here and not later.
[windowController processCommandQueueDidFinish];
// NOTE: Ensure that no calls are made after this "if" clause that may call
// sendMessage::. If this happens anyway, such messages will be put on the
// send queue and then the queue will not be flushed until the next time
// this method is called.
if ([sendQueue count] > 0) {
@try {
[backendProxy processInputAndData:sendQueue];
}
@catch (NSException *e) {
// Connection timed out, just ignore this.
//NSLog(@"WARNING! Connection timed out in %s", _cmd);
}
[sendQueue removeAllObjects];
}
[receiveQueue removeAllObjects];
inProcessCommandQueue = NO;
[self doProcessInputQueue:queue];
[windowController processInputQueueDidFinish];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)theToolbar
@@ -537,7 +462,7 @@ static unsigned identifierCounter = 1;
@implementation MMVimController (Private)
- (void)doProcessCommandQueue:(NSArray *)queue
- (void)doProcessInputQueue:(NSArray *)queue
{
NSMutableArray *delayQueue = nil;
@@ -593,7 +518,7 @@ static unsigned identifierCounter = 1;
if (delayQueue) {
//NSLog(@" Flushing delay queue (%d items)", [delayQueue count]/2);
[self performSelectorOnMainThread:@selector(processCommandQueue:)
[self performSelectorOnMainThread:@selector(processInputQueue:)
withObject:delayQueue
waitUntilDone:NO
modes:[NSArray arrayWithObject:
@@ -793,7 +718,7 @@ static unsigned identifierCounter = 1;
NSDictionary *attrs = [NSDictionary dictionaryWithData:data];
// The popup menu enters a modal loop so delay this call so that we
// don't block inside processCommandQueue:.
// don't block inside processInputQueue:.
[self performSelectorOnMainThread:@selector(popupMenuWithAttributes:)
withObject:attrs
waitUntilDone:NO
+1 -1
View File
@@ -55,7 +55,7 @@
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore;
- (void)setFont:(NSFont *)font;
- (void)setWideFont:(NSFont *)font;
- (void)processCommandQueueDidFinish;
- (void)processInputQueueDidFinish;
- (void)showTabBar:(BOOL)on;
- (void)showToolbar:(BOOL)on size:(int)size mode:(int)mode;
- (void)setMouseShape:(int)shape;
+4 -7
View File
@@ -308,7 +308,7 @@
// NOTE: The only place where the (rows,columns) of the vim view are
// modified is here and when entering/leaving full-screen. Setting these
// values have no immediate effect, the actual resizing of the view is done
// in processCommandQueueDidFinish.
// in processInputQueueDidFinish.
//
// The 'live' flag indicates that this resize originated from a live
// resize; it may very well happen that the view is no longer in live
@@ -419,11 +419,8 @@
[[vimView textView] setWideFont:font];
}
- (void)processCommandQueueDidFinish
- (void)processInputQueueDidFinish
{
// IMPORTANT! No synchronous DO calls are allowed in this method. They
// may cause the command queue to get processed out of order.
// NOTE: Resizing is delayed until after all commands have been processed
// since it often happens that more than one command will cause a resize.
// If we were to immediately resize then the vim view size would jitter
@@ -495,8 +492,8 @@
// NOTE: If the window is not visible we must toggle the toolbar
// immediately, otherwise "set go-=T" in .gvimrc will lead to the toolbar
// showing its hide animation every time a new window is opened. (See
// processCommandQueueDidFinish for the reason why we need to delay
// toggling the toolbar when the window is visible.)
// processInputQueueDidFinish for the reason why we need to delay toggling
// the toolbar when the window is visible.)
if (![decoratedWindow isVisible])
[self updateToolbar];
}
-1
View File
@@ -33,7 +33,6 @@
//
@protocol MMBackendProtocol
- (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data;
- (oneway void)processInputAndData:(in bycopy NSArray *)messages;
- (oneway void)setDialogReturn:(in bycopy id)obj;
- (NSString *)evaluateExpression:(in bycopy NSString *)expr;
- (id)evaluateExpressionCocoa:(in bycopy NSString *)expr