What is alternate of ::WaitForSignalObject API of MFC

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Yogesh191
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Feb 26, 2006 4:30 am
Location: India
Contact:

What is alternate of ::WaitForSignalObject API of MFC

Post by Yogesh191 » Fri Aug 13, 2010 10:55 am

hi,

I am porting code from mfc to linux i stuck at point where mfc use code like
::waitForSinalObject(m_pParentSession->ev_InProgress, 1)!=WAIT_OBJECT_))

and

m_pParentSession->ev_InProgress.SetEvent();


My question is that waht is alternate of ::waitForSinalObject
in wxWidgets.

Thanks in advance
Yogesh
Yogesh Chaturvedi
OS : Windows, Linux, Mac

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Aug 13, 2010 12:23 pm

Can you explain what they do? Not everyone here is familiar with MFC
"Keyboard not detected. Press F1 to continue"
-- Windows

Yogesh191
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Feb 26, 2006 4:30 am
Location: India
Contact:

Post by Yogesh191 » Fri Aug 13, 2010 1:13 pm

Hi,

Thanks for your reply:

In mfc Code It define some event variable Like
CEvent m_x, CEvent m_y etc.

Code: Select all

In the Cdoe 
It use like this :
if (::WaitForSingleObject(m_pParentSession->ev_InProgress, 1) != WAIT_OBJECT_0)
	{
		if(!m_pParentSession->in_progress_2 && !m_pParentSession->in_progress && m_pView )
		{
			if ( !TryToSaveFiles() )
				return FALSE;
			// TODO: Add your command handler code here

			CListCtrlText3Ex * pListFrame, * pListMap;
			CScaleDiffMap* pScaleMap; 
			pListFrame = NULL;
			pListMap = NULL;
			pScaleMap = NULL;
.....
}
then use the link lilke

Code: Select all

m_x->SetEvent();
m_y->SetEvent();
to perform some action:

Yogesh

EDIT by Auria : Please use code tags
Yogesh Chaturvedi
OS : Windows, Linux, Mac

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Aug 13, 2010 1:35 pm

I still don't understand :) maybe someone here knows MFC better than me and can help

If you mean custom events, see http://wiki.wxwidgets.org/Inter-Thread_ ... ain_thread (doesn't need to be multi-threaded to work)
"Keyboard not detected. Press F1 to continue"
-- Windows

Debster
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sat Aug 20, 2005 6:01 pm

Post by Debster » Fri Aug 13, 2010 9:52 pm

Hi,
"WaitForSingleObject" is a win function and has nothing todo with mfc. It's used for syncronising threads. Let's suppose you have a thread transfering some (Giga)bytes over an tcp/ip connection and another thread is waiting for this data. So this thread can use WaitFoSingleObject todo nothing in terms of using cpu cycles until the transfer thread is ready and set the signal. Now the Os awake the waiting thread and it can continue it's data procesing. Hope this helps. I don't know if there are similar functins in Unixes.

Debster
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sat Aug 20, 2005 6:01 pm

Post by Debster » Fri Aug 13, 2010 10:02 pm


Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sat Aug 14, 2010 5:12 pm

I'd say either a wxCondition or an event; the event won't freeze so the app will remain responsive during the thread is active, while wxCondition will freeze the main thread until signaled
"Keyboard not detected. Press F1 to continue"
-- Windows

Yogesh191
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Feb 26, 2006 4:30 am
Location: India
Contact:

Post by Yogesh191 » Sun Aug 15, 2010 6:55 am

Thanks Auria, Debster for response:

Actually in mfc Prject they use different threads anf use two API
WaitForSingalObject();
WaitForMultipleObject();

if(::WaitForSingleObject(m_pParentSession->ev_InProgress, 1) != WAIT_OBJECT_0)

It works for Obect of mutex critical section and other syncronization class and need onlt to pass event object i am looking for the similar Function in Unis so donot need to write global function for that purpose, wxCondition is similar class for CEvent but not fulfil my requirement in current condition.
Now i have plan to use wxCondition::WaitTimeOut functiojn for this purpose. But it would be more convienient and not change the coding style if i get similar api in unix.
Thanks for response
Yogesh Chaturvedi
OS : Windows, Linux, Mac

User avatar
doublemax
Moderator
Moderator
Posts: 14954
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Sun Aug 15, 2010 8:17 am

You won't find a single wx code line that replaces your old cold line, you probably have to look at the "bigger picture" and rewrite your code a bit in order to use wxMutex or any of its related classes.
http://docs.wxwidgets.org/stable/wx_wxc ... xcondition
http://docs.wxwidgets.org/stable/wx_wxc ... calsection
http://docs.wxwidgets.org/stable/wx_wxm ... ml#wxmutex
http://docs.wxwidgets.org/stable/wx_wxs ... xsemaphore

And if you're making GUI calls from separate threads (which almost looks that way), you have a bigger problem, because wxWidgets doesn't support that.
Use the source, Luke!

Post Reply