예제 #1
0
bool SendMessageEx(t_ulong tid, Message *pmsg,  void *&pres, t_ulong priority)throw()
{
		assert(pmsg != 0);
		pres = 0;
		if(tid == ThreadSpace::Thread::GetCurrentThreadId())
		{
				delete pmsg;
				assert(0);
				return false;
		}

		MsgCarrier *pmsg_carrier = new MsgCarrier;
		pmsg_carrier->pmsg = pmsg;
		pmsg_carrier->m_msg_event = new SyncMsgEvent();
		pmsg_carrier->Duplicate();
		assert(pmsg_carrier->Count() == 2);
		
		if(!PushMsg(tid, pmsg_carrier, priority))
		{
				pmsg_carrier->Release();
				pmsg_carrier->Release();
				return false;
		}else
		{
				pmsg_carrier->m_msg_event->Wait();
				pres = pmsg_carrier->m_msg_event->GetResult();
				pmsg_carrier->Release();
				return true;
		}
		

}
예제 #2
0
void
Str_PushWarn (MyStream * ms, const char * fmt, ...)
{
    va_list args;
    VA_START (args, fmt);
    PushMsg ("    ", fmt, args, NULL);
    va_end (args);
    PushWarn ("in %s:%d:", Str_GetName(ms), Str_GetLine(ms));
}
예제 #3
0
bool PostMessageEx(t_ulong tid, Message *pmsg, t_ulong priority)
{
		assert(pmsg != 0);
		
		MsgCarrier *pmsg_carrier = new MsgCarrier;
		
		pmsg_carrier->pmsg = pmsg;
		pmsg_carrier->m_msg_event = 0;

		bool has_queue = PushMsg(tid, pmsg_carrier, priority);
		if(!has_queue)
		{
				pmsg_carrier->Release();
		}

		return has_queue;
}
예제 #4
0
bool SendMessageTimeoutEx(t_ulong tid, Message *pmsg, t_ulong timeout, void *&pres, t_ulong priority)throw()
{
		pres = 0;
		assert(pmsg != 0);
		
		if(tid == ThreadSpace::Thread::GetCurrentThreadId())
		{
				//pmsg->Delete();
				delete pmsg;
				assert(false);
				return false;
		}
		MsgCarrier *pmsg_carrier = new MsgCarrier;
		pmsg_carrier->pmsg = pmsg;
		pmsg_carrier->m_msg_event = new SyncMsgEvent();
		pmsg_carrier->Duplicate();	//增加一次引用计数,以此也保证了pmsg_carrier->m_msg_event
		assert(pmsg_carrier->Count() == 2);	//不会在处理线程中被delete,因为在~Message()中执行delete

		if(PushMsg(tid, pmsg_carrier, priority))
		{
				if(pmsg_carrier->m_msg_event->Wait(timeout))
				{
						//如果被处理了,则得到返回结果
						pres = pmsg_carrier->m_msg_event->GetResult();
						pmsg_carrier->Release();
						return true;
				}else
				{
						pmsg_carrier->Release();
						return false;
				}
				
		}else
		{
				pmsg_carrier->Release();		
				pmsg_carrier->Release();
				return false;
		}

}