Skip to content

Commit 0a00172

Browse files
committed
Use global queue in order to catch read event from channel
1 parent 25bc16e commit 0a00172

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/MacVim/gui_macvim.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,16 +2257,26 @@ static int vimModMaskToEventModifierFlags(int mods)
22572257

22582258
// -- Channel Support ------------------------------------------------------
22592259

2260+
static NSMutableSet *MMChannels;
2261+
22602262
void *
22612263
gui_macvim_add_channel(channel_T *channel, int part)
22622264
{
2265+
if (!MMChannels)
2266+
MMChannels = [NSMutableSet new];
2267+
2268+
int fd = channel->ch_part[part].ch_fd;
2269+
dispatch_queue_t q =
2270+
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
22632271
dispatch_source_t s =
2264-
dispatch_source_create(DISPATCH_SOURCE_TYPE_READ,
2265-
channel->ch_part[part].ch_fd,
2266-
0,
2267-
dispatch_get_main_queue());
2272+
dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, q);
2273+
[MMChannels addObject:s];
22682274
dispatch_source_set_event_handler(s, ^{
2269-
channel_read(channel, part, "gui_macvim_add_channel");
2275+
dispatch_sync(dispatch_get_main_queue(), ^{
2276+
if ([MMChannels containsObject:s]) {
2277+
channel_read(channel, part, "gui_macvim_add_channel");
2278+
}
2279+
});
22702280
});
22712281
dispatch_resume(s);
22722282
return s;
@@ -2276,6 +2286,7 @@ static int vimModMaskToEventModifierFlags(int mods)
22762286
gui_macvim_remove_channel(void *cookie)
22772287
{
22782288
dispatch_source_t s = (dispatch_source_t)cookie;
2289+
[MMChannels removeObject:s];
22792290
dispatch_source_cancel(s);
22802291
dispatch_release(s);
22812292
}

src/channel.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,9 @@ channel_gui_register_one(channel_T *channel, int part)
599599
# endif
600600
# else
601601
# ifdef FEAT_GUI_MACVIM
602-
/* Tell Core Foundation we are interested in being called when there
603-
* is input on the editor connection socket. */
604602
if (channel->ch_part[part].ch_inputHandler == 0)
605-
channel->ch_part[part].ch_inputHandler = gui_macvim_add_channel(
606-
channel, part);
603+
channel->ch_part[part].ch_inputHandler =
604+
gui_macvim_add_channel(channel, part);
607605
# endif
608606
# endif
609607
# endif

0 commit comments

Comments
 (0)