Beispiel #1
0
// Let the interpreter know that this thread has completed the call, and is ready to finish
// up the external call (clear arguments off the stack of the calling process and push
// on the return value). We have to do this in synchronisation with the main thread since it 
// may involve memory management activities, etc, therefore we signal the Semaphore
// on which the process is waiting, and when the main thread processes this signal it
// will realise that a completion is waiting and send back an appropriate notification
// and then itself wait for the completion to take place on this thread.
void OverlappedCall::NotifyInterpreterOfCallReturn()
{
	m_bCompletionRequestPending = true;
	Process* myProc = GetProcess();
	Interpreter::asynchronousSignal(myProc->OverlapSemaphore());
	//completed = true;
	// We must set this event in case the main thread has quiesced
	Interpreter::SetWakeupEvent();
}
Beispiel #2
0
bool OverlappedCall::Initiate(CompiledMethod* pMethod, unsigned argCount)
{
	HARDASSERT(::GetCurrentThreadId() == Interpreter::MainThreadId());

	#if TRACING == 1
	{
		TRACELOCK();
		TRACESTREAM << std::hex << GetCurrentThreadId() << L": Initiate; " << *this << std::endl;
	}
	#endif

	// Note that the callDepth member examined by IsInCall() method is only  accessed 
	// from the main thread, or when the main thread is blocked waiting for call 
	// completion on the worker thread, therefore it needs no synchronisation
	if (IsInCall())
		// Nested overlapped calls are not currently supported
		return false;

	m_nCallDepth++;

	// Now save down contextual information
	m_pMethod = pMethod;
	m_nArgCount = argCount;
	ASSERT(m_oteProcess == Interpreter::actualActiveProcessPointer());
	// Copy context from Interpreter
	// ?? Not sure we'll need all this
	m_interpContext = Interpreter::GetRegisters();

	// As we are about to suspend the process, we must also store down the active frame into
	// the suspended frame, and update the active frame with the current IP/SP.
	m_interpContext.PrepareToSuspendProcess();

	Process* proc = m_oteProcess->m_location;

	// Block the process on its own private Semaphore - this simplifies the completion
	// handling since all that is needed is to async signal the Semaphore from the
	// background thread, and then let the process activation code (in process.cpp)
	// spot that an overlapped call completion is pending. However it does create
	// a ref. count issue since the Semaphore may be the only ref. to the process, and
	// the process is probably the only ref. to the Semaphore.
	Interpreter::QueueProcessOn(m_oteProcess, reinterpret_cast<LinkedListOTE*>(proc->OverlapSemaphore()));

	// OK to start the async. operation now
	// We don't use Suspend/Resume because if thread is not suspended yet 
	// (i.e. it hasn't reached its SuspendThread() call), then calling Resume() here
	// will do nothing, and the thread will suspend itself for ever!
	::SetEvent(m_hEvtGo);

	TODO("Try a deliberate SwitchToThread here to see effect of call completing before we reschedule")

	// Reschedule as we probably need another process to run
	if (Interpreter::schedule() == m_oteProcess)
		DebugBreak();

	//CHECKREFERENCES
	return true;
}