Exemplo n.º 1
0
 bool run(const string&, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     nonce64 *n = new nonce64(Security::getNonce());
     stringstream ss;
     ss << hex << *n;
     result.append("nonce", ss.str() );
     lastNonce.reset(n);
     return true;
 }
Exemplo n.º 2
0
 Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
     setThreadName(desc);
     assert( currentClient.get() == 0 );
     Client *c = new Client(desc, mp);
     currentClient.reset(c);
     mongo::lastError.initThread();
     return *c;
 }
Exemplo n.º 3
0
backtrace_t & backtrace_t::instance() {
    static boost::thread_specific_ptr<backtrace_t> instances;
    if (instances.get() == NULL) {
        instances.reset(new backtrace_t());
    }

    return *instances;
}
Exemplo n.º 4
0
boost::asio::io_service&
getGlobalIoService()
{
  if (g_ioService.get() == nullptr) {
    g_ioService.reset(new boost::asio::io_service());
  }
  return *g_ioService;
}
Exemplo n.º 5
0
CLogBuffer& CLogBuffer::GetCLogBuffer()
{
	if (_ptr.get() == NULL)
	{
		_ptr.reset(new CLogBuffer);
	}

	return *(_ptr.get());
}
Exemplo n.º 6
0
Scheduler&
getGlobalScheduler()
{
  if (g_scheduler.get() == nullptr) {
    g_scheduler.reset(new Scheduler(getGlobalIoService()));
  }

  return *g_scheduler;
}
Exemplo n.º 7
0
boost::asio::io_service* get_io_service(boost::asio::io_service* ioservice= 0 )
{
    static boost::thread_specific_ptr<boost::asynchronous::tss_io_service_wrapper> s_io_service;
    if (ioservice != 0)
    {
        s_io_service.reset(new boost::asynchronous::tss_io_service_wrapper(ioservice));
    }
    return s_io_service.get()->m_io_service;
}
Exemplo n.º 8
0
int* get_array_data()
{
   static boost::thread_specific_ptr<boost::array<int, 200> > tp;

   if(tp.get() == 0)
      tp.reset(new boost::array<int, 200>);

   return tp.get()->data();
}
Exemplo n.º 9
0
boost::thread_specific_ptr<double>& get_thread_local_aspect_ratio()
{
	static boost::thread_specific_ptr<double> aspect_ratio;

	if (!aspect_ratio.get())
		aspect_ratio.reset(new double(1.0));

	return aspect_ratio;
}
Exemplo n.º 10
0
PlowClient* getClient()
{
    static boost::thread_specific_ptr<PlowClient> instance;
    if(!instance.get())
    {
        instance.reset(new PlowClient);
    }
    return instance.get();
}
Exemplo n.º 11
0
	/*static*/ sources::severity_logger<Logging::Severity>& LogStream::GetLogger()
	{
		static boost::thread_specific_ptr<sources::severity_logger<Logging::Severity>> s_threadLocalLogger;
		if (!s_threadLocalLogger.get())
		{
			s_threadLocalLogger.reset(new sources::severity_logger<Logging::Severity>());
		}
		return *(s_threadLocalLogger.get());
	}
Exemplo n.º 12
0
void Expression::ScriptBreakpoint(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di)
{
	bool *inHandler = l_InBreakpointHandler.get();
	if (!inHandler || !*inHandler) {
		inHandler = new bool(true);
		l_InBreakpointHandler.reset(inHandler);
		OnBreakpoint(frame, ex, di);
		*inHandler = false;
	}
}
Exemplo n.º 13
0
    void operator()()
    {
        //int* p = manager::instance().get();
        std::string* p = manager::instance().get();
        *p = "hello";

        //ptr.reset(new (std::nothrow) int(200));
        ptr.reset(new (std::nothrow) std::string("world"));
        std::cout << "thread 2: " << *ptr << std::endl;
    }
Exemplo n.º 14
0
void init()
{
  static boost::thread_specific_ptr<bool> tls;
  if (!tls.get())
  {
    tls.reset(new bool{true});
    boost::lock_guard<boost::mutex> lock{mutex};
    std::cout << "done" << '\n';
  }
}
Exemplo n.º 15
0
UUID UUID::string_generate(const std::string &t_str)
{
  static boost::thread_specific_ptr<boost::uuids::string_generator> gen;

  if (gen.get() == nullptr) {
    gen.reset(new boost::uuids::string_generator);
  }

  return UUID((*gen)(t_str));
}
Exemplo n.º 16
0
// Return a reference to the string for this thread's error messages,
// creating it if none exists for this thread thus far.
static std::string&
error_msg()
{
    std::string* e = thread_error_msg.get();
    if (!e) {
        e = new std::string;
        thread_error_msg.reset(e);
    }
    return *e;
}
Exemplo n.º 17
0
 void operator()()
 {
     //ptr.reset(new (std::nothrow) int(0));
     ptr.reset(new (std::nothrow) std::string());
     std::cout << "thread 1: " << *ptr << std::endl;
     manager::instance().insert(ptr.get());
     std::cout << "thread 1: " << *ptr << std::endl;
     sleep(10);
     std::cout << "thread 1: " << *ptr << std::endl;
 }
Exemplo n.º 18
0
UUID UUID::random_generate()
{
  static boost::thread_specific_ptr<boost::uuids::random_generator> gen;

  if (gen.get() == nullptr) {
    gen.reset(new boost::uuids::random_generator);
  }

  return UUID((*gen)());
}
Exemplo n.º 19
0
    int   dlclose(void *handle) {
      g_LastError.reset();
      if (!handle)
        return 0;
#ifdef _WIN32
      // Mimic unix dlclose (0 on success)
      return FreeLibrary((HINSTANCE) handle) != 0 ? 0 : -1;
#else
      return ::dlclose(handle);
#endif
    }
Exemplo n.º 20
0
thread_context & thread_context::instance() {
    thread_context * self = instance_.get();
    if (self) {
        return *self;
    } else {
        // Create a new thread context for this thread
        thread_context * r = new thread_context();
        instance_.reset(r);
        return *r;
    }
}
Exemplo n.º 21
0
void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
{
	auto *tinfo = static_cast<std::type_info *>(pvtinfo);

	typedef void (*cxa_throw_fn)(void *, std::type_info *, void (*)(void *)) __attribute__((noreturn));
	static cxa_throw_fn real_cxa_throw;

#if !defined(__GLIBCXX__) && !defined(_WIN32)
	l_LastExceptionObj.reset(new void *(obj));
	l_LastExceptionPvtInfo.reset(new TYPEINFO_TYPE *(pvtinfo));
	l_LastExceptionDest.reset(new DestCallback(dest));
#endif /* !defined(__GLIBCXX__) && !defined(_WIN32) */

	if (real_cxa_throw == nullptr)
		real_cxa_throw = (cxa_throw_fn)dlsym(RTLD_NEXT, "__cxa_throw");

#ifndef NO_CAST_EXCEPTION
	void *uex = cast_exception(obj, tinfo, &typeid(user_error));
	auto *ex = reinterpret_cast<boost::exception *>(cast_exception(obj, tinfo, &typeid(boost::exception)));

	if (!uex) {
#endif /* NO_CAST_EXCEPTION */
		StackTrace stack;
		SetLastExceptionStack(stack);

#ifndef NO_CAST_EXCEPTION
		if (ex && !boost::get_error_info<StackTraceErrorInfo>(*ex))
			*ex << StackTraceErrorInfo(stack);
	}
#endif /* NO_CAST_EXCEPTION */

	ContextTrace context;
	SetLastExceptionContext(context);

#ifndef NO_CAST_EXCEPTION
	if (ex && !boost::get_error_info<ContextTraceErrorInfo>(*ex))
		*ex << ContextTraceErrorInfo(context);
#endif /* NO_CAST_EXCEPTION */

	real_cxa_throw(obj, tinfo, dest);
}
Exemplo n.º 22
0
    void LoadRTree()
    {
        BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");

        RTreeNode *tree_ptr =
            data_layout->GetBlockPtr<RTreeNode>(shared_memory, SharedDataLayout::R_SEARCH_TREE);
        m_static_rtree.reset(new TimeStampedRTreePair(
            CURRENT_TIMESTAMP,
            osrm::make_unique<SharedRTree>(
                tree_ptr, data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE],
                file_index_path, m_coordinate_list)));
    }
Exemplo n.º 23
0
static SFMTRand* GetRng()
{
    SFMTRand* rand = sfmtRand.get();

    if (!rand)
    {
        rand = new SFMTRand();
        sfmtRand.reset(rand);
    }

    return rand;
}
Exemplo n.º 24
0
 virtual
 boost::shared_ptr<void>
 construct(di::type_info const & type,
           di::type_provider & unscoped)
 {
   if(!m_instances.get())
     m_instances.reset(new instance_map_t);
   instance_map_t::iterator it = m_instances->find(type);
   if(it == m_instances->end())
     (*m_instances)[type] = unscoped.untyped_get();
   return (*m_instances)[type];
 }
Exemplo n.º 25
0
JNIEnv* GetJNIEnv( )
{
	// Do we already have a JNIEnv?
	ThreadJNIEnv* pJNIEnv = g_oJNIEnv.get( );

	if( pJNIEnv == NULL )
	{
		// Create a new JNIEnv (attach the thread)
		g_oJNIEnv.reset( new ThreadJNIEnv( ) );
	}

	return g_oJNIEnv->GetEnv( );
}
Exemplo n.º 26
0
inline const std::string& get_id<std::string>() {
    static boost::thread_specific_ptr<std::string> instance;
    if (!instance.get()) {
        std::ostringstream stream;
#ifdef __linux
        stream << std::hex << std::internal << std::showbase << std::setw(2) << std::setfill('0');
#endif
        stream << std::this_thread::get_id();
        instance.reset(new std::string(stream.str()));
    }

    return *instance.get();
}
Exemplo n.º 27
0
Arquivo: random.cpp Projeto: Jaak/ray
Engine& rng_engine() {
#ifdef HAVE_THREAD_LOCAL_STORAGE
    static thread_local auto the_rng_engine = Engine{std::random_device{}()};
    return the_rng_engine;
#else
    static boost::thread_specific_ptr<Engine> engine_ptr;
    if (!engine_ptr.get()) {
        engine_ptr.reset(new Engine{std::random_device{}()});
    }

    return *engine_ptr;
#endif
}
Exemplo n.º 28
0
bool& installed_for_thread()
{
	static boost::thread_specific_ptr<bool> installed;

	auto for_thread = installed.get();
	
	if (!for_thread)
	{
		for_thread = new bool(false);
		installed.reset(for_thread);
	}

	return *for_thread;
}
Exemplo n.º 29
0
bool& installed_for_thread()
{
	static boost::thread_specific_ptr<bool> installed;

	auto local = installed.get();

	if (!local)
	{
		local = new bool(false);
		installed.reset(local);
	}

	return *local;
}
Exemplo n.º 30
0
    unsigned _setThreadName( const char * name ) {
        if ( ! name ) name = "NONE";

        static unsigned N = 0;

        if ( strcmp( name , "conn" ) == 0 ) {
            string* x = _threadName.get();
            if ( x && mongoutils::str::startsWith( *x , "conn" ) ) {
                int n = atoi( x->c_str() + 4 );
                if ( n > 0 )
                    return n;
                warning() << "unexpected thread name [" << *x << "] parsed to " << n << endl;
            }
            unsigned n = ++N;
            stringstream ss;
            ss << name << n;
            _threadName.reset( new string( ss.str() ) );
            return n;
        }

        _threadName.reset( new string(name) );
        return 0;
    }