示例#1
0
	void PrintAllocations( )
	{
		GetLock( ).lock( );
#ifdef DEBUG_MEMORY
		Header* header = GetBottom( )->Next;

		std::string str = "\n";
		while ( header )
		{
			if ( !header->Free )
				str += "\tMEMORY LEAK\t\t" + std::string( header->File ) + ":" + std::to_string( header->Line ) + "\t\t" + std::to_string( header->Size ) + "\n";

			header = header->Next;
		}
		header = GetTop( )->Next;
		while ( header )
		{
			if ( !header->Free )
				str += "\tMEMORY LEAK\t\t" + std::string( header->File ) + ":" + std::to_string( header->Line ) + "\t\t" + std::to_string( header->Size ) + "\n";

			header = header->Next;
		}
		str += "\n";
#if PLATFORM == PLATFORM_WINDOWS
		OutputDebugStringA( str.c_str( ) );
#else
		printf( "%s", str.c_str( ) );
#endif
#endif
		GetLock( ).unlock( );
	}
示例#2
0
XnStatus XnSensorDepthStream::SetMirror(XnBool bIsMirrored)
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnOSEnterCriticalSection(GetLock());

	// set firmware mirror
	XnBool bFirmwareMirror = (bIsMirrored == TRUE && m_Helper.GetFirmwareVersion() >= XN_SENSOR_FW_VER_5_0);

	nRetVal = m_Helper.SimpleSetFirmwareParam(m_FirmwareMirror, (XnUInt16)bFirmwareMirror);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSLeaveCriticalSection(GetLock());
		return (nRetVal);
	}

	// update prop
	nRetVal = XnDepthStream::SetMirror(bIsMirrored);

	xnOSLeaveCriticalSection(GetLock());
	XN_IS_STATUS_OK(nRetVal);

	if (m_depthUtilsHandle != NULL)
	{
		nRetVal = DepthUtilsSetDepthConfiguration(m_depthUtilsHandle, GetXRes(), GetYRes(), GetOutputFormat(), IsMirrored());
		XN_IS_STATUS_OK(nRetVal);
	}

	return (XN_STATUS_OK);
}
static BOOL Intercept(THREADID tid, DEBUGGING_EVENT eventType, CONTEXT *ctxt, VOID *)
{
    if (eventType == DEBUGGING_EVENT_BREAKPOINT)
    {
        // When the child thread reaches the breakpoint in Breakpoint(), wait for the main
        // thread to reach the One() function.  If the main thread is not there yet, squash the
        // breakpoint and move the PC back to the start of the Breakpoint() function.  This will
        // delay a while and then re-trigger the breakpoint.
        //
        ADDRINT pc = PIN_GetContextReg(ctxt, REG_INST_PTR);
        if (pc == BreakpointLocation && !AllowBreakpoint)
        {
            PIN_SetContextReg(ctxt, REG_INST_PTR, BreakpointFunction);
            GetLock(&Lock, 1);
            std::cout << "Squashing breakpoint at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
            ReleaseLock(&Lock);
            return FALSE;
        }

        GetLock(&Lock, 1);
        std::cout << "Stopping at breakpoint at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
        ReleaseLock(&Lock);
        return TRUE;
    }

    if (eventType == DEBUGGING_EVENT_ASYNC_BREAK)
    {
        // When the child thread triggers the breakpoint, we should be at the One() function.
        // Change the PC to the Two() function, which is the point of this test.  We want to
        // make sure Pin properly handles the change of PC in this case.
        //
        ADDRINT pc = PIN_GetContextReg(ctxt, REG_INST_PTR);
        if (pc == OneFunction)
        {
            PIN_SetContextReg(ctxt, REG_INST_PTR, TwoFunction);
            GetLock(&Lock, 1);
            std::cout << "Changing ASYNC BREAK PC to Two() on thread " << std::dec << tid << std::endl;
            ReleaseLock(&Lock);
            return TRUE;
        }

        // If the PC is not at the One() function, the child thread has probably hit some breakpoint
        // other than the one at Breakpoint().  (E.g. an internal breakpoint set by GDB.)  Don't
        // change the PC in such a case.
        //
        GetLock(&Lock, 1);
        std::cout << "ASYNC_BREAK at 0x" << std::hex << pc << " on thread " << std::dec << tid << std::endl;
        ReleaseLock(&Lock);
        return TRUE;
    }

    GetLock(&Lock, 1);
    std::cout << "FAILURE: Unexpected debugging event type" << std::endl;
    ReleaseLock(&Lock);
    std::exit(1);
}
示例#4
0
int add_or_update_alarm(uint8_t hour, uint8_t min, uint8_t mode,
                         uint8_t repeat_factor, char *name)
{
    pthread_mutex_t *bucket_mtx = GetLock(hour, min);
    pthread_mutex_lock(bucket_mtx);
    AlarmClockInfo *header = GetHeader(hour, min);
    AlarmClockInfo *temp = header;
    // Check whether an existing entry should be updated
    while (temp)
    {
        if (temp->hour == hour && temp->min == min)
        {
            temp->mode = mode;
            temp->repeat_factor = repeat_factor;
            strcpy(temp->name, name);
            pthread_mutex_unlock(bucket_mtx);
            return 0;
        }
        temp = temp->next;
    }
    // A new entry is inserted
    AlarmClockInfo *naci = CreateNewInfo(hour,min,mode,repeat_factor,name);
    naci->next = header;
    *AC_TABLE_ENTRY(hour,min) = naci;
    pthread_mutex_unlock(bucket_mtx);
    return 1;
}
示例#5
0
// Return 1 if found and removed, otherwise return 0
int cancel_alarm(uint8_t hour, uint8_t min, int play)
{
    pthread_mutex_t *bucket_mtx = GetLock(hour, min);
    pthread_mutex_lock(bucket_mtx);
    AlarmClockInfo *cand = GetHeader(hour, min);
    AlarmClockInfo *prev = NULL;
    while (cand)
    {
        if (cand->hour == hour && cand->min == min)
        {
            // Optionally, play the alarm here before essentially removing it
            // ...
    
            if (play)
                ; // sound an alarm
            if (!prev) *AC_TABLE_ENTRY(hour, min) = cand->next;
            else prev->next = cand->next;
            free(cand);
            pthread_mutex_unlock(bucket_mtx);
            return 1;
        }
        prev = cand;
        cand = cand->next;
    }
    pthread_mutex_unlock(bucket_mtx);
    return 0;
}
示例#6
0
//-----------------------------------------
// функция логирует события мыши
//-----------------------------------------
bool TKeyLogger::LogMouse(HWND Wnd, int X, int Y, int Button)
{
	//------  блокируем код --------
	TLock L = GetLock();
	//------------------------------
	return true;
}
示例#7
0
void AccountMgr::ClearPlayerDataCache(ObjectGuid guid)
{
    if (!guid || !guid.IsPlayer())
        return;

    PlayerDataCache const* cache = GetPlayerDataCache(guid, false);

    if (cache)
    {
        uint32 accId = cache->account;

        WriteGuard Guard(GetLock());
        PlayerDataCacheMap::iterator itr = mPlayerDataCacheMap.find(guid);
        if (itr != mPlayerDataCacheMap.end())
            mPlayerDataCacheMap.erase(itr);

        RafLinkedMap::iterator itr1 = mRAFLinkedMap.find(std::pair<uint32,bool>(accId, true));
        if (itr1 != mRAFLinkedMap.end())
            mRAFLinkedMap.erase(itr1);
        itr1 = mRAFLinkedMap.find(std::pair<uint32,bool>(accId, false));
        if (itr1 != mRAFLinkedMap.end())
            mRAFLinkedMap.erase(itr1);
    }

}
示例#8
0
RafLinkedList* AccountMgr::GetRAFAccounts(uint32 accid, bool referred)
{

    RafLinkedMap::iterator itr = mRAFLinkedMap.find(std::pair<uint32,bool>(accid, referred));
    if (itr == mRAFLinkedMap.end())
    {
        QueryResult* result;

        if (referred)
            result = LoginDatabase.PQuery("SELECT `friend_id` FROM `account_friends` WHERE `id` = %u AND `expire_date` > NOW() LIMIT %u", accid, sWorld.getConfig(CONFIG_UINT32_RAF_MAXREFERERS));
        else
            result = LoginDatabase.PQuery("SELECT `id` FROM `account_friends` WHERE `friend_id` = %u AND `expire_date` > NOW() LIMIT %u", accid, sWorld.getConfig(CONFIG_UINT32_RAF_MAXREFERALS));

        RafLinkedList acclist;

        if (result)
        {
            do
            {
                Field* fields = result->Fetch();
                uint32 refaccid = fields[0].GetUInt32();
                acclist.push_back(refaccid);
            }
            while (result->NextRow());
            delete result;
        }
        ReadGuard Guard(GetLock());
        mRAFLinkedMap.insert(RafLinkedMap::value_type(std::pair<uint32,bool>(accid, referred), acclist));
        itr = mRAFLinkedMap.find(std::pair<uint32,bool>(accid, referred));
    }

    return &itr->second;
}
示例#9
0
// This routine is executed each time malloc is called.
VOID BeforeMalloc( int size, THREADID threadid )
{
    GetLock(&lock, threadid+1);
    fprintf(out, "thread %d entered malloc(%d)\n", threadid, size);
    fflush(out);
    ReleaseLock(&lock);
}
示例#10
0
int main(int argc, char **argv)
{
   if(InitLocks("qlite", "sapc13", 5468))
   {
      if(GetLock(1, 5)==0)
         printf("Got lock!\n");
      else
         printf("Lock denied!\n");

/*
      if(GetLock(1, 5)==0)
         printf("Got lock!\n");
      else
         printf("Lock denied!\n");

      if(ReleaseLock(1))
         printf("Lock released!\n");
      else
         printf("Couldn't release lock!\n");

      if(GetLock(1, 5)==0)
         printf("Got lock!\n");
      else
         printf("Lock denied!\n");

      if(ReleaseLock(2))
         printf("Lock released!\n");
      else
         printf("Couldn't release lock!\n");
*/
   }

   return(0);
}
示例#11
0
// Note that opening a file in a callback is only supported on Linux systems.
// See buffer-win.cpp for how to work around this issue on Windows.
//
// This routine is executed every time a thread is created.
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    GetLock(&lock, threadid+1);
    fprintf(out, "thread begin %d\n",threadid);
    fflush(out);
    ReleaseLock(&lock);
}
示例#12
0
T* HashMapHolder<T>::Find(ObjectGuid guid)
{
    boost::shared_lock<boost::shared_mutex> lock(*GetLock());

    typename MapType::iterator itr = GetContainer().find(guid);
    return (itr != GetContainer().end()) ? itr->second : NULL;
}
示例#13
0
int
C_File::AddLock( LockStruct *ls, BOOL bWait )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	LockStruct *lsAux = GetLock( ls );
	if( lsAux ){
		lsAux->iCount++;
		if( ls ){
			delete ls;
		}
		return( OK );
	} else {
		if( !IsLocked( ls, TRUE ) ){
			ls->iCount++;
			if( _LockTable [ iLine ]->Add( ls, TAIL ) == OK ){
				if( RealLock( ls, bWait ) == OK ){
					return( OK );
				} else {
					_LockTable [ iLine ]->Refresh( NULL );
					_LockTable [ iLine ]->Del();
				}
			}
		}
	}
	return( !OK );
}
示例#14
0
void OPFResource::AddSigilVersionMeta()
{
    QWriteLocker locker(&GetLock());
    QString source = CleanSource::ProcessXML(GetText(),"application/oebps-package+xml");
    OPFParser p;
    p.parse(source);
    for (int i=0; i < p.m_metadata.count(); ++i) {
        MetaEntry me = p.m_metadata.at(i);
        if ((me.m_name == "meta") && (me.m_atts.contains("name"))) {  
            QString name = me.m_atts[QString("name")];
            if (name == SIGIL_VERSION_META_NAME) {
                me.m_atts["content"] = QString(SIGIL_VERSION);
                p.m_metadata.replace(i, me);
                UpdateText(p);
                return;
            }
        }
    }
    MetaEntry me;
    me.m_name = "meta";
    me.m_atts[QString("name")] = QString("Sigil version");
    me.m_atts[QString("content")] = QString(SIGIL_VERSION);
    p.m_metadata.append(me);
    UpdateText(p);
}
示例#15
0
VOID  Image(IMG img, VOID *v){
        char    szFilePath[260];
        unsigned long index;
        
        GetLock(&lock, 1);
        if (process_start != 0){
                ReleaseLock(&lock);
                return;
        }
        if (IMG_Valid(img)){
                memset(szFilePath, 0, sizeof(szFilePath));
                strncpy(szFilePath, IMG_Name(img).c_str(), sizeof(szFilePath)-1);
                index = 0;
                while (szFilePath[index] != 0){
                        szFilePath[index] = tolower(szFilePath[index]);
                        index++;
                }
                
                if (strstr(szFilePath, KnobProcessToTrace.Value().c_str())){
                        process_start = IMG_LowAddress(img);
                        process_end   = IMG_HighAddress(img);
                }
        }
        ReleaseLock(&lock);
        
}
示例#16
0
/*!
 * Print out analysis results.
 * This function is called when the application exits.
 * @param[in]   code            exit code of the application
 * @param[in]   v               value specified by the tool in the 
 *                              PIN_AddFiniFunction function call
 */
VOID Fini(INT32 code, VOID *v)
{
    GetLock(&fileLock, 1);
    fclose(outfile);
    printf("outfile closed\n");
    ReleaseLock(&fileLock);
}
示例#17
0
// This routine is executed every time a thread is destroyed.
VOID ThreadFini(THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v)
{
    GetLock(&lock, threadid+1);
    fprintf(out, "thread end %d code %d\n",threadid, code);
    fflush(out);
    ReleaseLock(&lock);
}
示例#18
0
// call this method only
void TerrainInfo::CleanUpGrids(uint32 const diff)
{
    for (int y = 0; y < MAX_NUMBER_OF_GRIDS; ++y)
    {
        for (int x = 0; x < MAX_NUMBER_OF_GRIDS; ++x)
        {
            // delete those GridMap objects which have refcount == 0
            if (m_GridMaps[x][y] && m_GridMaps[x][y].count() == 0)
            {
                DEBUG_FILTER_LOG(LOG_FILTER_MAP_LOADING,"TerrainInfo::CleanUpGrids unload grid map:%u x:%d y:%d", GetMapId(), x, y);
                WriteGuard Guard(GetLock(), true);

                GridMapPtr tmpPtr = m_GridMaps[x][y];
                m_GridMaps[x][y] = GridMapPtr();

                // unload VMAPS...
                VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(m_mapId, x, y);

                // unload mmap...
                MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(m_mapId, x, y);

                // tmpPtr be auto-erased after cycle end
            }
        }
    }
}
示例#19
0
void TextResource::InitialLoad()
{
    /**
      * Stuff to know about resource loading...
      *
      * Currently Sigil when opening an ePub creates Resource objects *prior*
      * to actually copying the resources from the zip into the Sigil folders.
      * So in 99% of cases the resource will not exist, so a call to InitialLoad()
      * from the constructor would fail (which it used to do).
      *
      * For some resource types there is a call made afterwards which will result
      * in the resource being loaded such as for HTML files, CSS, NCX and OPF
      * (see UniversalUpdates.cpp and code setting default text for new html pages etc).
      *
      * For other text resource types, they will only get loaded on demand, when
      * the tab is actually opened, TextTab.cpp will call this InitialLoad() function.
      *
      * If you were to write some code to iterate over resources that do not fall
      * into the special cases above, you *must* call InitialLoad() first to ensure
      * the data is loaded, or else it will be blank or have data depending on whether
      * it had been opened in a tab first.
      */
    QWriteLocker locker(&GetLock());
    Q_ASSERT(m_TextDocument);

    if (m_TextDocument->toPlainText().isEmpty() && QFile::exists(GetFullPath())) {
        SetText(Utility::ReadUnicodeTextFile(GetFullPath()));
    }
}
示例#20
0
VOID Error(std::string where, THREADID tid, UINT32 r, ADDRINT expect, ADDRINT val)
{
    GetLock(&Lock, 1);
    Out << "Mismatch " << where << ": tid=" << std::dec << tid << " (G" << r << ")" <<
        ", Expect " << std::hex << expect << ", Got " << std::hex << val << std::endl;
    ReleaseLock(&Lock);
}
示例#21
0
VOID ThreadBegin(UINT32 threadid, VOID * sp, int flags, VOID *v)
{
    GetLock(&lock, threadid+1);
    numThreads++;
    ReleaseLock(&lock);
    
    ASSERT(numThreads <= MaxNumThreads, "Maximum number of threads exceeded\n");
}
示例#22
0
bool OPFResource::CoverImageExists() const
{
    QReadLocker locker(&GetLock());
    QString source = CleanSource::ProcessXML(GetText(),"application/oebps-package+xml");
    OPFParser p;
    p.parse(source);
    return GetCoverMeta(p) > -1;
}
示例#23
0
GridMapPtr TerrainInfo::GetGridMap(uint32 const& x, uint32 const& y)
{
    if (x >= MAX_NUMBER_OF_GRIDS || y >= MAX_NUMBER_OF_GRIDS)
        return GridMapPtr();

    ReadGuard Guard(GetLock(), true);
    return m_GridMaps[x][y];
}
示例#24
0
void EventMgr::SetState(int eventId, LuaEventState state)
{
    Guard guard(GetLock());
    if (!processors.empty())
        for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
            (*it)->SetState(eventId, state);
    globalProcessor->SetState(eventId, state);
}
示例#25
0
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    GetLock(&lock, threadid+1);
    numThreads++;
    ReleaseLock(&lock);
    
    ASSERT(numThreads <= MaxNumThreads, "Maximum number of threads exceeded\n");
}
示例#26
0
void EventMgr::RemoveEvent(int eventId)
{
    ReadGuard lock(GetLock());
    if (!processors.empty())
        for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
            (*it)->RemoveEvent(eventId);
    globalProcessor->RemoveEvent(eventId);
}
示例#27
0
void WorldObjectEventProcessor::Update(uint32 p_time, bool force)
{
    if (force)
        RenewEvents();

    ReadGuard Guard(GetLock());
    EventProcessor::Update(p_time);
}
示例#28
0
/**
 * backend_refresh_cache_thread:
 */
static gboolean
backend_refresh_cache_thread (PkBackend *backend)
{
	pk_backend_set_allow_cancel (backend, true);

	aptcc *m_apt = new aptcc(backend, _cancel);
	pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
	if (m_apt->init()) {
		egg_debug ("Failed to create apt cache");
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
	// Lock the list directory
	FileFd Lock;
	if (_config->FindB("Debug::NoLocking", false) == false)
	{
		Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
		if (_error->PendingError() == true) {
			pk_backend_error_code (backend, PK_ERROR_ENUM_CANNOT_GET_LOCK, "Unable to lock the list directory");
			delete m_apt;
			pk_backend_finished (backend);
			return false;
	// 	 return _error->Error(_("Unable to lock the list directory"));
		}
	}
	// Create the progress
	AcqPackageKitStatus Stat(m_apt, backend, _cancel);

	// do the work
	if (_config->FindB("APT::Get::Download",true) == true) {
		ListUpdate(Stat, *m_apt->packageSourceList);
	}

	// Rebuild the cache.
	pkgCacheFile Cache;
	OpTextProgress Prog(*_config);
	if (Cache.BuildCaches(Prog, true) == false) {
		if (_error->PendingError() == true) {
			show_errors(backend, PK_ERROR_ENUM_CANNOT_GET_LOCK);
		}
		delete m_apt;
		pk_backend_finished (backend);
		return false;
	}

	// missing gpg signature would appear here
	// TODO we need a better enum
	if (_error->PendingError() == false && _error->empty() == false) {
		show_warnings(backend, PK_MESSAGE_ENUM_UNTRUSTED_PACKAGE);
	}

	pk_backend_finished (backend);
	delete m_apt;
	return true;
}
示例#29
0
VOID ThreadFini(THREADID tid, const CONTEXT *ctxt, INT32 code, VOID *v)
{
    // When the thread exits, accumulate the thread's dynamic instruction
    // count into the total.
    //
    GetLock(&Lock, tid+1);
    TotalCount += PIN_GetContextReg(ctxt, ScratchReg);
    ReleaseLock(&Lock);
}
示例#30
0
bool OPFResource::IsCoverImage(const ImageResource *image_resource) const
{
    QReadLocker locker(&GetLock());
    QString source = CleanSource::ProcessXML(GetText(),"application/oebps-package+xml");
    OPFParser p;
    p.parse(source);
    QString resource_id = GetResourceManifestID(image_resource, p);
    return IsCoverImageCheck(resource_id, p);
}