void Initialize(char * pCmdLine) {int iX, iY, iSum; int iErrCode; WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD( 2, 2 ); iErrCode = WSAStartup( wVersionRequested, &wsaData ); if ( iErrCode ) { MessageBox(G_hWnd, "Winsock-V1.1 not found! Cannot execute program.","ERROR",MB_ICONEXCLAMATION | MB_OK); PostQuitMessage(0); return; } if (G_pGame->bInit(G_hWnd, G_hInstance, pCmdLine) == FALSE) { PostQuitMessage(0); return; } G_mmTimer = _StartTimer(1000); for (iX = 0; iX < 64; iX++) for (iY = 0; iY < 510; iY++) { iSum = iX + (iY - 255); if (iSum <= 0) iSum = 1; if (iSum >= 31) iSum = 31; G_iAddTable31[iX][iY] = iSum; iSum = iX + (iY - 255); if (iSum <= 0) iSum = 1; if (iSum >= 63) iSum = 63; G_iAddTable63[iX][iY] = iSum; if ((iY - 255) < iX) G_iAddTransTable31[iY][iX] = iX; else if ((iY - 255) > 31) G_iAddTransTable31[iY][iX] = 31; else G_iAddTransTable31[iY][iX] = iY-255; if ((iY - 255) < iX) G_iAddTransTable63[iY][iX] = iX; else if ((iY - 255) > 63) G_iAddTransTable63[iY][iX] = 63; else G_iAddTransTable63[iY][iX] = iY-255; } }
//============================================================================= void Initialize() { if (_InitWinsock() == FALSE) { MessageBox(G_hWnd, "Socket 1.1 not found! Cannot execute program.","ERROR", MB_ICONEXCLAMATION | MB_OK); PostQuitMessage(0); return; } g_game = new class CGame(G_hWnd); if (g_game->bInit() == FALSE) { PutLogList("(!!!) STOPPED!"); return; } SetPriorityClass( GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS ); G_mmTimer = _StartTimer(TICKDELAY); G_pListenSock = new class XSocket(G_hWnd, SERVERSOCKETBLOCKLIMIT); G_pListenSock->bListen(g_game->m_cGameServerAddr, g_game->m_iGameServerPort, WM_USER_ACCEPT); G_sLogCounter = 0 ; ZeroMemory(G_cLogBuffer, sizeof(G_cLogBuffer)); }
void Initialize() { if (_InitWinsock() == false) { MessageBox(G_hWnd, "Socket 1.1 not found! Cannot execute program.", "ERROR", MB_ICONEXCLAMATION | MB_OK); PostQuitMessage(0); return; } G_pGame = new class CGame(G_hWnd); if (G_pGame->bInit() == false) { PutLogList("(!!!) STOPPED!"); return; } G_mmTimer = _StartTimer(300); G_pListenSock = new class XSocket(G_hWnd, DEF_SERVERSOCKETBLOCKLIMIT); if (G_pGame->m_iGameServerMode == 1) { G_pListenSock->bListen(G_pGame->m_cGameServerAddrInternal, G_pGame->m_iGameServerPort, WM_USER_ACCEPT); } if (G_pGame->m_iGameServerMode == 2) { G_pListenSock->bListen(G_pGame->m_cGameServerAddr, G_pGame->m_iGameServerPort, WM_USER_ACCEPT); } pLogFile = 0; //pLogFile = fopen("test.log","wt+"); }
void CScrollButtonWindow::_OnTimer() { POINT pt = {0, 0}; CScrollBarWindow* pParent = (CScrollBarWindow*)_GetParent(); // more secure w/ dynamic_cast if (pParent == nullptr) { return; } // start another faster timer _StartTimer(_GetScrollSpeed()); GetCursorPos(&pt); MapWindowPoints(HWND_DESKTOP, pParent->_GetWnd(), &pt, 1); RECT rc = {0, 0, 0, 0}; _GetClientRect(&rc); if (PtInRect(&rc, pt)) { switch (subTypeOfControl) { case DFCS_SCROLLDOWN: _NotifyCommand(WM_VSCROLL, SB_LINEDOWN, 0); pParent->_ShiftLine(+1, FALSE); break; case DFCS_SCROLLUP: _NotifyCommand(WM_VSCROLL, SB_LINEUP, 0); pParent->_ShiftLine(-1, FALSE); break; } } }
//----------------------------------------------------------------------------// double CUDAImpl::Run(std::string * err) { _StartTimer(); for(size_t i = 0; i < _kernels.size(); ++i) { if (!_LaunchKernel(*_kernels[i].get(), _cudaKernels[i], err)) { return GPUIP_ERROR; } } cudaDeviceSynchronize(); return _StopTimer(); }
//----------------------------------------------------------------------------// double CUDAImpl::Allocate(std::string * err) { _StartTimer(); if (!_FreeBuffers(err)) { return GPUIP_ERROR; } std::map<std::string,Buffer::Ptr>::const_iterator it; for(it = _buffers.begin(); it != _buffers.end(); ++it) { _cudaBuffers[it->second->name] = NULL; cudaError_t c_err = cudaMalloc(&_cudaBuffers[it->second->name], _BufferSize(it->second)); if(_cudaErrorMalloc(c_err, err)) { return GPUIP_ERROR; } } return _StopTimer(); }
//----------------------------------------------------------------------------// double CUDAImpl::Copy(Buffer::Ptr buffer, Buffer::CopyOperation op, void * data, std::string * err) { _StartTimer(); cudaError_t e = cudaSuccess; const size_t size = _BufferSize(buffer); if (op == Buffer::COPY_FROM_GPU) { e =cudaMemcpy(data, _cudaBuffers[buffer->name], size, cudaMemcpyDeviceToHost); } else if (op == Buffer::COPY_TO_GPU) { e = cudaMemcpy(_cudaBuffers[buffer->name],data, size, cudaMemcpyHostToDevice); } if (_cudaErrorCopy(e, err, buffer->name, op)) { return GPUIP_ERROR; } return _StopTimer(); }
void CScrollButtonWindow::_OnLButtonDown(POINT pt) { CButtonWindow::_OnLButtonDown(pt); CScrollBarWindow* pParent = (CScrollBarWindow*)_GetParent(); // more secure w/ dynamic_cast if (pParent == nullptr) { return; } switch (subTypeOfControl) { case DFCS_SCROLLDOWN: _NotifyCommand(WM_VSCROLL, SB_LINEDOWN, 0); pParent->_ShiftLine(+1, FALSE); break; case DFCS_SCROLLUP: _NotifyCommand(WM_VSCROLL, SB_LINEUP, 0); pParent->_ShiftLine(-1, FALSE); break; } _StartTimer(_GetScrollDelay()); }
double CUDAImpl::Build(std::string * err) { _StartTimer(); if(!_UnloadModule(err)) { return GPUIP_ERROR; } const char * file_helper_math_h = ".helper_math.h"; const char * file_temp_cu = ".temp.cu"; const char * file_temp_ptx = ".temp.ptx"; // Includes vector float operations such as mult, add etc std::ofstream out_helper(file_helper_math_h); out_helper << get_cuda_helper_math(); out_helper.close(); // Create temporary file to compile std::ofstream out(file_temp_cu); out << "#include \"" << file_helper_math_h << "\"\n"; out << "extern \"C\" { \n"; // To avoid function name mangling for(size_t i = 0; i < _kernels.size(); ++i) { out << _kernels[i]->code << "\n"; } out << "}"; // End the extern C bracket out.close(); std::stringstream ss; const char * cuda_bin_path = getenv("CUDA_BIN_PATH"); if (cuda_bin_path != NULL) { ss << cuda_bin_path << "/nvcc"; } else { ss << "nvcc"; } ss << " -ptx " << file_temp_cu << " -o " << file_temp_ptx << " --Wno-deprecated-gpu-targets" << " -include " << file_helper_math_h; if(sizeof(void *) == 4) { ss << " -m32"; } else { ss << " -m64"; } #ifdef _WIN32 const char * cl_bin_path = getenv("CL_BIN_PATH"); if (cl_bin_path != NULL) { ss << " -ccbin \"" << cl_bin_path << "\""; } #endif ss << " 2>&1" << std::endl; // get both standard output and error std::string pipe_err; int nvcc_exit_status = _execPipe(ss.str().c_str(), &pipe_err); // Cleanup temp text file _removeFile(file_helper_math_h); _removeFile(file_temp_cu); if (nvcc_exit_status) { (*err) = "Cuda error: Could not compile kernels:\n"; (*err) += pipe_err; return GPUIP_ERROR; } // Load cuda ptx from file CUresult c_err = cuModuleLoad(&_cudaModule, ".temp.ptx"); _removeFile(file_temp_ptx); if (_cudaErrorLoadModule(c_err, err)) { return GPUIP_ERROR; } _cudaKernels.resize(_kernels.size()); for(size_t i = 0; i < _kernels.size(); ++i) { c_err = cuModuleGetFunction(&_cudaKernels[i], _cudaModule, _kernels[i]->name.c_str()); if (_cudaErrorGetFunction(c_err, err, _kernels[i]->name)) { return GPUIP_ERROR; } } _cudaBuild = true; return _StopTimer(); }
void SMTPDeliveryManager::DoWork() //---------------------------------------------------------------------------() // DESCRIPTION: // Responsible for creating threads to deliver messages. //---------------------------------------------------------------------------() { LOG_DEBUG("SMTPDeliveryManager::Start()"); // Unlock all messages PersistentMessage::UnlockAll(); shared_ptr<WorkQueue> pQueue = WorkQueueManager::Instance()->GetQueue(GetQueueName()); while (1) { // Deliver all pending messages shared_ptr<Message> pMessage; while (pMessage = _GetNextMessage()) { // Lock this message if (!PersistentMessage::LockObject(pMessage)) { // Failed to lock the message. ErrorManager::Instance()->ReportError(ErrorManager::Critical, 4216, "SMTPDeliveryManager::DoWork", "Failed to lock message."); continue; } shared_ptr<DeliveryTask> pDeliveryTask = shared_ptr<DeliveryTask>(new DeliveryTask(pMessage)); WorkQueueManager::Instance()->AddTask(m_iQueueID, pDeliveryTask); m_lCurNumberOfSent++; _SendStatistics(); ServerStatus::Instance()->OnMessageProcessed(); } _StartTimer(); const int iSize = 3; HANDLE handles[iSize]; handles[0] = m_hStopRequest.GetHandle(); handles[1] = m_evtDeliverMessage.GetHandle(); handles[2] = m_evtTimer; DWORD dwWaitResult = WaitForMultipleObjects(iSize, handles, FALSE, INFINITE); int iEvent = dwWaitResult - WAIT_OBJECT_0; // Temp test to see if cause of IOCP errors if (iEvent < 0) { ErrorManager::Instance()->ReportError(ErrorManager::Critical, 9999, "SMTPDeliveryManager::DoWork", "WARNING iEvent less than 0!"); m_evtDeliverMessage.Reset(); return; } else { switch (iEvent) { case 0: // We should stop now _SendStatistics(true); return; case 1: // --- Reset the event to give someone else the chance to // sending emails. m_evtDeliverMessage.Reset(); break; } } } _SendStatistics(true); return; }