Event synchronization between worker thread and application thread.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I?m currently integrating PJSUA under a C++ application wrapper. Joy of joy
with pthreads and class members. I?ve basically decided to serialise
everything through one thread ?App? so all UI requests and incoming calls
etc get sent to that App thread context for processing.

What I currently have is an application thread and then of course the worker
thread that PJSIP creates.

When calls come down from the UI layer they can be on a new random thread.
When this happens I want to basically post a message to my application
thread, have that thread wake up, process the request and the post a
response. Basically a mailbox system between the threads. The worker thread
would also post messages to the main application thread upon callbacks (ie:
incoming call) app thread then puts it in a que and notifies the UI layer.

All that aside, looking through the PJSIP documentation and pthreads I?m
looking at wanting to use either some event que or a mutex to block access
to a condition variable (pthreads) which my app thread is blocked on.. Now
PJSIP doesn?t have the condition variables.. But it does have Event object
which looks very similar.

I know how to construct all of this, but in the docs (
http://www.pjsip.org/pjlib/docs/html/group__PJ__EVENT.htm) it says this is
?where available?. Scary. Is this available on all PJSIP supported platforms
or..? 

Here?s how I?d see it working (number showing process switching)

UI Thread (requesting a new outbound call):
1. Take ?mailbox? mutex
2.  Update variables such as what API I?d like to call in context of App
thread
3. Send event (?posted?)

 [Process switch to App thread below]

9. Wait event (?finished?)
10. Get result variable do whatever
11. Free mailbox mutex

App Thread:
- Waiting on event ?posted?
4. Wakes up
5. Read variables (Mutex still held by UI thread but I?m read only) (can
mark them volatile if needed)
6. Process the API
7. Update response variable
8. Send event ?finished?

So, my questions,

A. With the event object is this supported across all platforms?
B. Is there a better method to do inter thread communications of events (I/O
Queue in pjsip?) ?

Cheers!

Chris
 






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20110305/08ba5916/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux