本文整理汇总了C++中ResetEvent函数的典型用法代码示例。如果您正苦于以下问题:C++ ResetEvent函数的具体用法?C++ ResetEvent怎么用?C++ ResetEvent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ResetEvent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResetEvent
void CBounsDBManager::RestManagerEvent()
{
ResetEvent(m_hManagerEvent);
}
示例2: main
//.........这里部分代码省略.........
/* reset the buffer used by WSARecv */
memset(myBuffer, 0, 255);
/* Prepare to receive data */
err = WSARecv( testSockets[1],
&wsaBuf,
dwNbrOfBuf,
&dwNbrOfByteSent,
&dwRecvFlags,
&wsaRecvOverlapped,
0 );
if( err != SOCKET_ERROR )
{
if(dwNbrOfByteSent==0)
{
Trace("Server error: WSARecv() "
"returned 0 bytes\n");
WaitForClientThreadToFinish(hThreadClient);
CloseThreadHandle(hThreadClient);
CloseEventHandle(hReadEvent);
/* Do some cleanup */
DoWSATestCleanup( testSockets,
numSockets );
Fail("");
}
/* Reset Event */
ResetEvent(hReadEvent);
}
else
{
err = GetLastError();
/* Only WSA_IO_PENDING is expected */
if(err!=WSA_IO_PENDING)
{
Trace("Server error: WSARecv() "
"returned %u, expected WSA_IO_PENDING\n",
GetLastError() );
WaitForClientThreadToFinish(hThreadClient);
CloseThreadHandle(hThreadClient);
CloseEventHandle(hReadEvent);
/* Do some cleanup */
DoWSATestCleanup( testSockets,
numSockets );
Fail("");
}
/* Wait 10 seconds for ReadEvent to be signaled
from the pending operation
*/
waitResult = WaitForSingleObject( hReadEvent,
10000 );
if (waitResult!=WAIT_OBJECT_0)
{
Trace("Server error: Unexpected failure: "
示例3: qemu_event_reset
void qemu_event_reset(QemuEvent *ev)
{
ResetEvent(ev->event);
}
示例4: MyAssertProc
int MyAssertProc(const wchar_t* pszFile, int nLine, const wchar_t* pszTest, bool abNoPipe)
{
HooksUnlocker;
#ifdef _DEBUG
if (MyAssertSkip(pszFile, nLine, pszTest, abNoPipe))
return 1;
#endif
MyAssertDumpToFile(pszFile, nLine, pszTest);
HANDLE hHeap = GetProcessHeap();
MyAssertInfo* pa = (MyAssertInfo*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(MyAssertInfo));
if (!pa)
return -1;
wchar_t *szExeName = (wchar_t*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, (MAX_PATH+1)*sizeof(wchar_t));
if (szExeName && !GetModuleFileNameW(NULL, szExeName, MAX_PATH+1)) szExeName[0] = 0;
pa->bNoPipe = abNoPipe;
msprintf(pa->szTitle, countof(pa->szTitle), L"CEAssert PID=%u TID=%u", GetCurrentProcessId(), GetCurrentThreadId());
wchar_t szVer4[2] = WSTRING(MVV_4a);
msprintf(pa->szDebugInfo, countof(pa->szDebugInfo), L"Assertion in %s [%02u%02u%02u%s]\n%s\n\n%s: %i\n\nPress 'Retry' to trap.",
szExeName ? szExeName : L"<HeapAllocFailed>",
MVV_1, MVV_2, MVV_3, szVer4,
pszTest ? pszTest : L"", pszFile, nLine);
DWORD dwCode = 0;
if (gAllowAssertThread == am_Thread)
{
DWORD dwTID;
HANDLE hThread = apiCreateThread(MyAssertThread, pa, &dwTID, "MyAssertThread");
if (hThread == NULL)
{
dwCode = IDRETRY;
goto wrap;
}
WaitForSingleObject(hThread, INFINITE);
GetExitCodeThread(hThread, &dwCode);
CloseHandle(hThread);
goto wrap;
}
#ifdef ASSERT_PIPE_ALLOWED
#ifdef _DEBUG
if (!abNoPipe && (gAllowAssertThread == am_Pipe))
{
HWND hConWnd = GetConEmuHWND(2);
HWND hGuiWnd = ghConEmuWnd;
// -- искать - нельзя. Если мы НЕ в ConEmu - нельзя стучаться в другие копии!!!
//#ifndef CONEMU_MINIMAL
//if (hGuiWnd == NULL)
//{
// hGuiWnd = FindWindowEx(NULL, NULL, VirtualConsoleClassMain, NULL);
//}
//#endif
if (hGuiWnd && gnInMyAssertTrap <= 0)
{
InterlockedIncrement(&gnInMyAssertTrap);
InterlockedIncrement(&gnInMyAssertPipe);
gnInMyAssertThread = GetCurrentThreadId();
ResetEvent(ghInMyAssertTrap);
dwCode = GuiMessageBox(abNoPipe ? NULL : hGuiWnd, pa->szDebugInfo, pa->szTitle, MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_RETRYCANCEL);
InterlockedDecrement(&gnInMyAssertTrap);
InterlockedDecrement(&gnInMyAssertPipe);
SetEvent(ghInMyAssertTrap);
gnInMyAssertThread = 0;
goto wrap;
}
}
while (gnInMyAssertPipe>0 && (gnInMyAssertThread != GetCurrentThreadId()))
{
Sleep(250);
}
#endif
#endif
// В консольных приложениях попытка запустить CreateThread(MyAssertThread) может зависать
dwCode = MyAssertThread(pa);
wrap:
if (pa)
HeapFree(hHeap, 0, pa);
if (szExeName)
HeapFree(hHeap, 0, szExeName);
return (dwCode == IDRETRY) ? -1 : 1;
}
示例5: main
//.........这里部分代码省略.........
memset(myBuffer, 0, 255);
/* Initialize the WSAOVERLAPPED to 0 */
memset(&wsaRecvOverlapped, 0, sizeof(WSAOVERLAPPED));
/* Specify which event to signal when data is arrived*/
wsaRecvOverlapped.hEvent = hReadEvent;
/* Initialize the WSABUF structure */
wsaBuf.buf = myBuffer;
wsaBuf.len = 255;
/* Prepare to receive data */
err = WSARecvFrom( testSockets[0],
&wsaBuf,
dwNbrOfBuf,
&dwNbrOfByteSent,
&dwRecvFlags,
(struct sockaddr FAR *) NULL,
(int) NULL,
&wsaRecvOverlapped,
0 );
if( err != SOCKET_ERROR )
{
if(dwNbrOfByteSent==0)
{
/* Packet dropped, UDP is not reliable
we just stop receiving
*/
break;
}
/* Reset the event */
ResetEvent(hReadEvent);
}
else
{
err = GetLastError();
/* Only WSA_IO_PENDING is expected */
if(err!=WSA_IO_PENDING)
{
Trace("Server error: WSARecv()"
"returned %d, expected WSA_IO_PENDING\n",
err );
WaitForClientThreadToFinish(hThreadClient);
CloseThreadHandle(hThreadClient);
CloseEventHandle(hThreadEvent);
CloseEventHandle(hReadEvent);
/* Do some cleanup */
DoWSATestCleanup( testSockets,
numSockets );
Fail("");
}
}
/* verify if it needs to start the client thread */
if(!bClientStarted)
{
if(SetEvent(hThreadEvent)==0)
{
示例6: while
void AT91_USBHS_Driver::Global_ISR( void* Param )
{
struct AT91_UDPHS *pUdp = (struct AT91_UDPHS *) (AT91C_BASE_UDP);
UINT32 USB_INTR = (pUdp->UDPHS_INTSTA & pUdp->UDPHS_IEN);
UINT32 endpoint = 0;
// debug_printf("%x", USB_INTR);
// Handle all UDP interrupts
while(USB_INTR != 0)
{
// Start Of Frame (SOF)
if(USB_INTR & AT91C_UDPHS_IEN_SOF)
{
// Acknowledge interrupt
pUdp->UDPHS_CLRINT = AT91C_UDPHS_IEN_SOF;
USB_INTR &= ~AT91C_UDPHS_IEN_SOF;
// This interrupt should not happen, as it is not enabled.
ASSERT(0);
}
// Suspend
if (USB_INTR & AT91C_UDPHS_DET_SUSPD)
{
AT91_PMC_DisableUTMIBIAS();
// Acknowledge interrupt
pUdp->UDPHS_CLRINT = AT91C_UDPHS_DET_SUSPD | AT91C_UDPHS_WAKE_UP;
USB_INTR &= ~AT91C_UDPHS_DET_SUSPD;
SuspendEvent();
}
// Resume or Wakeup
if((USB_INTR & AT91C_UDPHS_WAKE_UP) ||(USB_INTR & AT91C_UDPHS_ENDOFRSM))
{
ResumeEvent();
// Acknowledge interrupt
pUdp->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_ENDOFRSM;
USB_INTR &= ~(AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_ENDOFRSM);
}
// End of bus reset
if(USB_INTR & AT91C_UDPHS_ENDRESET)
{
// Acknowledge end of bus reset interrupt
ResetEvent();
pUdp->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_DET_SUSPD | AT91C_UDPHS_ENDRESET;
pUdp->UDPHS_IEN |= AT91C_UDPHS_DET_SUSPD;
USB_INTR &= ~AT91C_UDPHS_ENDRESET;
}
if(USB_INTR & AT91C_UDPHS_UPSTR_RES)
{
pUdp->UDPHS_CLRINT = AT91C_UDPHS_UPSTR_RES;
USB_INTR &= ~AT91C_UDPHS_UPSTR_RES;
}
else //Endpoint Interrupt
{
UINT32 i = 0;
USB_INTR >>= 8;
while(USB_INTR != 0)
{
if (USB_INTR & 1)
{
endpoint = i;
Endpoint_ISR(endpoint);
if (endpoint == 1)
{
// debug_printf("1\r\n");
// num_ep_int1 += 1;
}
if (endpoint == 2)
{
// debug_printf("2\r\n");
// num_ep_int2 += 1;
}
}
USB_INTR >>= 1;
i++;
}
}
USB_INTR = pUdp->UDPHS_INTSTA & pUdp->UDPHS_IEN;
}
}
示例7: ThrowIf
bool CAGuard::WaitFor(UInt64 inNanos)
{
bool theAnswer = false;
#if TARGET_OS_MAC
ThrowIf(!pthread_equal(pthread_self(), mOwner), CAException(1), "CAGuard::WaitFor: A thread has to have locked a guard be for it can wait");
#if Log_TimedWaits
DebugMessageN1("CAGuard::WaitFor: waiting %.0f", (Float64)inNanos);
#endif
struct timespec theTimeSpec;
static const UInt64 kNanosPerSecond = 1000000000ULL;
if(inNanos >= kNanosPerSecond)
{
theTimeSpec.tv_sec = static_cast<UInt32>(inNanos / kNanosPerSecond);
theTimeSpec.tv_nsec = static_cast<UInt32>(inNanos % kNanosPerSecond);
}
else
{
theTimeSpec.tv_sec = 0;
theTimeSpec.tv_nsec = static_cast<UInt32>(inNanos);
}
#if Log_TimedWaits || Log_Latency || Log_Average_Latency
UInt64 theStartNanos = CAHostTimeBase::GetCurrentTimeInNanos();
#endif
mOwner = 0;
#if Log_WaitOwnership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAGuard::WaitFor: thread %p is waiting on %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), pthread_self(), mName, mOwner);
#endif
OSStatus theError = pthread_cond_timedwait_relative_np(&mCondVar, &mMutex, &theTimeSpec);
ThrowIf((theError != 0) && (theError != ETIMEDOUT), CAException(theError), "CAGuard::WaitFor: Wait got an error");
mOwner = pthread_self();
#if Log_TimedWaits || Log_Latency || Log_Average_Latency
UInt64 theEndNanos = CAHostTimeBase::GetCurrentTimeInNanos();
#endif
#if Log_TimedWaits
DebugMessageN1("CAGuard::WaitFor: waited %.0f", (Float64)(theEndNanos - theStartNanos));
#endif
#if Log_Latency
DebugMessageN1("CAGuard::WaitFor: latency %.0f", (Float64)((theEndNanos - theStartNanos) - inNanos));
#endif
#if Log_Average_Latency
++mAverageLatencyCount;
mAverageLatencyAccumulator += (theEndNanos - theStartNanos) - inNanos;
if(mAverageLatencyCount >= 50)
{
DebugMessageN2("CAGuard::WaitFor: average latency %.3f ns over %ld waits", mAverageLatencyAccumulator / mAverageLatencyCount, mAverageLatencyCount);
mAverageLatencyCount = 0;
mAverageLatencyAccumulator = 0.0;
}
#endif
#if Log_WaitOwnership
DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAGuard::WaitFor: thread %p waited on %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), pthread_self(), mName, mOwner);
#endif
theAnswer = theError == ETIMEDOUT;
#elif TARGET_OS_WIN32
ThrowIf(GetCurrentThreadId() != mOwner, CAException(1), "CAGuard::WaitFor: A thread has to have locked a guard be for it can wait");
#if Log_TimedWaits
DebugMessageN1("CAGuard::WaitFor: waiting %.0f", (Float64)inNanos);
#endif
// the time out is specified in milliseconds(!)
UInt32 theWaitTime = static_cast<UInt32>(inNanos / 1000000ULL);
#if Log_TimedWaits || Log_Latency || Log_Average_Latency
UInt64 theStartNanos = CAHostTimeBase::GetCurrentTimeInNanos();
#endif
mOwner = 0;
#if Log_WaitOwnership
DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAGuard::WaitFor: thread %lu is waiting on %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), GetCurrentThreadId(), mName, mOwner);
#endif
ReleaseMutex(mMutex);
HANDLE theHandles[] = { mMutex, mEvent };
OSStatus theError = WaitForMultipleObjects(2, theHandles, true, theWaitTime);
ThrowIf((theError != WAIT_OBJECT_0) && (theError != WAIT_TIMEOUT), CAException(GetLastError()), "CAGuard::WaitFor: Wait got an error");
mOwner = GetCurrentThreadId();
ResetEvent(mEvent);
#if Log_TimedWaits || Log_Latency || Log_Average_Latency
UInt64 theEndNanos = CAHostTimeBase::GetCurrentTimeInNanos();
#endif
#if Log_TimedWaits
DebugMessageN1("CAGuard::WaitFor: waited %.0f", (Float64)(theEndNanos - theStartNanos));
#endif
//.........这里部分代码省略.........
示例8: mir_sntprintf
void __cdecl CMsnProto::MsnFileAckThread(void* arg)
{
filetransfer* ft = (filetransfer*)arg;
TCHAR filefull[MAX_PATH];
mir_sntprintf(filefull, _T("%s\\%s"), ft->std.tszWorkingDir, ft->std.tszCurrentFile);
replaceStrT(ft->std.tszCurrentFile, filefull);
ResetEvent(ft->hResumeEvt);
if (ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, ft, (LPARAM)&ft->std))
WaitForSingleObject(ft->hResumeEvt, INFINITE);
ft->create();
#ifdef OBSOLETE
if (ft->tType != SERVER_HTTP) {
if (ft->p2p_appID != 0) {
if (fcrt)
p2p_sendFeedStart(ft);
p2p_sendStatus(ft, fcrt ? 200 : 603);
}
else msnftp_sendAcceptReject(ft, fcrt);
}
#endif
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
if (ft->tType == SERVER_HTTP) {
const char *pszSkypeToken;
if (ft->fileId != -1 && (pszSkypeToken=authSkypeToken.Token())) {
NETLIBHTTPHEADER nlbhHeaders[3] = { 0 };
NETLIBHTTPREQUEST nlhr = { 0 }, *nlhrReply;
char szRange[32];
nlbhHeaders[0].szName = "User-Agent"; nlbhHeaders[0].szValue = (LPSTR)MSN_USER_AGENT;
nlbhHeaders[1].szName = "Authorization"; nlbhHeaders[1].szValue = (char*)pszSkypeToken;
nlhr.headersCount = 2;
if (ft->std.currentFileProgress) {
mir_snprintf(szRange, sizeof(szRange), "bytes=%I64d-", ft->std.currentFileProgress);
nlbhHeaders[2].szName = "Range";
nlbhHeaders[2].szValue = szRange;
nlhr.headersCount++;
}
nlhr.cbSize = sizeof(nlhr);
nlhr.requestType = REQUEST_GET;
nlhr.flags = NLHRF_GENERATEHOST | NLHRF_SMARTREMOVEHOST | NLHRF_SMARTAUTHHEADER | NLHRF_HTTP11;
nlhr.szUrl = ft->szInvcookie;
nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
NETLIBOPENCONNECTION nloc = { 0 };
MyNetlibConnFromUrl(nlhr.szUrl, nloc);
nloc.flags |= NLOCF_HTTP;
if (nloc.flags & NLOCF_SSL) nlhr.flags |= NLHRF_SSL;
HANDLE nlc = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
if (nlc && CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)nlc, (LPARAM)&nlhr) != SOCKET_ERROR &&
(nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)nlc, 0)))
{
if (nlhrReply->resultCode == 200 || nlhrReply->resultCode == 206) {
INT_PTR dw;
char buf[1024];
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, ft, 0);
while (!ft->bCanceled && ft->std.currentFileProgress < ft->std.currentFileSize &&
(dw = Netlib_Recv(nlc, buf, sizeof(buf), MSG_NODUMP))>0 && dw!=SOCKET_ERROR)
{
_write(ft->fileId, buf, dw);
ft->std.totalProgress += dw;
ft->std.currentFileProgress += dw;
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std);
}
if (ft->std.currentFileProgress == ft->std.currentFileSize) ft->std.currentFileNumber++;
}
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply);
}
Netlib_CloseHandle(nlc);
mir_free((char*)nloc.szHost);
if (ft->std.currentFileNumber >= ft->std.totalFiles) ft->complete();
}
delete ft;
}
}
示例9: ReadDILCANMsg
DWORD WINAPI ReadDILCANMsg(LPVOID pVoid)
{
CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC*) pVoid;
if (pThreadParam != NULL)
{
CReadCanMsg* pCurrObj = (CReadCanMsg*) pThreadParam->m_pBuffer;
if (pCurrObj != NULL)
{
pThreadParam->m_unActionCode = INVOKE_FUNCTION; // Set default action
// Create the action event. In this case this will be used solely for
// thread exit procedure. The first entry will be used.
pThreadParam->m_hActionEvent = pCurrObj->m_ahActionEvent[0];
DWORD dwWaitRet;
BYTE byHIndex;
bool bLoopON = true;
while (bLoopON)
{
dwWaitRet = WaitForMultipleObjects(pCurrObj->m_nEvents,
pCurrObj->m_ahActionEvent, FALSE, INFINITE);
///// TEMP : BEGIN
DWORD dwLLimit = WAIT_OBJECT_0;
DWORD dwULimit = WAIT_OBJECT_0 + pCurrObj->m_nEvents - 1;
DWORD dwLLError = WAIT_ABANDONED_0;
DWORD dwULError = WAIT_ABANDONED_0 + pCurrObj->m_nEvents - 1;
if ((dwWaitRet >= dwLLimit) && (dwWaitRet <= dwULimit))
{
switch (pThreadParam->m_unActionCode)
{
case INVOKE_FUNCTION:
{
//Get the handle's index and pass it
byHIndex = (BYTE)(dwWaitRet - WAIT_OBJECT_0);
HANDLE hHandleSet = pCurrObj->m_ahActionEvent[byHIndex];
BYTE byNodeIndex;
if( pCurrObj->m_omHandleToNodeMgrMap.Lookup(hHandleSet, byNodeIndex))
{
//vRetrieveDataFromBuffer to read from that buffer
pCurrObj->vRetrieveDataFromBuffer(byNodeIndex);
}
//BOOL Result = ResetEvent(hHandleSet);
ResetEvent(hHandleSet);
}
break;
case EXIT_THREAD:
{
bLoopON = false;
}
break;
case INACTION:
{
// Signal the owner
SetEvent(pThreadParam->m_hThread2Owner);
Sleep(0);
// Wait until owner signals back.
WaitForSingleObject(pThreadParam->m_hOwner2Thread, INFINITE);
// Signal the owner
SetEvent(pThreadParam->m_hThread2Owner);
Sleep(0);
}
break;
case CREATE_TIME_MAP:
default:
break;
}
}
else if ((dwWaitRet >= dwLLError) && (dwWaitRet <= dwULError))
{
TRACE(_T("Abandoned... %X %d\n"), dwWaitRet, g_unCount++);
}
else if ( dwWaitRet == WAIT_TIMEOUT)
{
TRACE(_T("ReadDILCANMsg->WAIT_TIMEOUT %d\n"), g_unCount++);
}
else if (dwWaitRet == WAIT_FAILED)
{
TRACE(_T("WAIT_FAILED... %X %d\n"), GetLastError(), g_unCount++);
}
///// TEMP : END
}
SetEvent(pThreadParam->hGetExitNotifyEvent());
}
}
return 0;
}
示例10: Reset
bool CLREventStatic::Reset()
{
if (!m_fInitialized)
return false;
return !!ResetEvent(m_hEvent);
}
示例11: ConSrvTermReadStream
static NTSTATUS NTAPI
ConSrvTermReadStream(IN OUT PTERMINAL This,
/**/IN PUNICODE_STRING ExeName /**/OPTIONAL/**/,/**/
IN BOOLEAN Unicode,
/**PWCHAR Buffer,**/
OUT PVOID Buffer,
IN OUT PCONSOLE_READCONSOLE_CONTROL ReadControl,
IN ULONG NumCharsToRead,
OUT PULONG NumCharsRead OPTIONAL)
{
PFRONTEND FrontEnd = This->Data;
PCONSRV_CONSOLE Console = FrontEnd->Console;
PCONSOLE_INPUT_BUFFER InputBuffer = &Console->InputBuffer;
// STATUS_PENDING : Wait if more to read ; STATUS_SUCCESS : Don't wait.
NTSTATUS Status = STATUS_PENDING;
PLIST_ENTRY CurrentEntry;
ConsoleInput *Input;
ULONG i;
/* Validity checks */
// ASSERT(Console == InputBuffer->Header.Console);
ASSERT((Buffer != NULL) || (Buffer == NULL && NumCharsToRead == 0));
/* We haven't read anything (yet) */
i = ReadControl->nInitialChars;
if (InputBuffer->Mode & ENABLE_LINE_INPUT)
{
/* COOKED mode, call the line discipline */
if (Console->LineBuffer == NULL)
{
/* Starting a new line */
Console->LineMaxSize = max(256, NumCharsToRead);
Console->LineBuffer = ConsoleAllocHeap(0, Console->LineMaxSize * sizeof(WCHAR));
if (Console->LineBuffer == NULL) return STATUS_NO_MEMORY;
Console->LinePos = Console->LineSize = ReadControl->nInitialChars;
Console->LineComplete = Console->LineUpPressed = FALSE;
Console->LineInsertToggle = Console->InsertMode;
Console->LineWakeupMask = ReadControl->dwCtrlWakeupMask;
/*
* Pre-filling the buffer is only allowed in the Unicode API,
* so we don't need to worry about ANSI <-> Unicode conversion.
*/
memcpy(Console->LineBuffer, Buffer, Console->LineSize * sizeof(WCHAR));
if (Console->LineSize == Console->LineMaxSize)
{
Console->LineComplete = TRUE;
Console->LinePos = 0;
}
}
/* If we don't have a complete line yet, process the pending input */
while (!Console->LineComplete && !IsListEmpty(&InputBuffer->InputEvents))
{
/* Remove input event from queue */
CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
if (IsListEmpty(&InputBuffer->InputEvents))
{
ResetEvent(InputBuffer->ActiveEvent);
}
Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
/* Only pay attention to key down */
if (Input->InputEvent.EventType == KEY_EVENT &&
Input->InputEvent.Event.KeyEvent.bKeyDown)
{
LineInputKeyDown(Console, ExeName,
&Input->InputEvent.Event.KeyEvent);
ReadControl->dwControlKeyState = Input->InputEvent.Event.KeyEvent.dwControlKeyState;
}
ConsoleFreeHeap(Input);
}
/* Check if we have a complete line to read from */
if (Console->LineComplete)
{
while (i < NumCharsToRead && Console->LinePos != Console->LineSize)
{
WCHAR Char = Console->LineBuffer[Console->LinePos++];
if (Unicode)
{
((PWCHAR)Buffer)[i] = Char;
}
else
{
ConsoleInputUnicodeCharToAnsiChar(Console, &((PCHAR)Buffer)[i], &Char);
}
++i;
}
if (Console->LinePos == Console->LineSize)
{
/* Entire line has been read */
//.........这里部分代码省略.........
示例12: named_pipe_accept_loop
static void named_pipe_accept_loop(const char *path) {
HANDLE handles[2];
OVERLAPPED olap;
HANDLE connected_event = CreateEvent(NULL, FALSE, TRUE, NULL);
if (!connected_event) {
w_log(W_LOG_ERR, "named_pipe_accept_loop: CreateEvent failed: %s\n",
win32_strerror(GetLastError()));
return;
}
listener_thread_event = CreateEvent(NULL, FALSE, TRUE, NULL);
handles[0] = connected_event;
handles[1] = listener_thread_event;
memset(&olap, 0, sizeof(olap));
olap.hEvent = connected_event;
w_log(W_LOG_ERR, "waiting for pipe clients on %s\n", path);
while (!stopping) {
w_stm_t stm;
HANDLE client_fd;
DWORD res;
client_fd = CreateNamedPipe(
path,
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|
PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES,
WATCHMAN_IO_BUF_SIZE,
512, 0, NULL);
if (client_fd == INVALID_HANDLE_VALUE) {
w_log(W_LOG_ERR, "CreateNamedPipe(%s) failed: %s\n",
path, win32_strerror(GetLastError()));
continue;
}
ResetEvent(connected_event);
if (!ConnectNamedPipe(client_fd, &olap)) {
res = GetLastError();
if (res == ERROR_PIPE_CONNECTED) {
goto good_client;
}
if (res != ERROR_IO_PENDING) {
w_log(W_LOG_ERR, "ConnectNamedPipe: %s\n",
win32_strerror(GetLastError()));
CloseHandle(client_fd);
continue;
}
res = WaitForMultipleObjectsEx(2, handles, false, INFINITE, true);
if (res == WAIT_OBJECT_0 + 1) {
// Signalled to stop
CancelIoEx(client_fd, &olap);
CloseHandle(client_fd);
continue;
}
if (res == WAIT_OBJECT_0) {
goto good_client;
}
w_log(W_LOG_ERR, "WaitForMultipleObjectsEx: ConnectNamedPipe: "
"unexpected status %u\n", res);
CancelIoEx(client_fd, &olap);
CloseHandle(client_fd);
} else {
good_client:
stm = w_stm_handleopen(client_fd);
if (!stm) {
w_log(W_LOG_ERR, "Failed to allocate stm for pipe handle: %s\n",
strerror(errno));
CloseHandle(client_fd);
continue;
}
make_new_client(stm);
}
}
}
示例13: PerformancePageRefreshThread
static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
{
ULONG CommitChargeTotal;
ULONG CommitChargeLimit;
ULONG CommitChargePeak;
ULONG KernelMemoryTotal;
ULONG KernelMemoryPaged;
ULONG KernelMemoryNonPaged;
ULONG PhysicalMemoryTotal;
ULONG PhysicalMemoryAvailable;
ULONG PhysicalMemorySystemCache;
ULONG TotalHandles;
ULONG TotalThreads;
ULONG TotalProcesses;
WCHAR Text[256];
static const WCHAR wszFormatDigit[] = {'%','u',0};
WCHAR wszMemUsage[255];
LoadStringW(hInst, IDS_STATUS_BAR_MEMORY_USAGE, wszMemUsage, sizeof(wszMemUsage)/sizeof(WCHAR));
/* Create the event */
hPerformancePageEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
/* If we couldn't create the event then exit the thread */
if (!hPerformancePageEvent)
return 0;
while (1)
{
DWORD dwWaitVal;
/* Wait on the event */
dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
/* If the wait failed then the event object must have been */
/* closed and the task manager is exiting so exit this thread */
if (dwWaitVal == WAIT_FAILED)
return 0;
if (dwWaitVal == WAIT_OBJECT_0)
{
ULONG CpuUsage;
ULONG CpuKernelUsage;
int nBarsUsed1, nBarsUsed2;
DWORD_PTR args[2];
/* Reset our event */
ResetEvent(hPerformancePageEvent);
/*
* Update the commit charge info
*/
CommitChargeTotal = PerfDataGetCommitChargeTotalK();
CommitChargeLimit = PerfDataGetCommitChargeLimitK();
CommitChargePeak = PerfDataGetCommitChargePeakK();
wsprintfW(Text, wszFormatDigit, CommitChargeTotal);
SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text);
wsprintfW(Text, wszFormatDigit, CommitChargeLimit);
SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text);
wsprintfW(Text, wszFormatDigit, CommitChargePeak);
SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
args[0] = CommitChargeTotal;
args[1] = CommitChargeLimit;
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
wszMemUsage, 0, 0, Text,
sizeof(Text)/sizeof(*Text), (__ms_va_list*)args);
SendMessageW(hStatusWnd, SB_SETTEXTW, 2, (LPARAM)Text);
/*
* Update the kernel memory info
*/
KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
wsprintfW(Text, wszFormatDigit, KernelMemoryTotal);
SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
wsprintfW(Text, wszFormatDigit, KernelMemoryPaged);
SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
wsprintfW(Text, wszFormatDigit, KernelMemoryNonPaged);
SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
/*
* Update the physical memory info
*/
PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
wsprintfW(Text, wszFormatDigit, PhysicalMemoryTotal);
SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
wsprintfW(Text, wszFormatDigit, PhysicalMemoryAvailable);
SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
wsprintfW(Text, wszFormatDigit, PhysicalMemorySystemCache);
SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
//.........这里部分代码省略.........
示例14: CreateRPCEnvironment
/// <summary>
/// Execute code in context of any existing thread
/// </summary>
/// <param name="pCode">Cde to execute</param>
/// <param name="size">Code size.</param>
/// <param name="callResult">Execution result</param>
/// <param name="thd">Target thread</param>
/// <returns>Status</returns>
NTSTATUS RemoteExec::ExecInAnyThread( PVOID pCode, size_t size, uint64_t& callResult, Thread& thd )
{
NTSTATUS dwResult = STATUS_SUCCESS;
CONTEXT_T ctx;
// Prepare for remote exec
CreateRPCEnvironment( true );
// Write code
dwResult = CopyCode( pCode, size );
if (dwResult != STATUS_SUCCESS)
return dwResult;
if (_hWaitEvent)
ResetEvent( _hWaitEvent );
if (!thd.Suspend())
return LastNtStatus();
if (thd.GetContext( ctx, CONTEXT_ALL, true ))
{
AsmJit::Assembler a;
AsmJitHelper ah( a );
#ifdef _M_AMD64
const int count = 15;
AsmJit::GPReg regs[] = { AsmJit::rax, AsmJit::rbx, AsmJit::rcx, AsmJit::rdx, AsmJit::rsi,
AsmJit::rdi, AsmJit::r8, AsmJit::r9, AsmJit::r10, AsmJit::r11,
AsmJit::r12, AsmJit::r13, AsmJit::r14, AsmJit::r15, AsmJit::rbp
};
//
// Preserve thread context
// I don't care about FPU, XMM and anything else
//
a.sub(AsmJit::rsp, count * WordSize); // Stack must be aligned on 16 bytes
a.pushfq(); //
// Save registers
for (int i = 0; i < count; i++)
a.mov( AsmJit::Mem( AsmJit::rsp, i * WordSize ), regs[i] );
ah.GenCall( _userCode.ptr<size_t>(), { _userData.ptr<size_t>() } );
AddReturnWithEvent( ah, rt_int32, INTRET_OFFSET );
// Restore registers
for (int i = 0; i < count; i++)
a.mov( regs[i], AsmJit::Mem( AsmJit::rsp, i * WordSize ) );
a.popfq();
a.add( AsmJit::rsp, count * WordSize );
a.jmp( ctx.Rip );
#else
a.pushad();
a.pushfd();
ah.GenCall( _userCode.ptr<size_t>(), { _userData.ptr<size_t>() } );
AddReturnWithEvent( ah, rt_int32, INTRET_OFFSET );
a.popfd();
a.popad();
a.push( ctx.NIP );
a.ret();
#endif
if (_userCode.Write( size, a.getCodeSize(), a.make() ) == STATUS_SUCCESS)
{
ctx.NIP = _userCode.ptr<size_t>() + size;
if (!thd.SetContext( ctx, true ))
dwResult = LastNtStatus();
}
else
dwResult = LastNtStatus();
}
else
dwResult = LastNtStatus();
thd.Resume();
if (dwResult == STATUS_SUCCESS)
{
WaitForSingleObject( _hWaitEvent, INFINITE );
callResult = _userData.Read<size_t>( INTRET_OFFSET, 0 );
}
return dwResult;
}
示例15: Log
void CEventThread::RunThread()
{
Log(StrF(_T("Start of CEventThread::RunThread() Name: %s"), m_threadName));
m_threadRunning = true;
m_threadWasStarted = true;
HANDLE *pHandleArray = new HANDLE[m_eventMap.size()];
int indexPos = 0;
for(EventMapType::iterator it = m_eventMap.begin(); it != m_eventMap.end(); it++)
{
pHandleArray[indexPos] = it->first;
indexPos++;
}
SetEvent(m_hEvt);
ResetEvent(m_hEvt);
while(m_exitThread == false)
{
DWORD event = WaitForMultipleObjects((DWORD)m_eventMap.size(), pHandleArray, FALSE, m_waitTimeout);
if(event == WAIT_FAILED)
{
LPVOID lpMsgBuf = NULL;
DWORD dwErr = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwErr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
ASSERT(!lpMsgBuf);
LocalFree(lpMsgBuf);
}
else if(event == WAIT_TIMEOUT)
{
OnTimeOut(m_param);
}
else
{
HANDLE firedHandle = pHandleArray[event - WAIT_OBJECT_0];
int eventId = m_eventMap[firedHandle];
if(eventId == EXIT_EVENT)
{
break;
}
else
{
Log(StrF(_T("Start of CEventThread::RunThread() - OnEvent %d - Name %s"), eventId, m_threadName));
OnEvent(eventId, m_param);
Log(StrF(_T("End of CEventThread::RunThread() - OnEvent %d - Name: %d"), eventId, m_threadName));
}
}
}
UndoFireEvent(EXIT_EVENT);
SetEvent(m_hEvt);
Log(StrF(_T("End of CEventThread::RunThread() Name: %s"), m_threadName));
m_threadRunning = false;
}