[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] "Triggering" writes in an event loop from separate threads
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] "Triggering" writes in an event loop from separate threads
- From: Jan Danielsson <jan.m.danielsson@xxxxxxxxx>
- Date: Fri, 09 Aug 2013 01:15:07 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Thu, 08 Aug 2013 19:15:16 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=wIrOh8gHILNNC48pgpzAPe0ad7riSrAI/ty5HI0EHsg=; b=x1y5DyM9nMeHjJEPh1VAHSvMlUSU9PEPKthZAVLWSlFG9l1y0/Vu+X4qUIuixc7fQJ YaaQM6iwH7QtsRI9yNJP7JOfMsdrUaTmhS65HjZnnqMGradU6HQhE0JYgkUyQiHK6eMb 1sXWCxXnoNyX4EzBSkmdiD8g8sejCTIjVVmlDGD3SwnSrxUQB6ulTzolTrPUirKUDj/A ADiXprMT3yJHiXaoXsR2LxL0rwMOQbcOSRQr3b+TNDTdElExvzrhsz3+ILGl/71Ow3RY zJKR+sHycZ1mWkO67M/xkCdIQIHQcdnWH/qk8RY+XZGQnvCUSty40fpw9k1AUGZZscno JMMg==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
- User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
Hello,
I have an eventloop with a bufferevent set up in an application. When
handling read events everything is done on the event loop thread, and
some writes are done as a direct result of data being read there, but
writes are typically placed on a queue by a separate threads. But I want
the writes to be handled on the eventloop thread as well.
i.e. I have a readcb() function which reads incoming frames from the
remote system. Each frame typically leads to some kind of response.
These I can send directly using bufferevent_write() as soon as the
complete frames have been received and parsed. However, the bufferevent
also has a context associated with it which contains a mutex and a
linked list which is shared with the rest of the application. Other
parts of the application can place frames on the outqueue at any time.
Could one set up both a read and write callback, but not enable
EV_WRITE. Then, on the separate threads, lock the outqueue, add frames
to the queue, unlock the queue and finally call bufferevent_enable(bev,
EV_WRITE)? I.e. would enabling EV_WRITE cause the write callback to be
called? ..and once all the frames have been written, the write callback
would call bufferevent_disable(bev, EV_WRITE) again?
.. essentially using the EV_WRITE flag as a condvar, in some
perverted sense. Does switching on EV_WRITE trigger a call to the write
callback? Is it safe to do it from another thread? (Yes, I have enabled
thread support in the library, and am initializing the thread support
properly).
Is there some other way to do it? (For various reasons I don't want
to call bufferevent_write() directly from the threads which generate
output frames).
/Jan
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.