当前位置: 首页>>代码示例>>C++>>正文


C++ thread_specific_ptr类代码示例

本文整理汇总了C++中thread_specific_ptr的典型用法代码示例。如果您正苦于以下问题:C++ thread_specific_ptr类的具体用法?C++ thread_specific_ptr怎么用?C++ thread_specific_ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了thread_specific_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _scopeInitCallback


//.........这里部分代码省略.........
            }
        }

        Scope* get(const string& pool) {
            scoped_lock lk(_mutex);
            list<Scope*>& l = _pools[pool];
            if (l.size() == 0)
                return 0;

            Scope* s = l.back();
            l.pop_back();
            s->reset();
            s->incTimeUsed();
            return s;
        }

        void clear() {
            set<Scope*> seen;
            for (PoolToScopes::iterator i = _pools.begin(); i != _pools.end(); ++i) {
                for (list<Scope*>::iterator j = i->second.begin(); j != i->second.end(); ++j) {
                    Scope* s = *j;
                    fassert(16652, seen.insert(s).second);
                    delete s;
                }
            }
            _pools.clear();
        }

    private:
        PoolToScopes _pools;
        mongo::mutex _mutex;
    };

    thread_specific_ptr<ScopeCache> scopeCache;

    class PooledScope : public Scope {
    public:
        PooledScope(const std::string& pool, Scope* real) : _pool(pool), _real(real) {
            _real->loadStored(true);
        };
        virtual ~PooledScope() {
            ScopeCache* sc = scopeCache.get();
            if (sc) {
                sc->done(_pool, _real);
                _real = NULL;
            }
            else {
                // this means that the Scope was killed from a different thread
                // for example a cursor got timed out that has a $where clause
                LOG(3) << "warning: scopeCache is empty!" << endl;
                delete _real;
                _real = 0;
            }
        }

        // wrappers for the derived (_real) scope
        void reset() { _real->reset(); }
        void init(const BSONObj* data) { _real->init(data); }
        void localConnect(const char* dbName) { _real->localConnect(dbName); }
        void setLocalDB(const string& dbName) { _real->setLocalDB(dbName); }
        void loadStored(bool ignoreNotConnected = false) { _real->loadStored(ignoreNotConnected); }
        void externalSetup() { _real->externalSetup(); }
        void gc() { _real->gc(); }
        bool isKillPending() const { return _real->isKillPending(); }
        int type(const char* field) { return _real->type(field); }
        string getError() { return _real->getError(); }
开发者ID:Nub,项目名称:mongo,代码行数:67,代码来源:engine.cpp

示例2: syscalls_interruptable

namespace this_thread {

	/**
	 * @intern
	 */
	extern thread_specific_ptr<bool> _syscalls_interruptable;
	
	/**
	 * Check whether system calls should be interruptable in
	 * the calling thread.
	 */
	bool syscalls_interruptable();
	
	class restore_syscall_interruption;

	/**
	 * Create this struct on the stack to temporarily enable system
	 * call interruption, until the object goes out of scope.
	 */
	class enable_syscall_interruption {
	private:
		bool last_value;
	public:
		enable_syscall_interruption() {
			if (_syscalls_interruptable.get() == NULL) {
				last_value = true;
				_syscalls_interruptable.reset(new bool(true));
			} else {
				last_value = *_syscalls_interruptable;
				*_syscalls_interruptable = true;
			}
		}
		
		~enable_syscall_interruption() {
			*_syscalls_interruptable = last_value;
		}
	};
	
	/**
	 * Create this struct on the stack to temporarily disable system
	 * call interruption, until the object goes out of scope.
	 * While system call interruption is disabled, the functions in
	 * InterruptableCalls will try until the return code is not EINTR.
	 */
	class disable_syscall_interruption {
	private:
		friend class restore_syscall_interruption;
		bool last_value;
	public:
		disable_syscall_interruption() {
			if (_syscalls_interruptable.get() == NULL) {
				last_value = true;
				_syscalls_interruptable.reset(new bool(false));
			} else {
				last_value = *_syscalls_interruptable;
				*_syscalls_interruptable = false;
			}
		}
		
		~disable_syscall_interruption() {
			*_syscalls_interruptable = last_value;
		}
	};
	
	/**
	 * Creating an object of this class on the stack will restore the
	 * system call interruption state to what it was before.
	 */
	class restore_syscall_interruption {
	private:
		int last_value;
	public:
		restore_syscall_interruption(const disable_syscall_interruption &intr) {
			assert(_syscalls_interruptable.get() != NULL);
			last_value = *_syscalls_interruptable;
			*_syscalls_interruptable = intr.last_value;
		}
		
		~restore_syscall_interruption() {
			*_syscalls_interruptable = last_value;
		}
	};

} // namespace this_thread
开发者ID:famoseagle,项目名称:passenger,代码行数:84,代码来源:system_calls.hpp

示例3: run

 virtual bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     string fromhost = cmdObj.getStringField("fromhost");
     if ( fromhost.empty() ) {
         /* copy from self */
         stringstream ss;
         ss << "localhost:" << cmdLine.port;
         fromhost = ss.str();
     }
     string fromdb = cmdObj.getStringField("fromdb");
     string todb = cmdObj.getStringField("todb");
     if ( fromhost.empty() || todb.empty() || fromdb.empty() ) {
         errmsg = "parms missing - {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>}";
         return false;
     }
     Cloner c;
     string username = cmdObj.getStringField( "username" );
     string nonce = cmdObj.getStringField( "nonce" );
     string key = cmdObj.getStringField( "key" );
     if ( !username.empty() && !nonce.empty() && !key.empty() ) {
         uassert( 13008, "must call copydbgetnonce first", authConn_.get() );
         BSONObj ret;
         {
             dbtemprelease t;
             if ( !authConn_->runCommand( fromdb, BSON( "authenticate" << 1 << "user" << username << "nonce" << nonce << "key" << key ), ret ) ) {
                 errmsg = "unable to login " + string( ret );
                 return false;
             }
         }
         c.setConnection( authConn_.release() );
     }
     Client::Context ctx(todb);
     bool res = c.go(fromhost.c_str(), errmsg, fromdb, /*logForReplication=*/!fromRepl, /*slaveok*/false, /*replauth*/false, /*snapshot*/true);
     return res;
 }
开发者ID:erickt,项目名称:mongo,代码行数:34,代码来源:cloner.cpp

示例4: run

        virtual bool run(OperationContext* txn,
                         const string&,
                         BSONObj& cmdObj,
                         int,
                         string& errmsg,
                         BSONObjBuilder& result) {

            string fromhost = cmdObj.getStringField("fromhost");
            if ( fromhost.empty() ) {
                /* copy from self */
                stringstream ss;
                ss << "localhost:" << serverGlobalParams.port;
                fromhost = ss.str();
            }

            const ConnectionString cs(uassertStatusOK(ConnectionString::parse(fromhost)));

            authConn_.reset(cs.connect(errmsg));
            if (!authConn_.get()) {
                return false;
            }

            BSONObj ret;

            if( !authConn_->runCommand( "admin", BSON( "getnonce" << 1 ), ret ) ) {
                errmsg = "couldn't get nonce " + ret.toString();
                return false;
            }

            result.appendElements( ret );
            return true;
        }
开发者ID:ArgusTek,项目名称:mongo,代码行数:32,代码来源:copydb_start_commands.cpp

示例5: threadInstance

 static ClientConnections* threadInstance() {
     ClientConnections* cc = _perThread.get();
     if ( ! cc ) {
         cc = new ClientConnections();
         _perThread.reset( cc );
     }
     return cc;
 }
开发者ID:BendustiK,项目名称:mongo,代码行数:8,代码来源:shardconnection.cpp

示例6: bool

		disable_syscall_interruption() {
			if (_syscalls_interruptable.get() == NULL) {
				last_value = true;
				_syscalls_interruptable.reset(new bool(false));
			} else {
				last_value = *_syscalls_interruptable;
				*_syscalls_interruptable = false;
			}
		}
开发者ID:famoseagle,项目名称:passenger,代码行数:9,代码来源:system_calls.hpp

示例7: assert

std::shared_ptr<CoreContext> CoreContext::CurrentContext(void) {
  if(!autoCurrentContext.get())
    return std::static_pointer_cast<CoreContext, GlobalCoreContext>(GetGlobalContext());

  std::shared_ptr<CoreContext>* retVal = autoCurrentContext.get();
  assert(retVal);
  assert(*retVal);
  return *retVal;
}
开发者ID:cuculesa,项目名称:autowiring,代码行数:9,代码来源:CoreContext.cpp

示例8: operator

 ostream & operator()() {
     ThreadOutputStream * tos( threadOutputStream_.get() );
     if( tos == nullptr ) {
         tos = new ThreadOutputStream();
         threadOutputStream_.reset( tos );
     }
     return (*tos) << boost::posix_time::microsec_clock::universal_time() <<
             ' ' << format("%014s") % boost::this_thread::get_id() <<
             " [ " << format("%-20.20s") % name_ << " ] ";
 };
开发者ID:danielhams,项目名称:Levgen-Algorithm-Benchmarks,代码行数:10,代码来源:Utils.cpp

示例9: worker

inline void worker(
    std::uint64_t updates
    )
{
    global_scratch.reset(new double);

    for (double i = 0.; i < updates; ++i)
        *global_scratch += 1. / (2. * i + 1.);

    global_scratch.reset();
}
开发者ID:ShmuelLevine,项目名称:hpx,代码行数:11,代码来源:hpx_tls_overhead.cpp

示例10: ScopeCache

    /** Get a scope from the pool of scopes matching the supplied pool name */
    auto_ptr<Scope> ScriptEngine::getPooledScope(const string& pool) {
        if (!scopeCache.get())
            scopeCache.reset(new ScopeCache());

        Scope* s = scopeCache->get(pool);
        if (!s)
            s = newScope();

        auto_ptr<Scope> p;
        p.reset(new PooledScope(pool, s));
        return p;
    }
开发者ID:Thor1Khan,项目名称:mongo,代码行数:13,代码来源:engine.cpp

示例11: checkTSSInit

		void checkTSSInit()
		{
			if(m_transactionInProgress.get() == 0)
			{
				m_transactionInProgress.reset(new bool);
				(*m_transactionInProgress) = false;
			}

			if(m_transaction.get() == 0)
			{
				m_transaction.reset(new DbTxn *);
				(*m_transaction) = NULL;
			}
		}
开发者ID:Tiger66639,项目名称:librebecca,代码行数:14,代码来源:DatabaseManager.cpp

示例12: ScopeCache

    /** Get a scope from the pool of scopes matching the supplied pool name */
    auto_ptr<Scope> ScriptEngine::getPooledScope(const string& pool, const string& scopeType) {
        if (!scopeCache.get())
            scopeCache.reset(new ScopeCache());

        Scope* s = scopeCache->get(pool + scopeType);
        if (!s)
            s = newScope();

        auto_ptr<Scope> p;
        p.reset(new PooledScope(pool + scopeType, s));
        p->setLocalDB(pool);
        p->loadStored(true);
        return p;
    }
开发者ID:Nub,项目名称:mongo,代码行数:15,代码来源:engine.cpp

示例13: CurrentContextOrNull

std::shared_ptr<CoreContext> CoreContext::SetCurrent(const std::shared_ptr<CoreContext>& ctxt) {
  const auto& currentContext = CurrentContextOrNull();

  // Short-circuit test, no need to proceed if we aren't changing the context:
  if (currentContext == ctxt)
    return currentContext;

  // Value is changing, update:
  auto retVal = currentContext;
  if (ctxt)
    autoCurrentContext.reset(new std::shared_ptr<CoreContext>(ctxt));
  else
    autoCurrentContext.reset();
  return retVal;
}
开发者ID:cuculesa,项目名称:autowiring,代码行数:15,代码来源:CoreContext.cpp

示例14:

    Glob::Glob(const std::string& pattern, GlobFlags flags)
    {
        globObject.reset(this);

        posix::glob_t glob;
        posix::glob(pattern.c_str(), flags, &onGlobError, &glob);

        globObject.release();

        if (glob.gl_pathc) {
            for (char** p = glob.gl_pathv; *p != NULL; ++p) {
                pathNames_.push_back(*p);
            }
        }

        posix::globfree(&glob);
    }
开发者ID:joramreal,项目名称:simpleshell,代码行数:17,代码来源:glob.cpp

示例15: pathName

    extern "C" int onGlobError(const char *epath, int eerrno)
    {
        std::string pathName(epath);
        std::error_code errorCode(eerrno, std::system_category());

        globObject->errors_.push_back(std::make_pair(pathName, errorCode));
        return globObject->onError(pathName, errorCode);
    }
开发者ID:joramreal,项目名称:simpleshell,代码行数:8,代码来源:glob.cpp


注:本文中的thread_specific_ptr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。