[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vim-dev
Subject:    RE: Using threading to remove blocking
From:       Vince Negri <vnegri () asl-electronics ! co ! uk>
Date:       2002-11-14 13:11:12
[Download RAW message or body]

To explain further, let's look at some
actual code - the all-important 
gui_wait_for_chars(). Since all places in the
code which wait for keys will ultimately get
here (in a GUI component version) it's where
the threading concept should be encapsulated.

For simplicity I'm leaving out the autocmd code.
For the mch_stuff, I'll refer to Win32 since
that's what I'm familiar with.

Note that despite its name, gui_wait_for_chars
would be called in the context of the worker
thread, not the GUI thread.

    int
gui_wait_for_chars(wtime)
    long    wtime;
{
    int     retval;

    /*
     * If we're going to wait a bit, update the menus and mouse shape for
the
     * current State.
     */
    if (wtime != 0)
    {
#ifdef FEAT_MENU
        gui_update_menus(0);
		/* THREADING: This will probably need to be synchronised
		with the GUI thread */
#endif
    }

    /* THREADING: gui_mch_update is not required here because
    keys are being pumped to us by the GUI thread. */
    with the GUI thread */
    /* gui_mch_update(); */

    if (!vim_is_input_buf_empty())      /* Got char, return immediately */
    {
        return OK;
    }
    if (wtime == 0)     /* Don't wait for char */
    {
        return FAIL;
    }

    /* Before waiting, flush any output to the screen. */
    gui_mch_flush();
    /* THREADING: gui_mch_flush  maps to a simple GDI call in 
    Win32. Thus would be a Synchronise() call.*/

    if (wtime > 0)
    {
        /* Blink when waiting for a character.  Probably only does something
         * for showmatch() */
        gui_mch_start_blink();
        /* THREADING: The blinking just handles a timer.*/

        retval = gui_mch_wait_for_chars(wtime);
		 /* THREADING: This is where we sleep waiting for an event
        posted to us by the GUI thread saying "I've put a key
        in your queue. In this case, we wait with a timeout.*/

        gui_mch_stop_blink();
        return retval;
    }

    /*
     * While we are waiting indefenitely for a character, blink the cursor.
     */
    gui_mch_start_blink();


    if (gui_mch_wait_for_chars(p_ut) != OK)
		 /* THREADING: Again we sleep waiting for an event
        posted to us by the GUI thread saying "I've put a key
        in your queue." The timeout here is p_ut*/
    {
        {
            updatescript(0);
            retval = gui_mch_wait_for_chars(-1L);
		     /* THREADING:Finally this is where we wait forever
            for our message from the GUI thread.*/
        }
    }
    else
        retval = OK;

    gui_mch_stop_blink();
    return retval;
}

You can see that the main bit of work in this area is creating
a new gui_mch_wait_for_chars() routine. In Win32, it would
be little more than a call to WaitForSingleObjectEx().

Vince



Legal Disclaimer: Any views expressed by the sender of this message are
not necessarily those of Application Solutions Ltd. Information in this 
e-mail may be confidential and is for the use of the intended recipient
only, no mistake in transmission is intended to waive or compromise such 
privilege. Please advise the sender if you receive this e-mail by mistake.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic