Beispiel #1
0
VOID GetAnswerToRequest(const TSVNCacheRequest* pRequest, TSVNCacheResponse* pReply, DWORD* pResponseLength)
{
    CTSVNPath path;
    *pResponseLength = 0;
    if(pRequest->flags & TSVNCACHE_FLAGS_FOLDERISKNOWN)
    {
        path.SetFromWin(pRequest->path, !!(pRequest->flags & TSVNCACHE_FLAGS_ISFOLDER));
    }
    else
    {
        path.SetFromWin(pRequest->path);
    }

    CAutoReadWeakLock readLock(CSVNStatusCache::Instance().GetGuard(), 2000);

    if (readLock.IsAcquired())
    {
        CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": app asked for status of %s\n", pRequest->path);
        CSVNStatusCache::Instance().GetStatusForPath(path, pRequest->flags, false).BuildCacheResponse(*pReply, *pResponseLength);
    }
    else
    {
        CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": timeout for asked status of %s\n", pRequest->path);
        CStatusCacheEntry entry;
        entry.BuildCacheResponse(*pReply, *pResponseLength);
    }
}
/*
 * Check for LameXP "portable" mode
 */
bool lamexp_portable_mode(void)
{
	QReadLocker readLock(&g_lamexp_portable.lock);

	if(g_lamexp_portable.bInitialized)
	{
		return g_lamexp_portable.bPortableModeEnabled;
	}
	
	readLock.unlock();
	QWriteLocker writeLock(&g_lamexp_portable.lock);

	if(!g_lamexp_portable.bInitialized)
	{
		if(VER_LAMEXP_PORTABLE_EDITION)
		{
			qWarning("LameXP portable edition!\n");
			g_lamexp_portable.bPortableModeEnabled = true;
		}
		else
		{
			QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName();
			int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive);
			int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive);
			g_lamexp_portable.bPortableModeEnabled = (idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2);
		}
		g_lamexp_portable.bInitialized = true;
	}
	
	return g_lamexp_portable.bPortableModeEnabled;
}
Beispiel #3
0
Cache::ApplyResult Cache::applyPolicy( CachePolicy& cachePolicy ) const
{
    ReadLock readLock( mutex_, boost::try_to_lock );
    if( !readLock.owns_lock() )
        return AR_CACHEBUSY;

    if( cacheMap_.empty() || !cachePolicy.willPolicyBeActivated( *this ) )
        return AR_NOTACTIVATED;

    std::vector< CacheObject* > cacheObjectList;
    cacheObjectList.reserve( cacheMap_.size() );

    for( CacheMap::const_iterator it = cacheMap_.begin(); it != cacheMap_.end(); ++it )
    {
        CacheObject* object = it->second.get();
        if( object && object->isValid() && object->isLoaded_() )
        {
            cacheObjectList.push_back( object );
        }
    }

    if( cacheObjectList.empty() )
        return AR_EMPTY;

    std::vector< CacheObject * > modifiedList;
    cachePolicy.apply_( *this, cacheObjectList, modifiedList );

    unloadCacheObjectsWithPolicy_( cachePolicy, modifiedList );
    return AR_ACTIVATED;
}
Beispiel #4
0
 FilterFactoryPtr FilterService::getFilterFactoryPtr(int filterId)
 {
     ReadLock readLock(mFilterFactoryMapMutex);
     return mFilterFactoryMap.find(filterId) == mFilterFactoryMap.end() ?
         FilterFactoryPtr() :
         mFilterFactoryMap[filterId];
 }
Beispiel #5
0
		void do_all(boost::function<void(plugin_type)> fun) {
			boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5));
			if (!has_valid_lock_log(readLock, "plugins_list::list"))
				return;
			BOOST_FOREACH(const plugin_type p, plugins_) {
				fun(p);
			}
Beispiel #6
0
TransferStats& TransferStats::operator+=(const TransferStats& stats) {
  folly::RWSpinLock::WriteHolder writeLock(mutex_.get());
  folly::RWSpinLock::ReadHolder readLock(stats.mutex_.get());
  headerBytes_ += stats.headerBytes_;
  dataBytes_ += stats.dataBytes_;
  effectiveHeaderBytes_ += stats.effectiveHeaderBytes_;
  effectiveDataBytes_ += stats.effectiveDataBytes_;
  numFiles_ += stats.numFiles_;
  numBlocks_ += stats.numBlocks_;
  failedAttempts_ += stats.failedAttempts_;
  if (stats.errCode_ != OK) {
    if (errCode_ == OK) {
      // First error. Setting this as the error code
      errCode_ = stats.errCode_;
    } else if (stats.errCode_ != errCode_) {
      // Different error than the previous one. Setting error code as generic
      // ERROR
      errCode_ = ERROR;
    }
  }
  if (stats.remoteErrCode_ != OK) {
    if (remoteErrCode_ == OK) {
      remoteErrCode_ = stats.remoteErrCode_;
    } else if (stats.remoteErrCode_ != remoteErrCode_) {
      remoteErrCode_ = ERROR;
    }
  }
  return *this;
}
const TagFmt* EventTagMap::find(uint32_t tag) const {
  std::unordered_map<uint32_t, TagFmt>::const_iterator it;
  android::RWLock::AutoRLock readLock(const_cast<android::RWLock&>(rwlock));
  it = Idx2TagFmt.find(tag);
  if (it == Idx2TagFmt.end()) return NULL;
  return &(it->second);
}
Beispiel #8
0
double HashContainer::getNthTheGreatestValue(unsigned int n)
{
	TimePoint tSearchGrStart = boost::chrono::high_resolution_clock::now();

	double rez = 0;
	unsigned int i = 0;

	ReadLock readLock(valuesLocker);

	ValuesSet::reverse_iterator iter = values.rbegin();

	if(iter != values.rend())
		rez = *iter;

	while(iter != values.rend())
	{
		if(rez != *iter)
			i++;

		rez = *iter;

		if(i == n)
			break;

		iter++;
	}

	TimePoint tSearchGrFinish = boost::chrono::high_resolution_clock::now();
	std::cout << "Search of " << n << "-th the greatest item took " << boost::chrono::duration_cast<boost::chrono::microseconds>(tSearchGrFinish - tSearchGrStart).count() << " microseconds\n";

	return rez;
}
Beispiel #9
0
double HashContainer::get(const string& key, bool withTimeMeasPrintout)
{
	HashContainer::TimePoint tStart;
	if(withTimeMeasPrintout)
		tStart = boost::chrono::high_resolution_clock::now();

	double rez = 0;

	unsigned int hashIndex = hash(key);
	SharedMutex* lock = bucketLocker[hashIndex];
	ReadLock readLock(*lock);
	
	Element* el = bucket[hashIndex];

	if(el)
	{
		if(el->getKey() == key)
		{
			rez = el->getValue();
		}
		else
		{
			rez = recursiveSearch(el, key);
		}
	}


	if(withTimeMeasPrintout)
	{
		HashContainer::TimePoint tFinish = boost::chrono::high_resolution_clock::now();
		std::cout << "Getting el with key = " << key << "; val = " << rez << " took " << boost::chrono::duration_cast<boost::chrono::microseconds>(tFinish - tStart).count() << " microseconds\n";
	}

	return rez;
}
void DataMatrix::_resetFieldStrings() {
  const QMap<QString, QString> meta_strings = dataSource()->matrix().metaStrings(_field);

  QStringList fieldStringKeys = _fieldStrings.keys();
  // remove field strings that no longer need to exist
  readLock();
  for (int i=0; i<fieldStringKeys.count(); i++) {
    QString key = fieldStringKeys.at(i);
    if (!meta_strings.contains(key)) {
      StringPtr sp = _fieldStrings[key];
      _fieldStrings.remove(key);
      sp = 0L;
    }
  }
  // find or insert strings, to set their value
  QMapIterator<QString, QString> it(meta_strings);
  while (it.hasNext()) {
    it.next();
    QString key = it.key();
    StringPtr sp;
    if (!_fieldStrings.contains(key)) { // insert a new one
      _fieldStrings.insert(key, sp = store()->createObject<String>());
      sp->setProvider(this);
      sp->setSlaveName(key);
    } else {  // find it
      sp = _fieldStrings[key];
    }
    sp->setValue(it.value());
  }
  unlock();
}
Beispiel #11
0
double Book::prize(eris_time_t t) const {
    if (t < created_) return 0.0;
    auto lock = readLock();
    auto it = prize_.find(t);
    if (it == prize_.end()) return 0.0;
    return it->second;
}
Beispiel #12
0
uint32_t Book::votes(eris_time_t t) const {
    if (t < created_) return 0;
    auto lock = readLock();
    auto it = votes_.find(t);
    if (it == votes_.end()) return 0;
    return it->second;
}
static skipItem skipLock(skipList list, UINT32 key, skipItem *save, INT32 top) {

  INT32 i;
  skipItem x, y;

  if(list->threaded)
    readLock(list);

  x = list->header;                            /* header contains all levels */

  for(i = top;                        /* loop from top level down to level 0 */
      i >= 0;
      i--) {

    y = x->next[i];                           /* get next item at this level */

    while(y->key < key) {       /* if y has a smaller key, try the next item */
      x = y;                                  /* save x in case we overshoot */
      y = x->next[i];                                       /* get next item */
    }

    save[i] = x;                  /* preserve item with next pointer in save */
  }

  if(list->threaded)
    writeLock(list);                                 /* lock list for update */

                               /* validate we have the closest previous item */
  return skipClosest(x, key, 0);
}
int EventTagMap::find(MapString&& tag) const {
  std::unordered_map<MapString, uint32_t>::const_iterator it;
  android::RWLock::AutoRLock readLock(const_cast<android::RWLock&>(rwlock));
  it = Tag2Idx.find(std::move(tag));
  if (it == Tag2Idx.end()) return -1;
  return it->second;
}
Beispiel #15
0
 bool TokenFactory::isAvailable(const Token & token)
 {
     ReadLock readLock( mMutex );
     return 
         std::find(mAvailableTokens.begin(), mAvailableTokens.end(), token) 
         != mAvailableTokens.end();
 }
    bool I_IpServerTransport::isIpAllowed(const IpAddress &ip) const
    {
        ReadLock readLock(mReadWriteMutex);

        if (!mAllowedIps.empty())
        {
            for (std::size_t i=0; i<mAllowedIps.size(); ++i)
            {
                if (ip.matches(mAllowedIps[i].first, mAllowedIps[i].second))
                {
                    return true;
                }
            }
            return false;
        }

        if (!mDisallowedIps.empty())
        {
            for (std::size_t i=0; i<mDisallowedIps.size(); ++i)
            {
                if (ip.matches(mDisallowedIps[i].first, mDisallowedIps[i].second))
                {
                    return false;
                }
            }
            return true;
        }

        return true;
    }    
/*
 * Install a new translator
 */
bool lamexp_install_translator(const QString &langId)
{
	bool success = false;
	const QString qmFileToPath(":/localization/%1");

	if(langId.isEmpty() || langId.toLower().compare(LAMEXP_DEFAULT_LANGID) == 0)
	{
		success = lamexp_install_translator_from_file(qmFileToPath.arg(LAMEXP_DEFAULT_TRANSLATION));
	}
	else
	{
		QReadLocker readLock(&g_lamexp_translation.lock);
		QString qmFile = (g_lamexp_translation.files) ? g_lamexp_translation.files->value(langId.toLower(), QString()) : QString();
		readLock.unlock();

		if(!qmFile.isEmpty())
		{
			success = lamexp_install_translator_from_file(qmFileToPath.arg(qmFile));
		}
		else
		{
			qWarning("Translation '%s' not available!", langId.toLatin1().constData());
		}
	}

	return success;
}
/*
 * Lookup tool version
 */
unsigned int lamexp_tool_version(const QString &toolName, QString *tag)
{
	QReadLocker readLock(&g_lamexp_tools.lock);
	if(tag) tag->clear();

	if(g_lamexp_tools.versions)
	{
		if(g_lamexp_tools.versions->contains(toolName.toLower()))
		{
			if(tag)
			{
				if(g_lamexp_tools.tags->contains(toolName.toLower())) *tag = g_lamexp_tools.tags->value(toolName.toLower());
			}
			return g_lamexp_tools.versions->value(toolName.toLower());
		}
		else
		{
			return UINT_MAX;
		}
	}
	else
	{
		return UINT_MAX;
	}
}
Beispiel #19
0
unsigned int Book::pirated(eris_time_t t) const {
    if (t < created_) return 0;
    auto lock = readLock();
    auto it = copies_pirated_.find(t);
    if (it == copies_pirated_.end()) return 0;
    return it->second;
}
Beispiel #20
0
UsdGeomCamera
GusdOBJ_usdcamera::_LoadCamera(fpreal t, int thread)
{
    /* XXX: Disallow camera loading until the scene has finished loading.
       What happens otherwise is that some parm values are pulled on
       during loading, causing a _LoadCamera request. If this happens before
       the node's parm values have been loaded, then we'll end up loading
       the camera using defaults (which reference the shot conversion).
       So if we don't block this, we end up always loading the shot conversion,
       even if we don't need it! */

    if(_isLoading)
        return UsdGeomCamera();

    /* Always return a null camera while saving.
       This is to prevent load errors from prematurely interrupting saves,
       which can lead to corrupt files.*/
    if(GusdUTverify_ptr(OPgetDirector())->getIsDoingExplicitSave())
        return UsdGeomCamera();

    {
        UT_AutoReadLock readLock(_lock);
        if(!_camParmsMicroNode.requiresUpdate(t))
            return _cam;
    }

    UT_AutoWriteLock writeLock(_lock);

    /* Other thread may already have loaded the cam, so only update if needed.*/
    if(_camParmsMicroNode.updateIfNeeded(t, thread))
    {
        _errors.clearAndDestroyErrors();
        _cam = UsdGeomCamera();

        GusdPRM_Shared prmShared;
        UT_String usdPath, primPath;

        evalStringT(usdPath, prmShared->filePathName.getToken(), 0, t, thread);
        evalStringT(primPath, prmShared->primPathName.getToken(), 0, t, thread);

        GusdUT_ErrorManager errMgr(_errors);
        GusdUT_ErrorContext err(errMgr);

        GusdStageCacheReader cache;
        if(UsdPrim prim = cache.GetPrimWithVariants(
               usdPath, primPath, GusdStageOpts::LoadAll(), &err).first) {

            // Track changes to the stage (eg., reloads)
            DEP_MicroNode* stageMicroNode =
                cache.GetStageMicroNode(prim.GetStage());
            UT_ASSERT_P(stageMicroNode);
            _camParmsMicroNode.addExplicitInput(*stageMicroNode);

            _cam = GusdUSD_Utils::MakeSchemaObj<UsdGeomCamera>(prim, &err);
            return _cam;
        }
    }
    return UsdGeomCamera();
}
 bool I_IpServerTransport::isClientIpAllowed(const std::string &ip) const
 {
     ReadLock readLock(mReadWriteMutex);
     return
         mAllowedIps.empty() ||
         (std::find(mAllowedIps.begin(), mAllowedIps.end(), ip) !=
             mAllowedIps.end());
 }
Beispiel #22
0
nsclient::core::plugin_cache::plugin_cache_list_type nsclient::core::plugin_cache::get_list() {
	boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(5));
	if (!readLock.owns_lock()) {
		LOG_ERROR_CORE("FATAL ERROR: Could not get read-mutex.");
		return plugin_cache_list_type();
	}
	return plugin_cache_list_type(plugin_cache_.begin(), plugin_cache_.end());
}
 StubFactoryPtr StubFactoryRegistry::getStubFactory(
     const std::string &objectName)
 {
     ReadLock readLock(mStubFactoryMapMutex);
     return mStubFactoryMap.find(objectName)  != mStubFactoryMap.end() ?
         mStubFactoryMap[objectName] :
         StubFactoryPtr();
 }
Beispiel #24
0
    ConstCacheObjectPtr getFromMap( const CacheId& cacheId ) const
    {
        ReadLock readLock( _mutex );
        ConstCacheMap::const_iterator it = _cacheMap.find( cacheId );
        if( it == _cacheMap.end( ))
            return CacheObjectPtr();

        return it->second;
    }
Beispiel #25
0
bool EventMonitorEntry::event(QEvent *e) {
    if (e->type() == EventMonitorEventType) {
      readLock();
      doLog(static_cast<EventMonitorEvent*>(e)->logMessage);
      unlock();
      return true;
    }
    return false;
}
Beispiel #26
0
void MsgHandler::Invoke(const IMsg *pMsg)
{
    ReadLock readLock(m_rwMutex);
    SigPunmap::iterator iter = m_sigPunmap.find(pMsg->ClassName());
    if (iter != m_sigPunmap.end())
    {
	(*(iter->second))(pMsg);
    }
}
Beispiel #27
0
void MsgHandler::Disconnect(const std::string &strClassName)
{
    ReadLock readLock(m_rwMutex);
    SigPunmap::iterator iter = m_sigPunmap.find(strClassName);
    if (iter != m_sigPunmap.end())
    {
	iter->second->disconnect_all_slots();
    }
}
Beispiel #28
0
bool StylesheetManager::hasStylesheet(const string& path)
{
	boost::shared_lock<boost::shared_mutex> readLock(stylesheetsLock);

	auto entry = parsedStylesheets.find(path);
	bool contained = (entry != parsedStylesheets.end());

	return contained;
}
 bool I_IpServerTransport::isClientAddrAllowed(const sockaddr_in &addr) const
 {
     ReadLock readLock(mReadWriteMutex);
     return
         mAllowedAddrs.empty() ||
         (std::find(
             mAllowedAddrs.begin(),
             mAllowedAddrs.end(),
             addr.sin_addr.s_addr) != mAllowedAddrs.end());
 }
Beispiel #30
0
	boost::optional<std::string> apply_cached(std::string &provider, long long mask) {
		boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(1));
		if (!readLock.owns_lock()) {
			return boost::optional<std::string>();
		}
		task_table::const_iterator pit = providers.find(provider);
		if (pit == providers.end())
			return boost::optional<std::string>();
		return do_apply(pit->second, mask);
	}