Article View: borland.public.cppbuilder.nativeapi
Article #345Re: Moving hooke callback to thread - suggestions? (was:Hooks, once again)
From: Bob Gonder
Date: Wed, 07 May 2008 14:11
Date: Wed, 07 May 2008 14:11
36 lines
2313 bytes
2313 bytes
Anders Johansen wrote:
>The code below has a potential flaw: The callback code is
>running in the main thread, and so may block the system event
>processing or at least delay it.
The only slow part in the hooks I can see is notifyKeyDown,
and it's reliance on virtual KeyDown functions.
Everything else should be quite fast enough.
Two thoughts on notifyKeyDown:
1) You use "set" with pointers, apparently ordered by address.
I would think "vector" would be more appropriate.
2) You could place notifyKeyDown in a thread and have
the hooks place data in a FIFO for the thread to consume.
void notifyKeyDown(const UINT vkey, const bool altDown)
{ ThreadStruct.vkey = vkey;
ThreadStruct.altDown = alt.Down;
Fifo.Push( ThreadStruct );
Thread.Resume();
}
>>void HookMaster::notifyKeyDown(const UINT vkey, const bool altDown) {
>> for (std::set<HookObserver*>::iterator i = observers.begin(); i != observers.end(); ++i) {
>> try {
>> HookObserver *obs = *i;
>> obs->keyDown(vkey, altDown, keyDownNumber);
>> } catch (...) {
>> // Something bad happened with the observer
>> }
>> }
>> ++keyDownNumber;
>>}
Technical Details
Message-ID:
<24c3249pbvhtdcpjihmskrvr9pisljt7g6@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!83.80.28.12.MISMATCH!multikabel.net!newsfeed10.multikabel.net!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.straub-nv.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47c935cb$1@newsgroups.borland.com> <48217905$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4ebd883022a89a5d X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Moving hooke callback to thread - suggestions? (was:Hooks, once again) Date: Wed, 07 May 2008 07:11:10 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <24c3249pbvhtdcpjihmskrvr9pisljt7g6@4ax.com> References: <47c935cb$1@newsgroups.borland.com> <48217905$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.145.6 X-Trace: newsgroups.borland.com 1210169469 67.77.145.6 (7 May 2008 07:11:09 -0700) Lines: 37 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!83.80.28.12.MISMATCH!multikabel.net!newsfeed10.multikabel.net!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.straub-nv.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail