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


C++ SpinLock类代码示例

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


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

示例1: SingletonReleaseHashTable

void SingletonReleaseHashTable()
{
	g_SpinLockHashTable.Lock();
	if (g_pObjHash)
	{
		delete g_pObjHash;
		g_pObjHash = 0;
	}
	g_SpinLockHashTable.Unlock();
}
开发者ID:PaulJing,项目名称:Sora,代码行数:10,代码来源:GlobalSingleton.cpp

示例2: SingletonReleaseTextVector

void SingletonReleaseTextVector()
{
	g_SpinLockTextVec.Lock();
	if (g_pTextVec)
	{
		delete g_pTextVec;
		g_pTextVec = 0;
	}
	g_SpinLockTextVec.Unlock();
}
开发者ID:PaulJing,项目名称:Sora,代码行数:10,代码来源:GlobalSingleton.cpp

示例3: SingletonGetTextVector

TextBufVecType * SingletonGetTextVector()
{
	if (!g_pTextVec)
	{
		g_SpinLockTextVec.Lock();
		if (!g_pTextVec)
			g_pTextVec = new TextBufVecType;
		g_SpinLockTextVec.Unlock();
	}
	return g_pTextVec;
}
开发者ID:PaulJing,项目名称:Sora,代码行数:11,代码来源:GlobalSingleton.cpp

示例4: SingletonGetHashTable

HashType * SingletonGetHashTable()
{
	if (!g_pObjHash)
	{
		g_SpinLockHashTable.Lock();
		if (!g_pObjHash)
			g_pObjHash = new HashType;
		g_SpinLockHashTable.Unlock();
	}
	return g_pObjHash;
}
开发者ID:PaulJing,项目名称:Sora,代码行数:11,代码来源:GlobalSingleton.cpp

示例5: ParsingProcInternal

	void ParsingProcInternal()
	{
		while(true)
		{
			WString currentParsingText;
			{
				SpinLock::Scope scope(parsingTextLock);
				currentParsingText=parsingText;
				parsingText=L"";
			}
			if(currentParsingText==L"")
			{
				isParsingRunning=false;
				break;
			}

			List<Ptr<ParsingError>> errors;
			Ptr<ParsingTreeObject> node=grammarParser->Parse(currentParsingText, L"ParserDecl", errors).Cast<ParsingTreeObject>();
			Ptr<ParserDecl> decl;
			if(node)
			{
				node->InitializeQueryCache();
				decl=new ParserDecl(node);
			}
			{
				SpinLock::Scope scope(parsingTreeLock);
				parsingTreeNode=node;
				parsingTreeDecl=decl;
				node=0;
			}
			RestartColorizer();
		}
		parsingRunningEvent.Leave();
	}
开发者ID:vincentshi,项目名称:gac,代码行数:34,代码来源:Main.cpp

示例6: trylock_or_cancel_get_lock

// See that timer_trylock_or_cancel acquires the lock when the holder releases it.
static bool trylock_or_cancel_get_lock() {
    BEGIN_TEST;

    // We need 2 or more CPUs for this test.
    if (get_num_cpus_online() < 2) {
        printf("skipping test trylock_or_cancel_get_lock, not enough online cpus\n");
        return true;
    }

    timer_args arg{};
    timer_t t = TIMER_INITIAL_VALUE(t);

    SpinLock lock;
    arg.lock = lock.GetInternal();
    arg.wait = 1;

    arch_disable_ints();

    uint timer_cpu = arch_curr_cpu_num();
    const Deadline deadline = Deadline::no_slack(current_time() + ZX_USEC(100));
    timer_set(&t, deadline, timer_trylock_cb, &arg);

    // The timer is set to run on timer_cpu, switch to a different CPU, acquire the spinlock then
    // signal the callback to proceed.
    thread_set_cpu_affinity(get_current_thread(), ~cpu_num_to_mask(timer_cpu));
    DEBUG_ASSERT(arch_curr_cpu_num() != timer_cpu);

    arch_enable_ints();

    {
        AutoSpinLock guard(&lock);

        while (!atomic_load(&arg.timer_fired)) {
        }

        // Callback should now be running. Tell it to stop waiting and start trylocking.
        atomic_store(&arg.wait, 0);
    }

    // See that timer_cancel returns false indicating that the timer ran.
    ASSERT_FALSE(timer_cancel(&t), "");

    // Note, we cannot assert the value of arg.result. We have both released the lock and canceled
    // the timer, but we don't know which of these events the timer observed first.

    END_TEST;
}
开发者ID:saltstar,项目名称:smartnix,代码行数:48,代码来源:timer_tests.cpp

示例7: sleepAndRelease

void Scheduler::sleepAndRelease ( SpinLock &lock )
{
  lockScheduling();
  currentThread->state_=Sleeping;
  lock.release();
  unlockScheduling();
  yield();
}
开发者ID:BackupTheBerlios,项目名称:sweb-x86,代码行数:8,代码来源:Scheduler.cpp

示例8: TEST

    TEST(ParallelUtils,SpinLock) {

        const int N = 1000000;

        SpinLock lock;

        volatile int c =0;

        #pragma omp parallel for num_threads(4)
        for(int i=0; i<N; i++) {
            lock.lock();
            c++;
            lock.unlock();
        }

        EXPECT_EQ(N, c);

    }
开发者ID:cotsog,项目名称:souffle,代码行数:18,代码来源:parallel_utils_test.cpp

示例9: while

void duplicate_node::match(vector<duplicate_node*>& entrances,
                           search_duplicate_files_status* status,
                           SpinLock& lock)
{
    duplicate_node* iter = this;
    while (iter) {
        bool first_matched = true;
        duplicate_node* current_node = iter;
        duplicate_node* last_node = iter;
        euint current_symbol = iter->m_symbol;
        while (current_node) {
            {
                SpinLock::Instance inst = lock.Lock();
                if (status) {
                    status->m_current_status = search_duplicate_files_status::Matching;
                    status->m_processing_file = current_node->m_path.c_str();
                }
            }
            if (current_node->m_symbol == current_symbol && current_node != last_node) {
                last_node->m_next1 = current_node;
                if (first_matched) {
                    entrances.push_back(last_node);
                    first_matched = false;
                }
                last_node->m_is_matched = true;
                current_node->m_is_matched = true;
                last_node = current_node;
            }
            current_node = current_node->m_next0;
        }
        iter = iter->m_next0;
        while (iter && iter->m_is_matched) {
            iter = iter->m_next0;
        }
    }
    {
        SpinLock::Instance inst = lock.Lock();
        if (status) {
            status->m_current_status = search_duplicate_files_status::Idling;
            status->m_processing_file = nullptr;
        }
    }
}
开发者ID:1179432578,项目名称:xhnSTL,代码行数:43,代码来源:xhn_duplicate_finder.cpp

示例10: while

void xhn::thread::assign_to_local_thread(thread_ptr& local_thread, thread_ptr& global_thread, SpinLock& lock)
{
    {
        xhn::SpinLock::Instance inst = lock.Lock();
        local_thread = global_thread;
    }
    if (!local_thread) {

        local_thread = VNEW xhn::thread;
        while (!local_thread->is_running()) {}

        {
            xhn::SpinLock::Instance inst = lock.Lock();
            if (!global_thread) {
                global_thread = local_thread;
            }
            else {
                local_thread = global_thread;
            }
        }
    }
}
开发者ID:vengine,项目名称:xhnSTL,代码行数:22,代码来源:xhn_thread.cpp

示例11: getDefault

		Font Font::getDefault()
		{
			static Font font;
			static SpinLock lock;

			lock.lock();

			if (font.getHandle() == nullptr)
			{
				jni::Class Button("libnative/ui/TextComponent");
				jni::method_t viewConstructor = Button.getConstructor("(Landroid/content/Context;)V");
				jni::Object button = Button.newInstance(viewConstructor, (jni::Object*) App::getAppHandle());

				// Android already scales its default fonts.
				font._size = button.call<float>("getScaledTextSize");
				font._shared->handle = new jni::Object(button.call<jni::Object>("getTypeface()Landroid/graphics/Typeface;"));
			}

			lock.release();

			return font;
		}
开发者ID:mitchdowd,项目名称:native,代码行数:22,代码来源:font.cpp

示例12: SubmitCurrentText

	void SubmitCurrentText(const wchar_t* text)
	{
		{
			// copy the text because this is a cross thread accessible data
			SpinLock::Scope scope(parsingTextLock);
			parsingText=text;
		}
		if(!isParsingRunning)
		{
			isParsingRunning=true;
			parsingRunningEvent.Enter();
			ThreadPoolLite::Queue(&ParsingProc, this);
		}
	}
开发者ID:vincentshi,项目名称:gac,代码行数:14,代码来源:Main.cpp

示例13: SpinGuard

	SpinGuard(SpinLock& mutex) : _mutex(&mutex){
		_mutex->lock();
	}
开发者ID:ankithbti,项目名称:OrderBookSketch,代码行数:3,代码来源:SpinLock.hpp

示例14: Run

void NetworkManager::Run()
{
	int threadId;
	struct epoll_event events[100];
	int numOfEvent, n;

	g_networkThreadCountLock.Lock();
	threadId = g_networkThreadCount++;
	g_networkThreadCountLock.Unlock();

	for(;;)
	{
		numOfEvent = epoll_wait(m_epollFdList[threadId], m_epollEvent2DList[threadId], 100, 2000);

		//printf("NW thread %d\n", threadId);
		if(numOfEvent < 0){	
			// critical error
			fprintf(stderr, "[ERROR] epoll_wait() ERROR : %s\n", strerror(errno));
			exit(1);
		}

		if(numOfEvent == 0)
		{
			continue;
		}

		//printf("NT %d activated\n", TC);
		OnEvent(numOfEvent, threadId);
	}
	close(m_serverFd);
	for(int i=0; i<NETWORK_THREAD_NUM; i++)
		close(m_epollFdList[i]);
}
开发者ID:rainloader,项目名称:PlaySsenger,代码行数:33,代码来源:NetworkManager.cpp

示例15: func

void func(int i)
{
	g_lock.lock();
	std::this_thread::sleep_for(std::chrono::milliseconds(10));
	std::cout << std::this_thread::get_id() << "add : " << i << std::endl;
	sum++;
	g_lock.unlock();
}
开发者ID:LeftThink,项目名称:CodeTricks,代码行数:8,代码来源:test.cpp


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