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


C++ atomic_bool::store方法代码示例

本文整理汇总了C++中std::atomic_bool::store方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic_bool::store方法的具体用法?C++ atomic_bool::store怎么用?C++ atomic_bool::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::atomic_bool的用法示例。


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

示例1: thread_connect

	void thread_connect() {
		connected.store(false);

		do {
			struct sockaddr_in addr;
			int      r;
			hostent* h;

			memset((void*)&addr, 0, sizeof(addr));
			addr.sin_addr.s_addr = inet_addr(ip.c_str());
			if(INADDR_NONE == addr.sin_addr.s_addr) {
				h = gethostbyname(ip.c_str());
				if(NULL == h) {
					perror("Could not get host by name");
					break;;
				}
			} else {
				h = gethostbyaddr((const char*)&addr.sin_addr, sizeof(struct sockaddr_in), AF_INET);
				if(NULL == h) {
					perror("Could not get host by address");
					break;;
				}
			}

			sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
			if(INVALID_SOCKET == sock) {
				perror("Could not create socket");
				break;
			}

			BOOL bDontLinger = TRUE;
			setsockopt( sock, SOL_SOCKET, SO_DONTLINGER, ( const char* )&bDontLinger, sizeof( BOOL ) );

			addr.sin_family = AF_INET;
			addr.sin_addr   = *((in_addr*)*h->h_addr_list);
			addr.sin_port   = htons(port);

			printf("Connecting... ");
			r = connect(sock, (sockaddr*)&addr, sizeof(struct sockaddr));
			if(SOCKET_ERROR == r) {
				printf("Cannot connect to server%d\n", get_errno());
				break;
			}
			printf("connected.\n");

			connected.store(true);
			connecting.store(false);
			sender.swap(std::thread(std::bind(&transport_t::thread_send, this)));
			recver.swap(std::thread(std::bind(&transport_t::thread_recv, this)));
			return;
		} while (0);

		connecting.store(false);
	}
开发者ID:killgxlin,项目名称:boost_network,代码行数:54,代码来源:new_client.cpp

示例2: addAndSetTime

    // ------------------------------------------------------------------------
    void addAndSetTime(uint32_t ping, uint64_t server_time)
    {
        if (m_synchronised.load() == true)
            return;

        if (m_force_set_timer.load() == true)
        {
            m_force_set_timer.store(false);
            m_synchronised.store(true);
            STKHost::get()->setNetworkTimer(server_time + (uint64_t)(ping / 2));
            return;
        }

        const uint64_t cur_time = StkTime::getMonoTimeMs();
        // Discard too close time compared to last ping
        // (due to resend when packet loss)
        // 10 packets per second as seen in STKHost
        const uint64_t frequency = (uint64_t)((1.0f / 10.0f) * 1000.0f) / 2;
        if (!m_times.empty() &&
            cur_time - std::get<2>(m_times.back()) < frequency)
            return;

        // Take max 20 averaged samples from m_times, the next addAndGetTime
        // is used to determine that server_time if it's correct, if not
        // clear half in m_times until it's correct
        if (m_times.size() >= 20)
        {
            uint64_t sum = std::accumulate(m_times.begin(), m_times.end(),
                (uint64_t)0, [cur_time](const uint64_t previous,
                const std::tuple<uint32_t, uint64_t, uint64_t>& b)->uint64_t
                {
                    return previous + (uint64_t)(std::get<0>(b) / 2) +
                        std::get<1>(b) + cur_time - std::get<2>(b);
                });
            const int64_t averaged_time = sum / 20;
            const int64_t server_time_now = server_time + (uint64_t)(ping / 2);
            int difference = (int)std::abs(averaged_time - server_time_now);
            if (std::abs(averaged_time - server_time_now) <
                UserConfigParams::m_timer_sync_difference_tolerance)
            {
                STKHost::get()->setNetworkTimer(averaged_time);
                m_times.clear();
                m_force_set_timer.store(false);
                m_synchronised.store(true);
                Log::info("NetworkTimerSynchronizer", "Network "
                    "timer synchronized, difference: %dms", difference);
                return;
            }
            m_times.erase(m_times.begin(), m_times.begin() + 10);
        }
        m_times.emplace_back(ping, server_time, cur_time);
    }
开发者ID:supertuxkart,项目名称:stk-code,代码行数:53,代码来源:network_timer_synchronizer.hpp

示例3:

/**
 * Start the IPC thread.
 */
void
ipcStart()
{
   std::unique_lock<std::mutex> lock { sIpcMutex };
   sIpcThreadRunning.store(true);
   sIpcThread = std::thread { ipcThreadEntry };
}
开发者ID:SakataGintokiYT,项目名称:decaf-emu,代码行数:10,代码来源:kernel_ipc.cpp

示例4: WndProc

LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    WindowEvent params = {};
    params.hWnd = hWnd;
    params.msg = msg;
    params.wParam = wParam;
    params.lParam = lParam;

    s_queue->Enqueue(params);

    switch (msg)
    {
    case WM_SIZE:
        if (g_renderApi && wParam != SIZE_MINIMIZED) {
            g_renderApi->Resize((int32_t) LOWORD(lParam), (int32_t) HIWORD(lParam));
            return 0;
        }
        break;
    case WM_SYSCOMMAND:
        if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
            return 0;
        break;
    case WM_DESTROY:
        s_running.store(false);
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProcW(hWnd, msg, wParam, lParam);
}
开发者ID:darkedge,项目名称:starlight,代码行数:28,代码来源:starlight_win32.cpp

示例5:

			progressIndicatorThreadWrapper( const std::chrono::nanoseconds& updateInterval )
			{
				m_stopCondition.store( false );
				
				m_thread = std::thread( [this, &updateInterval]
										{
											FormattedPrint::On(std::cout, false).app("    ");
											
											int slashIndex = 0;

											while( ! m_stopCondition.load() )
											{
												FormattedPrint::On(std::cout, false).app("\b\b\b \b")
																					.color( Green )
																					.app('[')
																					.color( Yellow )
																					.app( slashes[ slashIndex++ ] )
																					.color( Green )
																					.app(']')
																					.color();

												slashIndex = slashIndex % 4;

												std::this_thread::sleep_for( updateInterval );
											}

											FormattedPrint::On(std::cout, false).app("\b\b\b");
										});
			}
开发者ID:R3AL,项目名称:PackageManager,代码行数:29,代码来源:ProgressIndicator.hpp

示例6: operator

        /**
          * This is the actual function that the thread executes.
          * It receives a block from the scheduler, class its run() method and returns it to the scheduler.
          * The thread runs until the it is told to stop by setting the m_stop boolean flag
          */
        void operator()()
        {
            if(CPU_COUNT(&m_mask)>0)
            {
                pthread_t id = pthread_self();
               int ret = pthread_setaffinity_np(id, sizeof(m_mask), &m_mask);
                if(ret != 0)
                {
                    perror("setaffinity");
                    throw(std::runtime_error("set affinity failed"));
                }
            }
            while(!m_stop.load())
            {

                std::shared_ptr<Block>torun(m_scheduler.next_task(m_id));
                if(torun)
                {
                    torun->run();
                    m_scheduler.task_done(m_id, std::move(torun));
                }
                else
                {
                    std::this_thread::sleep_for(std::chrono::milliseconds(10));
                }
            }
            m_stop.store(false);
        }
开发者ID:netgroup,项目名称:dstreamon,代码行数:33,代码来源:ThreadHandler.hpp

示例7: init

bool init(const char* pipeline, core::c_window *window, bool validation) {
    VERIFY(graphics::render3d::resources::load_pipeline(pipeline));

    VERIFY(create_instance("appname"));
    VERIFY(create_surface(window));
    VERIFY(create_device());
    VERIFY(create_device_queue());
    VERIFY(graphics::render3d::resources::create_pipeline());

    vk_globals::is_init = true;

    flag_needs_recreate_swapchain.store(false);
    flag_needs_shutdown.store(false);

    on_window_resize_listener = window->add_event_listener(core::e_window_event::ON_RESIZE, on_window_resize);

    return true;
}
开发者ID:avpdiver,项目名称:gladius,代码行数:18,代码来源:render3d.cpp

示例8: disconnect

	void disconnect() {
		connected.store(false);
		closesocket(sock);

		sender.join();
		recver.join();

		send_queue.clear();
		recv_queue.clear();
	}
开发者ID:killgxlin,项目名称:boost_network,代码行数:10,代码来源:new_client.cpp

示例9:

	~WorkerThreads()
	{
		_shutdownFlag.store(true);

		_cache.setShutdownFlag();

		for (auto worker : _workers)
		{
			worker->join();
			delete worker;
		}
	}
开发者ID:Yukigaru,项目名称:RJCache,代码行数:12,代码来源:main.cpp

示例10: lock

void
handleDbgBreakInterrupt()
{
   // If we are not initialised, we should ignore DbgBreaks
   if (!decaf::config::debugger::enabled) {
      return;
   }

   std::unique_lock<std::mutex> lock(sMutex);
   auto coreId = cpu::this_core::id();

   // Store our core state before we flip isPaused
   sCorePauseState[coreId] = cpu::this_core::state();

   // Check to see if we were the last core to join on the fun
   auto coreBit = 1 << coreId;
   auto isPausing = sIsPausing.fetch_or(coreBit);

   if (isPausing == 0) {
      // This is the first core to hit a breakpoint
      sPauseInitiatorCoreId = coreId;

      // Signal the rest of the cores to stop
      for (auto i = 0; i < 3; ++i) {
         cpu::interrupt(i, cpu::DBGBREAK_INTERRUPT);
      }
   }

   if ((isPausing | coreBit) == (1 | 2 | 4)) {
      // This was the last core to join.
      sIsPaused.store(true);
      sIsPausing.store(0);
      sIsResuming.store(0);
   }

   // Spin around the release condition while we are paused
   while (sIsPausing.load() || sIsPaused.load()) {
      sPauseReleaseCond.wait(lock);
   }

   // Clear any additional DbgBreaks that occured
   cpu::this_core::clearInterrupt(cpu::DBGBREAK_INTERRUPT);

   // Everyone needs to leave at once in case new breakpoints occur.
   if ((sIsResuming.fetch_or(coreBit) | coreBit) == (1 | 2 | 4)) {
      sPauseReleaseCond.notify_all();
   } else {
      while ((sIsResuming.load() | coreBit) != (1 | 2 | 4)) {
         sPauseReleaseCond.wait(lock);
      }
   }
}
开发者ID:achurch,项目名称:decaf-emu,代码行数:52,代码来源:debugger.cpp

示例11: swap_queues

 void swap_queues()
 {
     for(unsigned int i=0; i<m_full_slots; ++i)
     {
         m_queues[m_consumer_q].vec[i].valid.store(false,std::memory_order_release);
     }
     unsigned int newpoint=m_consumer_q<<30;
     m_consumer_q=exchange_queue(m_consumer_q);
     unsigned int old_pointer=m_pointer.exchange(newpoint,std::memory_order_release);
     m_full.store(false,std::memory_order_release);
     old_pointer&=~MASK;
     m_full_slots=std::min(old_pointer,Qlen);
     m_read=0;
 }
开发者ID:cnplab,项目名称:blockmon,代码行数:14,代码来源:DBQueue.hpp

示例12: _tWinMain

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
#ifdef _DEBUG	// ATLTRACEで日本語を使うために必要
	_tsetlocale(LC_ALL, _T("japanese"));
#endif

	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	FILE* fp_out = freopen("result.txt", "w", stdout);

	g_atomicMegaThreadActive.store(true);
	std::thread threadMegaLoop(CMegaAppImpl::StartMegaLoop);

	int nRet = Run(lpstrCmdLine, nCmdShow);

	g_atomicMegaThreadActive.store(false);
	threadMegaLoop.join();

	fclose(fp_out);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
开发者ID:amate,项目名称:MegaOneWaySync,代码行数:37,代码来源:DriveSync.cpp

示例13: main

int main() {
    /* Handle Signals */
    std::signal(SIGTERM, cleanup);
    std::signal(SIGINT , cleanup);
    std::signal(SIGABRT, cleanup);

    std::thread sw{stopwatch};

    while(true) {
        if(std::getchar() != '\x03') /* ctrl+c */
            lap.store(true);
    }

    return 0;
}
开发者ID:tclamb,项目名称:Tests,代码行数:15,代码来源:Stopwatch.cpp

示例14: while

/**
 * Main thread entry point for the IPC thread.
 *
 * This thread represents the IOS side of the IPC mechanism.
 *
 * Responsible for receiving IPC requests and dispatching them to the
 * correct IOS device.
 */
void
ipcThreadEntry()
{
   std::unique_lock<std::mutex> lock { sIpcMutex };

   while (true) {
      if (!sIpcRequests.empty()) {
         auto request = sIpcRequests.front();
         sIpcRequests.pop();
         lock.unlock();
         iosDispatchIpcRequest(request);
         lock.lock();

         switch (request->cpuId) {
         case IOSCpuId::PPC0:
            sIpcResponses[0].push(request);
            cpu::interrupt(0, cpu::IPC_INTERRUPT);
            break;
         case IOSCpuId::PPC1:
            sIpcResponses[1].push(request);
            cpu::interrupt(1, cpu::IPC_INTERRUPT);
            break;
         case IOSCpuId::PPC2:
            sIpcResponses[2].push(request);
            cpu::interrupt(2, cpu::IPC_INTERRUPT);
            break;
         default:
            decaf_abort("Unexpected cpu id");
         }
      }

      if (!sIpcThreadRunning.load()) {
         break;
      }

      if (sIpcRequests.empty()) {
         sIpcCond.wait(lock);
      }
   }

   sIpcThreadRunning.store(false);
}
开发者ID:SakataGintokiYT,项目名称:decaf-emu,代码行数:50,代码来源:kernel_ipc.cpp

示例15: main

int main( int argc, char **argv ) {

    auto map = std::make_shared<concurrent::map>();

    auto key = "foo";

    auto t1 = std::thread( producer, map, key, "thread1" );
    auto t2 = std::thread( producer, map, key, "thread2" );

    auto t3 = std::thread( consumer, map, key );

    std::this_thread::sleep_for( std::chrono::seconds( 2 ) );

    g_is_done.store( true );

    t1.join();
    t2.join();

    t3.join();

    return EXIT_SUCCESS;
}
开发者ID:VarLog,项目名称:concurrent_map,代码行数:22,代码来源:main.cpp


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