PIMPL(WorkerThread*x) : owner(x), ID(0) , keeprunning(true), isrunning(false) , m_todo(Mutex()), m_done(Mutex()) , s_newdata(Semaphore()) , processingID(WorkerThread::INVALID) #ifndef HAVE_PTW32_HANDLE_T , p_thread(0) #endif { pthread_mutex_init(&p_runmutex, 0); pthread_cond_init (&p_runcond , 0); }
/*--------------------------------------------------------------------------- Captures the contents of the frame buffer object for streaming purposes. Returns true if the frame was successfully captured. If the Wait flag is set, the function with use a blocking mutex lock on the Frame texture. ---------------------------------------------------------------------------*/ bool Filter::Capture(Texture &Frame, bool Wait) { if (!Ready()) {return false;} MutexControl Mutex(Frame.GetMutexHandle()); if (!Wait && !Mutex.LockRequest()) {return false;} else {Mutex.Lock();} vector2u Res = Frame.Resolution(); if (Res.U != ViewPort.C2 || Res.V != ViewPort.C3 || Frame.DataType() != Texture::TypeRGB) { Res.Set(ViewPort.C2, ViewPort.C3); Frame.Create(Res, Texture::TypeRGB); } glBindFramebuffer(GL_READ_FRAMEBUFFER, FBOID); glReadPixels(0, 0, Res.U, Res.V, Frame.DataFormat(), Frame.DataCompType(), Frame.Pointer()); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); #if defined (DEBUG) GLenum Error = glGetError(); if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));} #endif return true; }
void* Nullcline::DataCopy() const { #ifdef DEBUG_FUNC ScopeTracker st("Nullcline::DataCopy", std::this_thread::get_id()); #endif std::lock_guard<std::mutex> lock( Mutex() ); if (!ConstData()) return nullptr; return new Record(*static_cast<const Record*>( ConstData() )); }
/*--------------------------------------------------------------------------- This function will update either the video texture, or depth texture, or both (if applicable). It may also recofigure the filter if the selected input has a different resolution. Returns true if either of the textures were updated. ---------------------------------------------------------------------------*/ bool Filter::Update(Buffers &Buffer) { if (!Ready()) {return false;} //Test for resolution change, if applicable Change(Buffer); bool Updated = false; if (Buffer.VideoUpdated(VideoUpdateID) && EnableVideo) { Texture &VideoFront = Buffer.GetVideo(); MutexControl Mutex(VideoFront.GetMutexHandle()); if (Mutex.LockRequest()) { Video.Bind(0); Video.Update(VideoFront); Video.Unbind(0); Mutex.Unlock(); Updated |= true; } } if (Buffer.DepthUpdated(DepthUpdateID) && EnableDepth) { Texture &DepthFront = Buffer.GetDepth(); MutexControl Mutex(DepthFront.GetMutexHandle()); if (Mutex.LockRequest()) { Depth.Bind(0); Depth.Update(DepthFront); Depth.Unbind(0); Mutex.Unlock(); Updated |= true; } } #if defined (DEBUG) GLenum Error = glGetError(); if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));} #endif return Updated; }
pair<Array<double>,Mutex>&HMMTables<CLS,MAPPERCLASSTOSTRING>::doGetBetaInit(int I) { betalock.lock(); if( !init_beta.count(I) ){ init_beta[I]=pair<Array<double>,Mutex>(Array<double>(I,0),Mutex()); } pair<Array<double>,Mutex>& ret = init_beta[I]; betalock.unlock(); return ret; }
Thread::Thread () : m_handle (NULL) , m_ID (-1) , m_name ("Unknown") , m_state (eState_Stopped) , m_stackSize (EX_KB(12)) , m_threadMutex (NULL) , m_priority (ePriority_Normal) , m_usePriorityBoost (true) , m_autoRelease (false) { if ( m_threadMutex == NULL ) m_threadMutex = ex_new Mutex(); }
OTSocket::OTSocket() : m_Mutex(Mutex()), m_lLatencySendMs(0), m_nLatencySendNoTries(0), m_lLatencyReceiveMs(0), m_nLatencyReceiveNoTries(0), m_lLatencyDelayAfter(0), m_bIsBlocking(false), m_bInitialized(false), m_HasContext(false), m_bConnected(false), m_bListening(false), m_strConnectPath(""), m_strBindingPath("") { }
//初始化函数 BOOL CGamePlazaApp::InitInstance() { __super::InitInstance(); //判断是否重入 #ifndef ADMIN_PLAZA #ifndef _DEBUG bool bExistIGame=false; CMutex Mutex(FALSE,MAIN_DLG_CLASSNAME,NULL); if (Mutex.Lock(0)==FALSE) bExistIGame=true; CWnd * pIGameWnd=CWnd::FindWindow(MAIN_DLG_CLASSNAME,NULL); if (pIGameWnd!=NULL) { bExistIGame=true; if (pIGameWnd->IsIconic()) pIGameWnd->ShowWindow(SW_RESTORE); pIGameWnd->SetActiveWindow(); pIGameWnd->BringWindowToTop(); pIGameWnd->SetForegroundWindow(); } if (bExistIGame==true) return FALSE; #endif #endif //程序初始化 AfxOleInit(); AfxInitRichEdit(); AfxInitRichEdit2(); InitCommonControls(); AfxEnableControlContainer(); //设置注册表 SetRegistryKey(szSystemRegKey); //加载界面库 CSkinAttribute::LoadSkinAttribute(GET_OBJECT_INTERFACE(m_SkinRecordFile,IUnknownEx)); //加载配置 g_GlobalOption.LoadOptionParameter(); //全局信息 if (g_GlobalUnits.InitGlobalUnits()==false) { AfxMessageBox(TEXT("游戏广场初始化失败,程序即将退出!"),MB_ICONSTOP); return FALSE; } //变量定义 WNDCLASS WndClasss; ZeroMemory(&WndClasss,sizeof(WndClasss)); //注册窗口 WndClasss.style=CS_DBLCLKS; WndClasss.lpfnWndProc=DefWindowProc; WndClasss.lpszClassName=MAIN_DLG_CLASSNAME; WndClasss.hInstance=AfxGetInstanceHandle(); WndClasss.hIcon=LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); WndClasss.hCursor=LoadStandardCursor(MAKEINTRESOURCE(IDC_ARROW)); if (AfxRegisterClass(&WndClasss)==FALSE) AfxThrowResourceException(); //建立窗口 CGameFrame * pMainFrame=new CGameFrame(); pMainFrame->Create(MAIN_DLG_CLASSNAME,TEXT(""),WS_MINIMIZEBOX|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,CRect(0,0,0,0)); m_pMainWnd=pMainFrame; return TRUE; }
/* * @file LightFlash.cpp * @author Mahmoud Dariti * @author Mohamed Sakhri * @date NOV 6, 2012 * * This class is a thread implementation of the flashing red light. * the blinking frequency id given as a parameter of the thread function execute. * */ #include "LightFlash.h" //#define DEBUG_ LightFlash* LightFlash::light_flash_instance_ = NULL; Mutex LightFlash::light_flash_mutex_ = Mutex(); LightFlash::LightFlash() { is_flashing_ = true; } LightFlash::~LightFlash() { // TODO Auto-generated destructor stub } LightFlash* LightFlash::getInstance() { if (-1 == ThreadCtl(_NTO_TCTL_IO, 0)) { perror("ThreadCtl access failed\n"); return NULL; }
/* * util.cpp * * Created on: Dec 4, 2013 * Author: kwang */ #include "util.h" #include "matrix_tcp_proxy_stub.h" uint _BUF_SIZE = 8192; Mutex tokenMutex = Mutex(); Mutex sockMutex = Mutex(); vector<string> tokenize(const std::string &source, const char *delimiter = " ") { //tokenMutex.lock(); vector<string> results; size_t prev = 0, next = 0; if (source.empty()) { return results; } while ((next = source.find_first_of(delimiter, prev)) != string::npos) { if (next - prev != 0) { results.push_back(source.substr(prev, next - prev)); } prev = next + 1; }
//初始化函数 BOOL CGamePlaceApp::InitInstance() { //TODO: call AfxInitRichEdit2() to initialize richedit2 library. Glb().m_release=false;//是否发布版 Glb().m_weblogon=false; //是否互联星空登录 Glb().m_autoreg=false; //不用设置,此变量程序自动改变 #ifndef MY_DEBUG Glb().m_release=true;//是否发布版 // try #endif { //定义变量 #ifndef MY_DEBUG CBcfFile _f(CBcfFile::GetAppPath()+"bzgame.bcf"); CString _mutexId = _f.GetKeyVal("BZW","mutexid","GamePlaceChangeed10001000"); CMutex Mutex(FALSE, _mutexId, NULL);////互斥 if (Mutex.Lock(0)==FALSE) return FALSE; SetUnhandledExceptionFilter(ExceptionFilter); #endif #ifdef BZ_ZLIB ///<读取资源文件 ///<先获取密码 add by wxx CBcfFile fMsg(CBcfFile::GetAppPath()+"bzgame.bcf"); CString strPassWord; strPassWord = fMsg.GetKeyVal("BZW","LoginIP1","www.szbzw.com"); char *password = strPassWord.GetBuffer(strPassWord.GetLength()+1); ///<读取文件 CUnZipRes unZipRes; char * pPW=new char[strlen(password)+1]; memcpy(pPW,password,strlen(password)+1); unZipRes.SetPassWord(pPW); if(!CBcfFile::IsFileExist("image.r"))///add by wxx 0712 { MessageBox(NULL,"资源文件有损!","提示",MB_OK); return FALSE; } CString strPackage = CBcfFile::GetAppPath() + "image.r"; BzDui::CPaintManagerUI::SetResourcePackage(strPackage.GetBuffer(),password); unZipRes.ReadFile("image.r",(unsigned char*)pPW); delete []pPW; #endif //初始化 InitCommonControls(); CWinApp::InitInstance(); #ifndef MY_DEV // 初始BzCrashRpt BzCrash_Initiation(); BzCrash_DisableSetUnhandledExceptionFilter(); BzCrash_SetProjectName("D平台大厅"); BzCrash_SetEmailSender("*****@*****.**"); BzCrash_SetEmailReceiver("*****@*****.**"); BzCrash_SetSmtpServer("smtp.sina.com"); BzCrash_SetSmtpUser("bzbugrev"); BzCrash_SetSmtpPassword("1122334455"); BzCrash_DeleteSended(false); #endif //初始化 SOCKET if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); SetRegistryKey(IDS_REG_KEY); //设置程序路径 TCHAR szModuleName[MAX_PATH]; DWORD dwLength=GetModuleFileName(AfxGetInstanceHandle(),szModuleName,sizeof(szModuleName)); szModuleName[dwLength-lstrlen(m_pszExeName)-lstrlen(TEXT(".EXE"))-1]=0; SetCurrentDirectory(szModuleName); CreateDirectory("CustomFace",NULL); CString str; int len=strlen(szModuleName); szModuleName[len]='\\'; szModuleName[len+1]='\0'; AfxGetApp()->WriteProfileString(TEXT("LogonInfo"),TEXT("Path"),szModuleName); Glb().m_Path=szModuleName; //初始化全局资源 AfxInitRichEdit(); CGameImageLink::InitResource(); // 加载钩子 DetourFunctionWithTrampoline((PBYTE)SetScrollInfoT, (PBYTE)SetScrollInfoD); DetourFunctionWithTrampoline((PBYTE)GetScrollInfoT, (PBYTE)GetScrollInfoD); DetourFunctionWithTrampoline((PBYTE)SetScrollPosT, (PBYTE)SetScrollPosD); DetourFunctionWithTrampoline((PBYTE)GetScrollPosT, (PBYTE)GetScrollPosD); DetourFunctionWithTrampoline((PBYTE)SetScrollRangeT, (PBYTE)SetScrollRangeD); DetourFunctionWithTrampoline((PBYTE)GetScrollRangeT, (PBYTE)GetScrollRangeD); DetourFunctionWithTrampoline((PBYTE)ShowScrollBarT, (PBYTE)ShowScrollBarD); DetourFunctionWithTrampoline((PBYTE)EnableScrollBarT, (PBYTE)EnableScrollBarD); //引入DirectUI支持,初始化DirectUI BzDui::CPaintManagerUI::SetInstance(m_hInstance); CString s = CBcfFile::GetAppPath ();/////本地路径 CString strSkin = m_skinmgr.GetSkinBcfFileName(); CBcfFile f(s + strSkin); TCHAR szUIPath[MAX_PATH]; CString skinfolder = f.GetKeyVal(m_skinmgr.GetKeyVal(strSkin),"skinfolder",m_skinmgr.GetSkinPath()); wsprintf(szUIPath,"%s",skinfolder); BzDui::CPaintManagerUI::SetResourcePath(szUIPath); //建立对话框 CGamePlaceDlg dlg; m_pMainWnd=&dlg; //BZUIInitial(); dlg.DoModal(); /////////////////////////////////////////////////////////// ///Kylin 20090107 添加最近游戏列表 //CString s=CBcfFile::GetAppPath (false);/////本地路径 //CBcfFile f( s + "bzgame.bcf"); //CString temp=""; //try //{ // for(int i=0;i<Glb().m_baFavorSave.GetCount();i++) // { // temp.Format("%s%i;",temp,Glb().m_baFavorSave[i]); // } // f.SetKeyValString(Glb().m_key,"Favor",temp); //} //catch (...) //{ // return FALSE; //} /////////////////////////////////////////////////////////// //BZUIShutDown(); } #ifndef MY_DEBUG //catch (...) //{ // //重新启动游戏 // STARTUPINFO StartInfo; // PROCESS_INFORMATION Info; // ::memset(&Info,0,sizeof(Info)); // ::memset(&StartInfo,0,sizeof(StartInfo)); // StartInfo.cb=sizeof(StartInfo); // StartInfo.wShowWindow=SW_SHOWMAXIMIZED; // CreateProcess(NULL,TEXT("BZW.exe"),NULL,NULL,TRUE,CREATE_DEFAULT_ERROR_MODE,NULL,NULL,&StartInfo,&Info); //} #endif return FALSE; }
/******************************************************************************* * ImageSources.cpp * * (C) 2007 AG Aktives Sehen <*****@*****.**> * Universitaet Koblenz-Landau * * Additional information: * $Id: $ *******************************************************************************/ #include "ImageSources.h" #define THIS ImageSources std::map<THIS::SourceId,std::string> THIS::sourceDesc=std::map<THIS::SourceId,std::string>(); Mutex THIS::mutex=Mutex(); std::map< THIS::SourceId, std::string > THIS::getSourceDesc() { initSourceDesc(); mutex.lock(); std::map<SourceId,std::string> descCopy=sourceDesc; mutex.unlock(); return descCopy; } std::string THIS::getSourceDesc( THIS::SourceId id ) { initSourceDesc(); mutex.lock(); std::string desc;
/** * Copyright (C) 2011-2012 Xu Cheng, Yang Zhengyu, Zuo Zhiheng, Yao Wenjie * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ ///:log.cpp #include "global.h" #include "log.h" BINGO_BEGIN_NAMESPACE bool Log::m_enable = false; bool Log::m_firstenable = true; QString Log::m_logfile = ".log"; Mutex Log::m_logMutex = Mutex(); QTime Log::m_timerBegin = QTime(); BINGO_END_NAMESPACE ///:~
//初始化函数 BOOL CGamePlazaApp::InitInstance() { __super::InitInstance(); //判断是否重入 #ifndef ADMIN_PLAZA #ifndef _DEBUG bool bExistIGame=false; CMutex Mutex(FALSE,MAIN_DLG_CLASSNAME,NULL); if (Mutex.Lock(0)==FALSE) bExistIGame=true; CWnd * pIGameWnd=CWnd::FindWindow(MAIN_DLG_CLASSNAME,NULL); if (pIGameWnd!=NULL) { bExistIGame=true; if (pIGameWnd->IsIconic()) pIGameWnd->ShowWindow(SW_RESTORE); pIGameWnd->SetActiveWindow(); pIGameWnd->BringWindowToTop(); pIGameWnd->SetForegroundWindow(); } if (bExistIGame==true) return FALSE; #endif #endif DWORD d=MAKELONG(MAKEWORD(6,0),MAKEWORD(1,0)); //程序初始化 AfxOleInit(); AfxInitRichEdit(); AfxInitRichEdit2(); InitCommonControls(); AfxEnableControlContainer(); //设置注册表 SetRegistryKey(szSystemRegKey); //加载界面库 CSkinAttribute::LoadSkinAttribute(GET_OBJECT_INTERFACE(m_SkinRecordFile,IUnknownEx)); //加载配置 g_GlobalOption.LoadOptionParameter(); //全局信息 if (g_GlobalUnits.InitGlobalUnits()==false) { AfxMessageBox(TEXT("游戏广场初始化失败,程序即将退出!"),MB_ICONSTOP); return FALSE; } //注册窗口类 WNDCLASS WndClasss; memset(&WndClasss,0,sizeof(WndClasss)); WndClasss.lpfnWndProc=::DefWindowProc; WndClasss.hInstance=AfxGetInstanceHandle(); WndClasss.lpszClassName=MAIN_DLG_CLASSNAME; if (!AfxRegisterClass(&WndClasss)) AfxThrowResourceException(); //建立窗口 const DWORD dwStyte=WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED|WS_CLIPCHILDREN; CGameFrame * pMainFrame=new CGameFrame(); pMainFrame->Create(MAIN_DLG_CLASSNAME,TEXT(""),dwStyte,CRect(0,0,0,0)); m_pMainWnd=pMainFrame; return TRUE; }
* @date NOV 2, 2012 * * This class implements all methods needed to interact with Port C * */ #include "PortC.h" #include "HWaccess.h" #include <iostream.h> /** * Mutex locks and unlocks access to Port C to assure thread-safe implementation. * * \see set_Bit_on() * \see set_Bit_off() */ Mutex PortC::portC_mutex_ = Mutex(); /** * Constructor does nothing */ PortC::PortC() { } /** * Destructor does nothing */ PortC::~PortC() { } /** * This method takes the bit's mask which has to be set on as parameter and it's thread-safe.
namespace DAVA { Mutex APKFile::mutex = Mutex(); APKFile::APKFile() : DynamicMemoryFile() { } APKFile::~APKFile() { } File * APKFile::CreateFromAssets(const FilePath &filePath, uint32 attributes) { LockGuard<Mutex> guard(mutex); FileSystem * fileSystem = FileSystem::Instance(); for (List<FileSystem::ResourceArchiveItem>::iterator ai = fileSystem->resourceArchiveList.begin(); ai != fileSystem->resourceArchiveList.end(); ++ai) { FileSystem::ResourceArchiveItem & item = *ai; String filenamecpp = filePath.GetAbsolutePathname(); String::size_type pos = filenamecpp.find(item.attachPath); if (0 == pos) { String relfilename = filenamecpp.substr(item.attachPath.length()); int32 size = item.archive->LoadResource(relfilename, 0); if (-1 == size) { return 0; } uint8 * buffer = new uint8[size]; item.archive->LoadResource(relfilename, buffer); APKFile *fileInstance = CreateFromData(relfilename, buffer, size, attributes); SafeDeleteArray(buffer); return fileInstance; } } bool isDirectory = FileSystem::Instance()->IsDirectory(filePath); if(isDirectory) { Logger::Error("[APKFile::CreateFromAssets] Can't create file because of it is directory (%s)", filePath.GetAbsolutePathname().c_str()); return NULL; } AssetsManager* assetsManager = AssetsManager::Instance(); DVASSERT_MSG(assetsManager, "[APKFile::CreateFromAssets] Need to create AssetsManager before loading files"); zip* package = assetsManager->GetApplicationPackage(); if (NULL == package) { DVASSERT_MSG(false, "[APKFile::CreateFromAssets] Package file should be initialized."); return NULL; } String assetFileStr = filePath.GetAbsolutePathname(); int index = zip_name_locate(package, assetFileStr.c_str(), 0); if (-1 == index) { Logger::Error("[APKFile::CreateFromAssets] Can't locate file in the archive: %s", assetFileStr.c_str()); return NULL; } struct zip_stat stat; int32 error = zip_stat_index(package, index, 0, &stat); if (-1 == error) { Logger::Error("[APKFile::CreateFromAssets] Can't get file info: %s", assetFileStr.c_str()); return NULL; } zip_file* file = zip_fopen_index(package, index, 0); if (NULL == file) { Logger::Error("[APKFile::CreateFromAssets] Can't open file in the archive: %s", assetFileStr.c_str()); return NULL; } DVASSERT(stat.size >= 0); uint8 *data = new uint8[stat.size]; if (zip_fread(file, data, stat.size) != stat.size) { Logger::Error("[APKFile::CreateFromAssets] Error reading file: %s", assetFileStr.c_str()); SafeDeleteArray(data); zip_fclose(file); return NULL; } APKFile *fileInstance = CreateFromData(filePath, data, stat.size, attributes); DVASSERT_MSG(fileInstance, "[APKFile::CreateFromAssets] Can't create dynamic file from memory"); SafeDeleteArray(data); zip_fclose(file); return fileInstance; } APKFile * APKFile::CreateFromData(const FilePath &filePath, const uint8 * data, int32 dataSize, uint32 attributes) { APKFile *fl = new APKFile(); fl->filename = filePath; fl->Write(data, dataSize); fl->fileAttributes = attributes; fl->currentPtr = 0; return fl; } };
* * @author Mahmoud Dariti * @author Mohamed Sakhri * @date Nov 25, 2012 * * * This Class implements the Demultiplexer's. It's a part of the Dispatcher's design pattern. * Demultiplexer gets Events from HALsensoric, interprets them and send a message to dispatcher * containing exactly what happened in the engine */ #include "Demultiplexer.h" //#define DEBUG_ Mutex Demultiplexer::demultiplexer_mutex_ = Mutex(); Demultiplexer *Demultiplexer::demultiplexer_instance_ = NULL; /** * Call init ro do some initialization work */ Demultiplexer::Demultiplexer() { #ifdef DEBUG_ cout << "Demultiplexer created" << endl; #endif init(); } /**
void Nullcline::ComputeData() { #ifdef DEBUG_FUNC ScopeTracker st("Nullcline::ComputeData", std::this_thread::get_id()); #endif while (DrawState()==DRAWING) { if (!NeedNewStep() && !NeedRecompute()) goto label;{ const int xidx = Spec_toi("xidx"), yidx = Spec_toi("yidx"), resolution = Spec_toi("resolution")*2, resolution2 = resolution*resolution; InitParserMgrs(resolution2); const double xmin = _modelMgr->Minimum(ds::INIT, xidx), xmax = _modelMgr->Maximum(ds::INIT, xidx), ymin = _modelMgr->Minimum(ds::INIT, yidx), ymax = _modelMgr->Maximum(ds::INIT, yidx); const double xinc = (xmax - xmin) / (double)(resolution-1), yinc = (ymax - ymin) / (double)(resolution-1); Record* record = new Record(resolution2); double* x = record->x, * y = record->y, * xdiff = new double[resolution2], * ydiff = new double[resolution2]; try { std::lock_guard<std::mutex> lock( Mutex() ); RecomputeIfNeeded(); for (int i=0; i<resolution; ++i) for (int j=0; j<resolution; ++j) { const double xij = i*xinc + xmin, yij = j*yinc + ymin; const int idx = i*resolution+j; ParserMgr& parser_mgr = GetParserMgr(idx); const double* diffs = parser_mgr.ConstData(ds::DIFF); parser_mgr.SetData(ds::DIFF, xidx, xij); parser_mgr.SetData(ds::DIFF, yidx, yij); parser_mgr.ParserEval(false); xdiff[idx] = diffs[xidx] - xij; ydiff[idx] = diffs[yidx] - yij; x[idx] = xij; y[idx] = yij; } double lastx, lasty; std::vector< std::pair<int,int> >& xcross_h = record->xcross_h, & xcross_v = record->xcross_v, & ycross_h = record->ycross_h, & ycross_v = record->ycross_v; std::unordered_set<int> xidx_set, yidx_set; //To avoid duplicates; //The grid is being searched *column-wise* for (int j=0; j<resolution; ++j) { lastx = xdiff[j]; lasty = ydiff[j]; for (int i=0; i<resolution; ++i) { const int idx = i*resolution+j; if (ds::sgn(lastx) != ds::sgn(xdiff[idx])) { xcross_v.push_back( std::make_pair(i,j) ); xidx_set.insert(idx); } lastx = xdiff[idx]; if (ds::sgn(lasty) != ds::sgn(ydiff[idx])) { ycross_v.push_back( std::make_pair(i,j) ); yidx_set.insert(idx); } lasty = ydiff[idx]; } } //Switch indices so as to search row-wise for (int i=0; i<resolution; ++i) { lastx = xdiff[i*resolution]; lasty = ydiff[i*resolution]; for (int j=0; j<resolution; ++j) { const int idx = i*resolution+j; if (ds::sgn(lastx) != ds::sgn(xdiff[idx]) && xidx_set.count(idx)==0) xcross_h.push_back( std::make_pair(i,j) ); lastx = xdiff[idx]; if (ds::sgn(lasty) != ds::sgn(ydiff[idx]) && yidx_set.count(idx)==0) ycross_h.push_back( std::make_pair(i,j) ); lasty = ydiff[idx]; } } _packets.push_back(record); } catch (std::exception& e) { _log->AddExcept("Nullcline::ComputeData: " + std::string(e.what())); throw (e); } delete[] xdiff; delete[] ydiff; emit ComputeComplete(1); }label: std::this_thread::sleep_for( std::chrono::milliseconds(RemainingSleepMs()) ); } if (DeleteOnFinish()) emit ReadyToDelete(); }
void Nullcline::MakePlotItems() { #ifdef DEBUG_FUNC ScopeTracker st("Nullcline::MakePlotItems", std::this_thread::get_id()); #endif std::unique_lock<std::mutex> lock( Mutex() ); if (_packets.empty()) return; while (_packets.size()>1) { delete _packets.front(); _packets.pop_front(); } Record* record = _packets.front(); _packets.pop_front(); if (!record) return; lock.unlock(); ClearPlotItems(); const size_t xidx = Spec_toi("xidx"), yidx = Spec_toi("yidx"), resolution2 = NumParserMgrs(), resolution = (int)sqrt(resolution2); const std::vector< std::pair<int,int> >& xcross_h = record->xcross_h, & xcross_v = record->xcross_v, & ycross_h = record->ycross_h, & ycross_v = record->ycross_v; const double* x = record->x, * y = record->y; const double xinc = record->xinc, yinc = record->yinc; const size_t xnum_pts_h = xcross_h.size(), xnum_pts_v = xcross_v.size(), ynum_pts_h = ycross_h.size(), ynum_pts_v = ycross_v.size(); ReservePlotItems(xnum_pts_h + xnum_pts_v + ynum_pts_h + ynum_pts_v); const QColor& xcolor = _colors.at(xidx+1); for (size_t i=0; i<xnum_pts_h; ++i) { QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush(xcolor), QPen(xcolor, 2), QSize(5, 5) ); QwtPlotMarker* marker = new QwtPlotMarker(); marker->setSymbol(symbol); const int idx = xcross_h.at(i).first*resolution + xcross_h.at(i).second; marker->setXValue(x[idx] + xinc/2.0); marker->setYValue(y[idx]); marker->setZ(-1); AddPlotItem(marker); } for (size_t i=0; i<xnum_pts_v; ++i) { QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush(xcolor), QPen(xcolor, 2), QSize(5, 5) ); QwtPlotMarker* marker = new QwtPlotMarker(); marker->setSymbol(symbol); const int idx = xcross_v.at(i).first*resolution + xcross_v.at(i).second; marker->setXValue(x[idx]); marker->setYValue(y[idx] + yinc/2.0); marker->setZ(-1); AddPlotItem(marker); } QColor ycolor = _colors.at(yidx+1); for (size_t i=0; i<ynum_pts_h; ++i) { QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush(ycolor), QPen(ycolor, 2), QSize(5, 5) ); QwtPlotMarker* marker = new QwtPlotMarker(); marker->setSymbol(symbol); const int idx = ycross_h.at(i).first*resolution + ycross_h.at(i).second; marker->setXValue(x[idx] + xinc/2.0); marker->setYValue(y[idx]); marker->setZ(-1); AddPlotItem(marker); } for (size_t i=0; i<ynum_pts_v; ++i) { QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush(ycolor), QPen(ycolor, 2), QSize(5, 5) ); QwtPlotMarker* marker = new QwtPlotMarker(); marker->setSymbol(symbol); const int idx = ycross_v.at(i).first*resolution + ycross_v.at(i).second; marker->setXValue(x[idx]); marker->setYValue(y[idx] + yinc/2.0); marker->setZ(-1); AddPlotItem(marker); } DrawBase::Initialize(); //Have to wait on this, since we don't know how many objects there //are until the analysis is complete delete record; }
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <compiler.h> #include <debug.h> #include <event.h> #include <io.h> #include <algorithm> #include <sstream> #include <string> Mutex IO::Block::mutex = Mutex(Mutex::RECURSIVE); IO::Block::Block(std::string n,IO::channel_t *channel,size_t size):name(n) { for (size_t i=0; i<inputs.size(); ++i) while (inputs[i].links.size()) disconnect(inputs[i].links.front().block,inputs[i].links.front().channel,this,i); for (size_t i=0; i<outputs.size(); ++i) while (outputs[i].links.size()) disconnect(this,i,outputs[i].links.front().block,outputs[i].links.front().channel); int num_inputs = 0, num_outputs = 0; for (size_t i = 0; i < size; ++i) if (channel[i].flags & INPUT) num_inputs++; else if (channel[i].flags & OUTPUT)
ConsumerAndProductor::ConsumerAndProductor() :mutex_(Mutex()), cond_(Condition(mutex_)), consumer_(NULL), productor_(NULL) {}