Esempio n. 1
0
void CCopyThread::SyncConfig()
{
	// atomic read
	if(m_bConfigChanged)
	{
		CClipTypes* pTypes = NULL;
		
		ATL::CCritSecLock csLock(m_cs.m_sect);
		
		pTypes = m_LocalConfig.m_pSupportedTypes;
		
		m_LocalConfig = m_SharedConfig;
		
		// NULL means that it shouldn't have been sync'ed
		if( m_SharedConfig.m_pSupportedTypes == NULL )
		{	// let m_LocalConfig keep its types
			m_LocalConfig.m_pSupportedTypes = pTypes; // undo sync
			pTypes = NULL; // nothing to delete
		}
		else
			m_SharedConfig.m_pSupportedTypes = NULL; // now owned by LocalConfig
		
		// delete old types
		if( pTypes )
		{
			delete pTypes;
		}
	}
}
Esempio n. 2
0
void CMainFrmThread::AddClipToSave(CClip *pClip)
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	Log(_T("Adding clip to thread for save to db"));
	m_saveClips.AddTail(pClip);
	FireEvent(SAVE_CLIPS);
}
Esempio n. 3
0
bool CCopyThread::GetAsyncCopy()
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	bool bRet = m_SharedConfig.m_bAsyncCopy;

	return bRet;
}
Esempio n. 4
0
bool CCopyThread::GetCopyOnChange()
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	bool bRet = m_SharedConfig.m_bCopyOnChange;

	return bRet;
}
Esempio n. 5
0
HWND CCopyThread::GetClipHandler()
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	HWND hRet = m_SharedConfig.m_hClipHandler;

	return hRet;
}
Esempio n. 6
0
void VMPI_Stats_SpewHook( const char *pMsg )
{
	CCriticalSectionLock csLock( &g_SpewTextCS );
	csLock.Lock();

		// Queue the text up so we can send it to the DB right away when we connect.
		g_SpewText.AddMultipleToTail( strlen( pMsg ), pMsg );
}
Esempio n. 7
0
void CWorkPool::Add( do_work one )
{
	int nIndex = 0 ;
	{
		boost::mutex::scoped_lock csLock(m_cs);
		nIndex = m_nIndex ++ % m_nCount ;
	}
	m_vThreadPool[ nIndex ] ->AddWork( one ) ;
}
Esempio n. 8
0
bool CCopyThread::SetAsyncCopy(bool bVal)
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	bool bRet = m_SharedConfig.m_bAsyncCopy;
	m_SharedConfig.m_bAsyncCopy = bVal;
	m_bConfigChanged = (bRet != bVal);

	return bRet;
}
Esempio n. 9
0
HWND CCopyThread::SetClipHandler(HWND hWnd)
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	HWND hRet = m_SharedConfig.m_hClipHandler;
	m_SharedConfig.m_hClipHandler = hWnd;
	m_bConfigChanged = (hRet != hWnd);

	return hRet;
}
Esempio n. 10
0
XnStatus LinkContInputStream::Init(LinkControlEndpoint* pLinkControlEndpoint,
                                   XnStreamType streamType,
                                   XnUInt16 nStreamID, 
                                   IConnection* pConnection)
{
	XnStatus nRetVal = XN_STATUS_OK;
	if (m_hCriticalSection == NULL)
	{
		xnLogError(XN_MASK_INPUT_STREAM, "Cannot initialize - critical section was not created successfully");
		XN_ASSERT(FALSE);
		return XN_STATUS_ERROR;
	}

	xnl::AutoCSLocker csLock(m_hCriticalSection);
	if (m_bInitialized)
	{
		//We shutdown first so we can re-initialize.
		Shutdown();
	}

    nRetVal = LinkInputStream::Init(pLinkControlEndpoint, streamType, nStreamID, pConnection);
    XN_IS_STATUS_OK_LOG_ERROR("Init base input stream", nRetVal);

	m_nStreamID = nStreamID;
	m_nUserBufferMaxSize = CONT_STREAM_PREDEFINED_BUFFER_SIZE;
	m_nUserBufferCurrentSize = m_nWorkingBufferCurrentSize = 0;
	//Allocate buffers
	m_pUserBuffer = reinterpret_cast<XnUInt8*>(xnOSCallocAligned(1, m_nUserBufferMaxSize, XN_DEFAULT_MEM_ALIGN));
	if (m_pUserBuffer == NULL)
	{
		Shutdown();
		xnLogError(XN_MASK_INPUT_STREAM, "Failed to allocate buffer of size %u", m_nUserBufferMaxSize);
		XN_ASSERT(FALSE);
		return XN_STATUS_ALLOC_FAILED;
	}
	m_pWorkingBuffer = reinterpret_cast<XnUInt8*>(xnOSCallocAligned(1, CONT_STREAM_PREDEFINED_BUFFER_SIZE, XN_DEFAULT_MEM_ALIGN));
	if (m_pWorkingBuffer == NULL)
	{
		Shutdown();
		xnLogError(XN_MASK_INPUT_STREAM, "Failed to allocate buffer of size %u", m_nUserBufferMaxSize);
		XN_ASSERT(FALSE);
		return XN_STATUS_ALLOC_FAILED;
	}
	
    nRetVal = xnLinkGetStreamDumpName(m_nStreamID, m_strDumpName, sizeof(m_strDumpName));
    if (nRetVal != XN_STATUS_OK)
    {
        xnLogWarning(XN_MASK_INPUT_STREAM, "Failed to get stream dump name: %s", xnGetStatusString(nRetVal));
        XN_ASSERT(FALSE);
    }

    m_bInitialized = TRUE;
	return XN_STATUS_OK;
}
Esempio n. 11
0
void CCopyThread::SetSupportedTypes( CClipTypes* pTypes )
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	if(m_SharedConfig.m_pSupportedTypes)
	{
		delete m_SharedConfig.m_pSupportedTypes;
	}

	m_SharedConfig.m_pSupportedTypes = pTypes;
	m_bConfigChanged = true;
}
Esempio n. 12
0
void CMainFrmThread::OnSaveRemoteClips()
{
	LogSendRecieveInfo("---------Start of OnSaveRemoteClips");

	CClipList *pLocalClips = new CClipList();

	//Save the clips locally
	{
		ATL::CCritSecLock csLock(m_cs.m_sect);

		POSITION pos;
		CClip* pClip;

		pos = m_saveRemoteClips.GetHeadPosition();
		while(pos)
		{
			pClip = m_saveRemoteClips.GetNext(pos);
			pLocalClips->AddTail(pClip);
		}

		//pLocalClips now own, the clips
		m_saveRemoteClips.RemoveAll();
	}

	LogSendRecieveInfo("---------OnSaveRemoteClips - Before AddToDB");

	int count = pLocalClips->AddToDB(true);

	LogSendRecieveInfo("---------OnSaveRemoteClips - After AddToDB");

	//are we supposed to add this clip to the clipboard
	CClip *pLastClip = pLocalClips->GetTail();
	if(pLastClip && pLastClip->m_param1 == TRUE)
	{
		LogSendRecieveInfo("---------OnSaveRemoteClips - Before Posting msg to main thread to set clipboard");

		//set the clipboard on the main thread, i was having a problem with setting the clipboard on a thread
		//guess it needs to be set on the main thread
		//main window will clear this memory
		PostMessage(theApp.m_MainhWnd, WM_LOAD_ClIP_ON_CLIPBOARD, (LPARAM)pLastClip, 0);

		LogSendRecieveInfo("---------OnSaveRemoteClips - After Posting msg to main thread to set clipboard");

		pLocalClips->RemoveTail();
	}

	theApp.RefreshView();

	delete pLocalClips;

	LogSendRecieveInfo("---------End of OnSaveRemoteClips");
}
Esempio n. 13
0
void PerfThread_SendSpewText()
{
	// Send the spew text to the database.
	CCriticalSectionLock csLock( &g_SpewTextCS );
	csLock.Lock();
		
		if ( g_SpewText.Count() > 0 )
		{
			g_SpewText.AddToTail( 0 );
			g_pDB->AddCommandToQueue( new CSQLDBCommand_TextMessage( g_SpewText.Base() ), NULL );
			g_SpewText.RemoveAll();
		}

	csLock.Unlock();
}
SpewRetval_t MySpewFunc( SpewType_t type, char const *pMsg )
{
	CCriticalSectionLock csLock( &g_MsgCS );
	csLock.Lock();

		printf( "%s", pMsg );
		OutputDebugString( pMsg );

	csLock.Unlock();	

	if( type == SPEW_ASSERT )
		return SPEW_DEBUGGER;
	else if( type == SPEW_ERROR )
		return SPEW_ABORT;
	else
		return SPEW_CONTINUE;
}
Esempio n. 15
0
void CMainFrmThread::OnSaveClips()
{
	CClipList *pLocalClips = new CClipList();

	//Save the clips locally
	{
		ATL::CCritSecLock csLock(m_cs.m_sect);

		POSITION pos;
		CClip* pClip;

		pos = m_saveClips.GetHeadPosition();
		while(pos)
		{
			pClip = m_saveClips.GetNext(pos);
			pLocalClips->AddTail(pClip);
		}

		//pLocalClips now own, the clips
		m_saveClips.RemoveAll();
	}

	Log(_T("SaveCopyClips Before AddToDb")); 

	int count = pLocalClips->AddToDB(true);

	Log(StrF(_T("SaveCopyclips After AddToDb, Count: %d"), count));

	if(count > 0)
	{
		int Id = pLocalClips->GetTail()->m_id;

		Log(StrF(_T("SaveCopyclips After AddToDb, Id: %d Before OnCopyCopyCompleted"), Id));

		theApp.OnCopyCompleted(Id, count);

		Log(StrF(_T("SaveCopyclips After AddToDb, Id: %d After OnCopyCopyCompleted"), Id));
	
		if(g_Opt.m_lAutoSendClientCount > 0)
		{
			m_sendToClientThread.FireSendToClient(pLocalClips);
		}
	}

	delete pLocalClips;
}
Esempio n. 16
0
void CMainFrmThread::AddRemoteClipToSave(CClipList *pClipList)
{
	ATL::CCritSecLock csLock(m_cs.m_sect);

	Log(_T("Adding REMOTE clip to thread for save to db"));
	
	POSITION pos = pClipList->GetHeadPosition();
	while(pos)
	{
		CClip *pClip = pClipList->GetNext(pos);
		m_saveRemoteClips.AddTail(pClip);
	}

	//local cliplist now owns the clip memory
	pClipList->RemoveAll();
	
	FireEvent(SAVE_REMOTE_CLIPS);
}
Esempio n. 17
0
XnStatus LinkContInputStream::UpdateData()
{
	xnl::AutoCSLocker csLock(m_hCriticalSection);
	if (!m_bInitialized)
	{
		xnLogError(XN_MASK_INPUT_STREAM, "Attempted to update data from stream %u which is not initialized", m_nStreamID);
		XN_ASSERT(FALSE);
		return XN_STATUS_NOT_INIT;
	}

	if (m_bNewDataAvailable)
	{
		//Copy working buffer to user buffer
		xnOSMemCopy(m_pUserBuffer, m_pWorkingBuffer, m_nUserBufferMaxSize);
		m_nUserBufferCurrentSize = m_nWorkingBufferCurrentSize;
		m_bNewDataAvailable = FALSE;
	}

	return XN_STATUS_OK;
}
Esempio n. 18
0
XnStatus LinkContInputStream::HandlePacket(const LinkPacketHeader& header, const XnUInt8* pData, XnBool& bPacketLoss)
{
	XnStatus nRetVal = XN_STATUS_OK;
	xnl::AutoCSLocker csLock(m_hCriticalSection);
	if (!m_bInitialized)
	{
		return XN_STATUS_NOT_INIT;
	}

	// TODO: handle packet loss!
	bPacketLoss = FALSE;

	if(m_streamType == XN_LINK_STREAM_TYPE_LOG)
	{
		// begin parsing frame
		nRetVal = m_logParser.BeginParsing(m_pWorkingBuffer, CONT_STREAM_PREDEFINED_BUFFER_SIZE);
		XN_IS_STATUS_OK_LOG_ERROR("Begin parsing link log msg", nRetVal);

		nRetVal = m_logParser.ParsePacket(header, pData);

		if (nRetVal != XN_STATUS_OK)
			XN_IS_STATUS_OK_LOG_ERROR("Parse data from stream", nRetVal);
	}
	
	//Write new data to dump (if it's on)
	xnDumpFileWriteBuffer(m_pDumpFile, 
		reinterpret_cast<const XnUInt8*>(m_logParser.GetParsedData()), 
		m_logParser.GetParsedSize());

	if (header.GetFragmentationFlags() & XN_LINK_FRAG_END)
	{
		//Notify that we have new data available
		m_bNewDataAvailable = TRUE;
		nRetVal = m_newDataAvailableEvent.Raise();
		XN_IS_STATUS_OK_LOG_ERROR("Raise new data available event", nRetVal);
	}

	return XN_STATUS_OK;
}
void VMPI_WorkerThread( int iThread, void *pUserData )
{
    CDSInfo *pInfo = (CDSInfo*)pUserData;
    CWorkerInfo *pWorkerInfo = &pInfo->m_WorkerInfo;


    // Get our index for running work units
    uint64 idxRunningWorkUnit = (uint64) iThread;
    {
        CCriticalSectionLock csLock( &pWorkerInfo->m_WorkUnitsRunningCS );
        csLock.Lock();
        pWorkerInfo->m_WorkUnitsRunning.ExpandWindow( idxRunningWorkUnit, ~0ull );
        csLock.Unlock();
    }


    MessageBuffer mb;
    PrepareDistributeWorkHeader( &mb, DW_SUBPACKETID_WU_RESULTS );

    MessageBuffer mbStartedWorkUnit;	// Special messagebuffer used to tell the master when we started a work unit.

    while ( g_iMasterFinishedDistributeWorkCall < g_iCurDSInfo && !g_bVMPIEarlyExit )
    {
        WUIndexType iWU;

        // Quit out when there are no more work units.
        if ( !g_pCurDistributorWorker->GetNextWorkUnit( &iWU ) )
        {
            // Wait until there are some WUs to do. This should probably use event handles.
            VMPI_Sleep( 10 );
            continue;
        }

        CCriticalSectionLock csLock( &pWorkerInfo->m_WorkUnitsRunningCS );
        csLock.Lock();

        // Check if this WU is not running
        WUIndexType const *pBegin = &pWorkerInfo->m_WorkUnitsRunning.Get( 0ull ), *pEnd = pBegin + pWorkerInfo->m_WorkUnitsRunning.PastVisibleIndex();
        WUIndexType const *pRunningWu = GenericFind( pBegin, pEnd, iWU );
        if ( pRunningWu != pEnd )
            continue;

        // We are running it
        pWorkerInfo->m_WorkUnitsRunning.Get( idxRunningWorkUnit ) = iWU;

        csLock.Unlock();


        // Process this WU and send the results to the master.
        mb.setLen( 4 );
        mb.write( &iWU, sizeof( iWU ) );

        // Set the current WU for the stats database.
        if ( iThread >= 0 && iThread < 4 )
        {
            g_ThreadWUs[iThread] = iWU;
        }

        // Tell the master we're starting on this WU.
        TellMasterThatWorkerStartedAWorkUnit( mbStartedWorkUnit, pInfo, iWU );


        pWorkerInfo->m_pProcessFn( iThread, iWU, &mb );
        g_pCurDistributorWorker->NoteLocalWorkUnitCompleted( iWU );

        VMPI_SendData( mb.data, mb.getLen(), VMPI_MASTER_ID, /*k_eVMPISendFlags_GroupPackets*/0 );

        // Flush grouped packets every once in a while.
        //VMPI_FlushGroupedPackets( 1000 );
    }

    if ( g_iVMPIVerboseLevel >= 1 )
        Msg( "Worker thread exiting.\n" );
}
Esempio n. 20
0
void CQPasteWndThread::OnLoadItems(void *param)
{
    CQPasteWnd *pasteWnd = (CQPasteWnd*)param;

    ResetEvent(m_SearchingEvent);

	while(true)
	{
		long startTick = GetTickCount();
	    int loadItemsIndex = 0;
	    int loadItemsCount = 0;
	    int loadCount = 0;
	    CString localSql;
	    bool clearFirstLoadItem = false;
		bool firstLoad = false;

		{
			ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

		    if(pasteWnd->m_loadItems.size() > 0)
		    {
				firstLoad = (pasteWnd->m_loadItems.begin()->x == -1);
		        loadItemsIndex = max(pasteWnd->m_loadItems.begin()->x, 0);
		        loadItemsCount = pasteWnd->m_loadItems.begin()->y - pasteWnd->m_loadItems.begin()->x;
		        localSql = pasteWnd->m_SQL;
		        pasteWnd->m_bStopQuery = false;
		        clearFirstLoadItem = true;
		    }
		}

	    if(clearFirstLoadItem)
	    {
			try
			{
				Log(StrF(_T("Load Items start = %d, count = %d"), loadItemsIndex, loadItemsCount));

				CString limit;
				limit.Format(_T(" LIMIT %d OFFSET %d"), loadItemsCount, loadItemsIndex);
				localSql += limit;

				CMainTable table;

				CppSQLite3Query q = theApp.m_db.execQuery(localSql);
				while(!q.eof())
				{
					pasteWnd->FillMainTable(table, q);

					{
						ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

						pasteWnd->m_listItems.push_back(table);
					}

					if(pasteWnd->m_bStopQuery)
					{
						Log(StrF(_T("StopQuery called exiting filling cache count = %d"), loadItemsIndex));
						break;
					}

					q.nextRow();

					if(firstLoad == false)
					{
	            		::PostMessage(pasteWnd->m_hWnd, NM_REFRESH_ROW, table.m_lID, loadItemsIndex);
					}

					loadItemsIndex++;
					loadCount++;
				}

				if(firstLoad)
				{
					::PostMessage(pasteWnd->m_hWnd, NM_REFRESH_ROW, -2, 0);
					//allow the next thread message to process, this should be the message to set the list count

					OnSetListCount(param);
					OnLoadAccelerators(param);
				}
				else
				{
					::PostMessage(pasteWnd->m_hWnd, NM_REFRESH_ROW, -1, 0);
				}

				if(clearFirstLoadItem)
				{
					ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

					pasteWnd->m_loadItems.erase(pasteWnd->m_loadItems.begin());
				}

				Log(StrF(_T("Load items End count = %d, time = %d"), loadCount, GetTickCount() - startTick));
			}
			catch (CppSQLite3Exception& e)	\
			{								\
				Log(StrF(_T("ONLoadItems - SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage()));	\
				ASSERT(FALSE);				\
				break;
			}	
		}
		else
		{
			break;
		}
	}

    SetEvent(m_SearchingEvent);
}
Esempio n. 21
0
void CQPasteWndThread::OnLoadExtraData(void *param)
{
    ResetEvent(m_SearchingEvent);

    CQPasteWnd *pasteWnd = (CQPasteWnd*)param;

    Log(_T("Start of load extra data, Bitmaps/rtf"));

    std::list<CClipFormatQListCtrl> localFormats;
	{
		ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

		for (std::list<CClipFormatQListCtrl>::iterator it = pasteWnd->m_ExtraDataLoadItems.begin(); it != pasteWnd->m_ExtraDataLoadItems.end(); it++)
		{
			localFormats.push_back(*it);
		}
	    pasteWnd->m_ExtraDataLoadItems.clear();
	}

	for (std::list<CClipFormatQListCtrl>::iterator it = localFormats.begin(); it != localFormats.end(); it++)
    {
        if(theApp.GetClipData(it->m_dbId, *it))
        {
            Log(StrF(_T("Loaded, extra data for clip %d, type: %d"), it->m_dbId, it->m_cfType));

			ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

            if(it->m_cfType == CF_DIB)
            {
                pasteWnd->m_cf_dibCache[it->m_dbId] = *it;
                //the cache now owns the format data, set it to delete the data in the destructor
                pasteWnd->m_cf_dibCache[it->m_dbId].m_autoDeleteData = true;
            }
            else if(it->m_cfType == theApp.m_RTFFormat)
            {
                pasteWnd->m_cf_rtfCache[it->m_dbId] = *it;
                //the cache now owns the format data, set it to delete the data in the destructor
                pasteWnd->m_cf_rtfCache[it->m_dbId].m_autoDeleteData = true;
            }

            ::PostMessage(pasteWnd->m_hWnd, NM_REFRESH_ROW, it->m_dbId, it->m_clipRow);
        }
        else
        {
			ATL::CCritSecLock csLock(pasteWnd->m_CritSection.m_sect);

            if(it->m_cfType == CF_DIB)
            {
                CClipFormatQListCtrl localFormat;
                pasteWnd->m_cf_dibCache[it->m_dbId] = *it;
            }
            else if(it->m_cfType == theApp.m_RTFFormat)
            {
                CClipFormatQListCtrl localFormat;
                pasteWnd->m_cf_rtfCache[it->m_dbId] = *it;
            }
        }
    }

    SetEvent(m_SearchingEvent);
    Log(_T("End of load extra data, Bitmaps/rtf"));
}