/*********************************************************************** * WaitEvent (KERNEL.30) */ BOOL16 WINAPI WaitEvent16( HTASK16 hTask ) { TDB *pTask; if (!hTask) hTask = GetCurrentTask(); pTask = TASK_GetPtr( hTask ); if (pTask->flags & TDBF_WIN32) { FIXME("called for Win32 thread (%04x)!\n", GetCurrentThreadId()); return TRUE; } if (pTask->nEvents > 0) { pTask->nEvents--; return FALSE; } if (pTask->teb == NtCurrentTeb()) { DWORD lockCount; NtResetEvent( pTask->hEvent, NULL ); ReleaseThunkLock( &lockCount ); SYSLEVEL_CheckNotLevel( 1 ); WaitForSingleObject( pTask->hEvent, INFINITE ); RestoreThunkLock( lockCount ); if (pTask->nEvents > 0) pTask->nEvents--; } else FIXME("for other task %04x cur=%04x\n",pTask->hSelf,GetCurrentTask()); return TRUE; }
/* * @implemented */ BOOL WINAPI ResetEvent(IN HANDLE hEvent) { NTSTATUS Status; /* Clear the event */ Status = NtResetEvent(hEvent, NULL); if (NT_SUCCESS(Status)) return TRUE; /* If we got here, then we failed */ BaseSetLastNTError(Status); return FALSE; }
/* Loop to install all queued devices installations */ static ULONG NTAPI DeviceInstallThread(IN PVOID Parameter) { HINF hSetupInf = *(HINF*)Parameter; PSLIST_ENTRY ListEntry; DeviceInstallParams* Params; LARGE_INTEGER Timeout; for (;;) { ListEntry = RtlInterlockedPopEntrySList(&DeviceInstallListHead); if (ListEntry == NULL) { /* * The list is now empty, but there may be a new enumerated device * that is going to be added to the list soon. In order to avoid * setting the hNoPendingInstalls event to release it soon after, * we wait for maximum 1 second for no PnP enumeration event being * received before declaring that no pending installations are * taking place and setting the corresponding event. */ Timeout.QuadPart = -10000000LL; /* Wait for 1 second */ if (NtWaitForSingleObject(hDeviceInstallListNotEmpty, FALSE, &Timeout) == STATUS_TIMEOUT) { /* We timed out: set the event and do the actual wait */ NtSetEvent(hNoPendingInstalls, NULL); NtWaitForSingleObject(hDeviceInstallListNotEmpty, FALSE, NULL); } } else { NtResetEvent(hNoPendingInstalls, NULL); Params = CONTAINING_RECORD(ListEntry, DeviceInstallParams, ListEntry); InstallDevice(hSetupInf, hEnumKey, hServicesKey, Params->DeviceIds); RtlFreeHeap(ProcessHeap, 0, Params); } } return 0; }
BOOLEAN WeSendServerRequest( __in HWND hWnd ) { ULONG threadId; ULONG processId; LARGE_INTEGER timeout; if (!WeServerSharedData || !WeServerSharedSectionEvent) return FALSE; threadId = GetWindowThreadProcessId(hWnd, &processId); if (UlongToHandle(processId) == NtCurrentProcessId()) { // We are trying to get information about the server. Call the procedure directly. WepWriteClientData(hWnd); return TRUE; } // Call the client and wait for the client to finish. WeCurrentMessageId++; WeServerSharedData->MessageId = WeCurrentMessageId; NtResetEvent(WeServerSharedSectionEvent, NULL); if (!SendNotifyMessage(hWnd, WeServerMessage, (WPARAM)NtCurrentProcessId(), WeCurrentMessageId)) return FALSE; timeout.QuadPart = -WE_CLIENT_MESSAGE_TIMEOUT * PH_TIMEOUT_MS; if (NtWaitForSingleObject(WeServerSharedSectionEvent, FALSE, &timeout) != STATUS_WAIT_0) return FALSE; return TRUE; }
VOID NotificationThread( PVOID pJunk) { INT nEvents = ID_MEDIACHANGE; INT nMediaEvents = 0; KPRIORITY Priority; NTSTATUS Status; HANDLE hEvent[ MAXIMUM_WAIT_OBJECTS ]; try { /* * Set the priority of the RIT to 3. */ Priority = LOW_PRIORITY + 3; NtSetInformationThread(hThreadNotification, ThreadPriority, &Priority, sizeof(KPRIORITY)); /* * Setup the NLS event */ NtCreateEvent(&ghNlsEvent, EVENT_ALL_ACCESS, NULL, SynchronizationEvent, FALSE); UserAssert( ghNlsEvent != NULL ); hEvent[ID_NLS] = ghNlsEvent; /* * Setup the MediaChangeEvent */ RtlZeroMemory(wcDriveCache, sizeof(wcDriveCache)); Status = NtUserGetMediaChangeEvents(MAXIMUM_WAIT_OBJECTS - ID_MEDIACHANGE, &hEvent[ID_MEDIACHANGE], &nMediaEvents); if (NT_SUCCESS(Status)) { nEvents += nMediaEvents; } #ifdef DEBUG else { KdPrint(("NotificationThread: NtUserGetMediaChangeEvents failed 0x08X\n", Status)); } #endif StartRegReadRead(); /* * Sit and wait forever. */ while (TRUE) { Status = NtWaitForMultipleObjects(nEvents, hEvent, WaitAny, TRUE, NULL); if (Status == ID_NLS + WAIT_OBJECT_0) { /* * Handle the NLS event */ if (gfLogon) { gfLogon = FALSE; BaseSrvNlsUpdateRegistryCache(NULL, NULL); } } else if (Status >= ID_MEDIACHANGE + WAIT_OBJECT_0 && Status < (ID_MEDIACHANGE + nMediaEvents + WAIT_OBJECT_0)) { /* * Handle the CD-ROM \Device\MediaChangeEventX event */ NtResetEvent( hEvent[Status - WAIT_OBJECT_0], NULL ); HandleMediaChangeEvent( Status - WAIT_OBJECT_0 - ID_MEDIACHANGE ); } } // While (TRUE) } except (CsrUnhandledExceptionFilter(GetExceptionInformation())) { KdPrint(("Registry notification thread is dead, sorry.\n")); } }
INT_PTR CALLBACK PhpEventPageProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PCOMMON_PAGE_CONTEXT pageContext; pageContext = PhpCommonPageHeader(hwndDlg, uMsg, wParam, lParam); if (!pageContext) return FALSE; switch (uMsg) { case WM_INITDIALOG: { PhpRefreshEventPageInfo(hwndDlg, pageContext); } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_SET: case IDC_RESET: case IDC_PULSE: { NTSTATUS status; HANDLE eventHandle; if (NT_SUCCESS(status = pageContext->OpenObject( &eventHandle, EVENT_MODIFY_STATE, pageContext->Context ))) { switch (LOWORD(wParam)) { case IDC_SET: NtSetEvent(eventHandle, NULL); break; case IDC_RESET: NtResetEvent(eventHandle, NULL); break; case IDC_PULSE: NtPulseEvent(eventHandle, NULL); break; } NtClose(eventHandle); } PhpRefreshEventPageInfo(hwndDlg, pageContext); if (!NT_SUCCESS(status)) PhShowStatus(hwndDlg, L"Unable to open the event", status, 0); } break; } } break; } return FALSE; }