Re: Patch 8.0.0097

2016-11-27 Fir de Conversatie Ken Takata
Hi Bram,

2016/11/26 Sat 23:10:03 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
> 
> > 2016/11/25 Fri 1:23:12 UTC+9 Bram Moolenaar wrote:
> > > Patch 8.0.0097
> > > Problem:When a channel callback consumes a lot of time Vim becomes
> > > unresponsive. (skywind)
> > > Solution:   Bail out of checking channel readahead after 100 msec.
> > > Files:  src/os_unix.c, src/misc2.c, src/vim.h, src/os_win32.c
> > 
> > > + long
> > > + elapsed(DWORD start_tick)
> > > + {
> > > + DWORD   now = GetTickCount();
> > > + 
> > > + if (now < start_tick)
> > > + /* overflow */
> > > + return (long)now;
> > > + return (long)now - (long)start_tick;
> > > + }
> > 
> > I don't think overflow checking is needed here.
> > 
> > return (long)now - (long)start_tick;
> > 
> > should work on Windows even if overflow occurs.
> 
> DWORD is 32 bits unsigned, right?  And long is 32 bits signed.

Right. So the following should work:

long
elapsed(DWORD start_tick)
{
DWORD   now = GetTickCount();

return (long)now - (long)start_tick;
}

Or we can reduce a cast:

return (long)(now - start_tick);


Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 8.0.0097

2016-11-26 Fir de Conversatie Bram Moolenaar

Ken Takata wrote:

> 2016/11/25 Fri 1:23:12 UTC+9 Bram Moolenaar wrote:
> > Patch 8.0.0097
> > Problem:When a channel callback consumes a lot of time Vim becomes
> > unresponsive. (skywind)
> > Solution:   Bail out of checking channel readahead after 100 msec.
> > Files:  src/os_unix.c, src/misc2.c, src/vim.h, src/os_win32.c
> 
> > + long
> > + elapsed(DWORD start_tick)
> > + {
> > + DWORD now = GetTickCount();
> > + 
> > + if (now < start_tick)
> > +   /* overflow */
> > +   return (long)now;
> > + return (long)now - (long)start_tick;
> > + }
> 
> I don't think overflow checking is needed here.
> 
> return (long)now - (long)start_tick;
> 
> should work on Windows even if overflow occurs.

DWORD is 32 bits unsigned, right?  And long is 32 bits signed.
I suppose that works.

-- 
hundred-and-one symptoms of being an internet addict:
49. You never have to deal with busy signals when calling your ISP...because
you never log off.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 8.0.0097

2016-11-24 Fir de Conversatie Ken Takata
Hi Bram,

2016/11/25 Fri 1:23:12 UTC+9 Bram Moolenaar wrote:
> Patch 8.0.0097
> Problem:When a channel callback consumes a lot of time Vim becomes
> unresponsive. (skywind)
> Solution:   Bail out of checking channel readahead after 100 msec.
> Files:  src/os_unix.c, src/misc2.c, src/vim.h, src/os_win32.c

> + long
> + elapsed(DWORD start_tick)
> + {
> + DWORD   now = GetTickCount();
> + 
> + if (now < start_tick)
> + /* overflow */
> + return (long)now;
> + return (long)now - (long)start_tick;
> + }

I don't think overflow checking is needed here.

return (long)now - (long)start_tick;

should work on Windows even if overflow occurs.

Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Patch 8.0.0097

2016-11-24 Fir de Conversatie Bram Moolenaar

Patch 8.0.0097
Problem:When a channel callback consumes a lot of time Vim becomes
unresponsive. (skywind)
Solution:   Bail out of checking channel readahead after 100 msec.
Files:  src/os_unix.c, src/misc2.c, src/vim.h, src/os_win32.c


*** ../vim-8.0.0096/src/os_unix.c   2016-11-17 17:25:28.212093109 +0100
--- src/os_unix.c   2016-11-24 17:10:57.847711807 +0100
***
*** 376,396 
RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL);
  }
  
- #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
- /*
-  * Return time in msec since "start_tv".
-  */
- static long
- elapsed(struct timeval *start_tv)
- {
- struct timeval  now_tv;
- 
- gettimeofday(_tv, NULL);
- return (now_tv.tv_sec - start_tv->tv_sec) * 1000L
-+ (now_tv.tv_usec - start_tv->tv_usec) / 1000L;
- }
- #endif
- 
  /*
   * mch_inchar(): low level input function.
   * Get a characters from the keyboard.
--- 376,381 
***
*** 411,420 
  int   did_start_blocking = FALSE;
  long  wait_time;
  long  elapsed_time = 0;
! #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
! struct timeval  start_tv;
  
! gettimeofday(_tv, NULL);
  #endif
  
  /* repeat until we got a character or waited long enough */
--- 396,405 
  int   did_start_blocking = FALSE;
  long  wait_time;
  long  elapsed_time = 0;
! #ifdef ELAPSED_FUNC
! ELAPSED_TYPE start_tv;
  
! ELAPSED_INIT(start_tv);
  #endif
  
  /* repeat until we got a character or waited long enough */
***
*** 438,445 
else
/* going to block after p_ut */
wait_time = p_ut;
! #if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
!   elapsed_time = elapsed(_tv);
  #endif
wait_time -= elapsed_time;
if (wait_time < 0)
--- 423,430 
else
/* going to block after p_ut */
wait_time = p_ut;
! #ifdef ELAPSED_FUNC
!   elapsed_time = ELAPSED_FUNC(start_tv);
  #endif
wait_time -= elapsed_time;
if (wait_time < 0)
***
*** 1554,1571 
  
  #ifdef FEAT_X11
  
! # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) \
&& (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE))
  
- static void xopen_message(struct timeval *start_tv);
- 
  /*
   * Give a message about the elapsed time for opening the X window.
   */
  static void
! xopen_message(struct timeval *start_tv)
  {
! smsg((char_u *)_("Opening the X display took %ld msec"), 
elapsed(start_tv));
  }
  # endif
  #endif
--- 1539,1554 
  
  #ifdef FEAT_X11
  
! # if defined(ELAPSED_TIMEVAL) \
&& (defined(FEAT_XCLIPBOARD) || defined(FEAT_TITLE))
  
  /*
   * Give a message about the elapsed time for opening the X window.
   */
  static void
! xopen_message(long elapsed_msec)
  {
! smsg((char_u *)_("Opening the X display took %ld msec"), elapsed_msec);
  }
  # endif
  #endif
***
*** 1864,1874 
  #endif
if (x11_display != NULL)
{
! # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
if (p_verbose > 0)
{
verbose_enter();
!   xopen_message(_tv);
verbose_leave();
}
  # endif
--- 1847,1857 
  #endif
if (x11_display != NULL)
{
! # ifdef ELAPSED_FUNC
if (p_verbose > 0)
{
verbose_enter();
!   xopen_message(ELAPSED_FUNC(start_tv));
verbose_leave();
}
  # endif
***
*** 4630,4637 
ga_init2(, 1, BUFLEN);
  
noread_cnt = 0;
! # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
!   gettimeofday(_tv, NULL);
  # endif
for (;;)
{
--- 4613,4620 
ga_init2(, 1, BUFLEN);
  
noread_cnt = 0;
! # ifdef ELAPSED_FUNC
!   ELAPSED_INIT(start_tv);
  # endif
for (;;)
{
***
*** 4666,4673 
  /* Get extra characters when we don't have any.
   * Reset the counter and timer. */
  noread_cnt = 0;
! # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
! gettimeofday(_tv, NULL);
  # endif
  len = ui_inchar(ta_buf, BUFLEN, 10L, 0);
  }
--- 4649,4656 
  /* Get extra characters when we don't have any.
   * Reset the counter and timer. */
  noread_cnt = 0;
! # ifdef ELAPSED_FUNC
! ELAPSED_INIT(start_tv);
  # endif