Example #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;
 }
Example #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;
 }
Example #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;
}
Example #4
0
boost::asio::io_service&
getGlobalIoService()
{
  if (g_ioService.get() == nullptr) {
    g_ioService.reset(new boost::asio::io_service());
  }
  return *g_ioService;
}
CLogBuffer& CLogBuffer::GetCLogBuffer()
{
	if (_ptr.get() == NULL)
	{
		_ptr.reset(new CLogBuffer);
	}

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

  return *g_scheduler;
}
Example #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;
}
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();
}
Example #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;
}
Example #10
0
PlowClient* getClient()
{
    static boost::thread_specific_ptr<PlowClient> instance;
    if(!instance.get())
    {
        instance.reset(new PlowClient);
    }
    return instance.get();
}
	/*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());
	}
Example #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;
	}
}
    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;
    }
Example #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';
  }
}
Example #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));
}
Example #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;
}
 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;
 }
Example #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)());
}
Example #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
    }
Example #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;
    }
}
Example #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);
}
    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)));
    }
Example #23
0
static SFMTRand* GetRng()
{
    SFMTRand* rand = sfmtRand.get();

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

    return rand;
}
Example #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];
 }
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( );
}
Example #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();
}
Example #27
0
File: random.cpp Project: 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
}
Example #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;
}
Example #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;
}
Example #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;
    }