IceUtilInternal::CountDownLatch::CountDownLatch(int count) : _count(count) { if(count < 0) { throw IceUtil::Exception(__FILE__, __LINE__); } #ifdef _WIN32 # ifndef ICE_OS_WINRT _event = CreateEvent(0, TRUE, FALSE, 0); # else _event = CreateEventExW(0, 0, CREATE_EVENT_MANUAL_RESET, SEMAPHORE_ALL_ACCESS); # endif if(_event == 0) { throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); } #else int rc = pthread_mutex_init(&_mutex, 0); if(rc != 0) { throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); } rc = pthread_cond_init(&_cond, 0); if(rc != 0) { throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); } #endif }
bool WindowsHttpDownloader::Initialize(const char* user_agent, int timeout_sec, unsigned buf_block_size_kb, unsigned buf_block_count) { if (!WinHttpCheckPlatform()) return false; if (_http.session != NULL) return false; WCHAR ua[MAX_PATH] = {}; if (user_agent) AnsiToUnicode(user_agent, ua); _http.session = WinHttpOpen(ua[0] != 0 ? ua : NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (_http.session == NULL) return false; int timeout = timeout_sec * 1000; if (timeout > 100) WinHttpSetTimeouts(_http.session, timeout, timeout, timeout, timeout); for (int i = 0; i < _countof(_events); i++) { _events[i] = CreateEventExW(NULL, NULL, (i != EventBuf && i != EventDataAvailable) ? CREATE_EVENT_MANUAL_RESET : 0, EVENT_ALL_ACCESS); } return _buffered.Initialize(buf_block_size_kb, buf_block_count); }
int select_t::select( _In_ int nfds, _Inout_ fd_set *readfds, _Inout_ fd_set *writefds, _Inout_ fd_set *exceptfds, _In_ const struct timeval *timeout) { hEvent_ = CreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS); int ec = 0; if (readfds) attach(0, readfds, &ec); if (ec == 0 && writefds) attach(1, writefds, &ec); if (ec == 0 && exceptfds) attach(2, exceptfds, &ec); DWORD ret = 0; if (ec == 0) { DWORD time = timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFINITE; WaitForSingleObjectEx(hEvent_, time, FALSE); } if (readfds) detach(0, readfds); if (writefds) detach(1, writefds); if (exceptfds) detach(2, exceptfds); CloseHandle(hEvent_); if (ec != 0) { SetLastError(ec); return -1; } else if (ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT) { if (readfds) *readfds = sets_[0]; if (writefds) *writefds = sets_[1]; if (exceptfds) *exceptfds = sets_[2]; return count_; } else { return -1; } }
mfxStatus mfxSchedulerCore::StartWakeUpThread(void) { // stop the thread before creating it again // don't try to check thread status, it might lead to interesting effects. if (m_hwWakeUpThread.handle) StopWakeUpThread(); m_timer_hw_event = MFX_THREAD_TIME_TO_WAIT; //!!!!!! // wa for case if it will be outside of coming 15.31 Beta //m_timer_hw_event = 10; #ifdef MFX_VLV_PLATFORM m_timer_hw_event = 10; //temporary fix for VLV #endif #if defined(_WIN32) || defined(_WIN64) m_hwTaskDone.handle = CreateEventExW(NULL, _T("Global\\IGFXKMDNotifyBatchBuffersComplete"), CREATE_EVENT_MANUAL_RESET, STANDARD_RIGHTS_ALL | EVENT_MODIFY_STATE); if (m_hwTaskDone.handle) { // create 'hardware task done' thread Ipp32s iRes = vm_thread_create(&m_hwWakeUpThread, scheduler_wakeup_thread_proc, this); if (0 == iRes) { return MFX_ERR_UNKNOWN; } m_zero_thread_wait = 15; //let wait 15 ms instead of 1 sec (we might miss event in case of GlobalEvents, it affects latency in multi-instance) } else m_zero_thread_wait = 1; // w/o events main thread should poll driver to get status #else #if !defined(SYNCHRONIZATION_BY_NON_ZERO_THREAD) m_zero_thread_wait = 1; #endif #endif // defined(_WIN32) || defined(_WIN64) return MFX_ERR_NONE; } // mfxStatus mfxSchedulerCore::StartWakeUpThread(void)
bool ThreadImpl::ThreadStart(void* param) { if (_hThread != NULL) return false; ThreadParams p; p.Object = this; p.Userdata = param; #ifdef CreateEventEx p.NoitfyEvent = CreateEventExW(NULL, NULL, 0, EVENT_ALL_ACCESS); #else p.NoitfyEvent = CreateEventW(NULL, FALSE, FALSE, NULL); #endif if (p.NoitfyEvent == NULL) return false; _hThread = CreateThread(NULL, 0, &ThreadImpl::DoThreadInvoke, &p, 0, NULL); WaitForSingleObjectEx(p.NoitfyEvent, INFINITE, FALSE); CloseHandle(p.NoitfyEvent); return _hThread != NULL; }