void write_x() {
    x.store(true, std::memory_order_release);
}
Example #2
0
void write_y()
{
    y.store(true, std::memory_order_seq_cst);
}
	void unlock()
	{
		locked.store(0, std::memory_order_release);
	}
Example #4
0
void Hook::loop(Hook::Hid::HidControllerDevice &realD, Hook::Scp::VirtualDevice &vjd)
{
	auto mapper(Remapper::create(Remapper::DEFAULT_PATH));

	bool hasProcList(Config::get()->hasProcessList());
	const auto &procList(Config::get()->getProcessList());

	bool suicide(hasProcList ? Config::get()->shouldEndOnGameProcDeath() : false);
	std::thread worker;

	HOOK_TCHARSTR activeProc(HOOK_TCHARIFY(Remapper::DEFAULT_PATH));

	if (!hasProcList)
	{
		std::cout << "\nSetup successful! Beginning controller translation. Press CTRL + END to quit. Press CTRL + HOME to re-read button mappings." << std::endl;
	}
	else
	{
		std::cout << "\nSetup successful! Awaiting game startup... Press CTRL + SHIFT + END to quit." << std::endl;
		auto procIter(procWaitLoop(procList));

		if (procIter == procList.cend())
		{
			return;
		}

		activeProc = *procIter;
		HOOK_TCHAROUT << "Detected startup of " << activeProc << "." << std::endl;

		mapper = Remapper::create(activeProc);

		std::wcout << "Beginning controller translation. Press CTRL + END to quit. Press CTRL + HOME to re-read button mappings." << std::endl;

		worker = std::thread(processCheckerThreadLoop, activeProc);
	}

	for (;;)
	{
		std::this_thread::sleep_for(std::chrono::milliseconds(1));

		realD.pullData();

		auto state(realD.parseData());

		mapper.remap(state);

		vjd.feed(state);

		if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_HOME))
		{
			std::cout << "Re-reading button mappings from file...\n";
			Remapper::reread(activeProc, mapper);
		}
		if (GetAsyncKeyState(VK_END) && GetAsyncKeyState(VK_CONTROL))
		{
			earlyDie.store(true);

			cleanupThread(worker);

			if (hasProcList)
			{
				goto rewait;
			}
			break;
		}
		else if (hasProcList && earlyDie.load())
		{
			if (suicide)
			{
				cleanupThread(worker);
				std::cout << "Game process ended. Terminating controller translation and quitting." << std::endl;
				break;
			}

			std::cout << "Game process ended. Terminating controller translation." << std::endl;

		rewait:
			cleanupThread(worker);

			std::cout << "Awaiting game startup... Press CTRL + SHIFT + END to quit." << std::endl;

			auto procIter(procWaitLoop(procList));

			if (procIter == procList.cend())
			{
				break;
			}

			activeProc = *procIter;
			mapper = Remapper::create(activeProc);

			earlyDie.store(false);
			worker = std::thread(processCheckerThreadLoop, *procIter);
		}
	}
}
Example #5
0
 ~TrueAtExit() {
    flag->store(true);
 }
 /** reset the ringbuffer
  *
  * \note Not thread-safe
  * */
 void reset(void)
 {
     write_index_.store(0, std::memory_order_relaxed);
     read_index_.store(0, std::memory_order_release);
 }
Example #7
0
void HiresTexture::Update()
{
	s_check_native_format = false;
	s_check_new_format = false;

	if (s_prefetcher.joinable())
	{
		s_textureCacheAbortLoading.Set();
		s_prefetcher.join();
	}

	if (!g_ActiveConfig.bHiresTextures)
	{
		s_textureMap.clear();
		s_textureCache.clear();
		size_sum.store(0);
		return;
	}

	if (!g_ActiveConfig.bCacheHiresTextures)
	{
		s_textureCache.clear();
		size_sum.store(0);
	}
	
	s_textureMap.clear();
	const std::string& gameCode = SConfig::GetInstance().m_strUniqueID;
	std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());	
	std::string ddscode(".dds");
	std::string cddscode(".DDS");
	std::vector<std::string> Extensions = {
		".png",
		".dds"
	};

	auto rFilenames = DoFileSearch(Extensions, { szDir }, /*recursive*/ true);

	const std::string code = StringFromFormat("%s_", gameCode.c_str());
	const std::string miptag = "mip";
	const std::string normaltag = ".nrm";
	for (u32 i = 0; i < rFilenames.size(); i++)
	{
		std::string FileName;
		std::string Extension;
		SplitPath(rFilenames[i], nullptr, &FileName, &Extension);
		if (FileName.substr(0, code.length()) == code)
		{
			s_check_native_format = true;
		}
		else if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix)
		{
			s_check_new_format = true;
		}
		else
		{
			// Discard wrong files
			continue;
		}
		const bool is_compressed = Extension.compare(ddscode) == 0 || Extension.compare(cddscode) == 0;
		const bool is_normal_map = hasEnding(FileName, normaltag);
		if (is_normal_map)
		{
			FileName = FileName.substr(0, FileName.size() - normaltag.size());
		}
		hires_mip_level mip_level_detail(rFilenames[i], Extension, is_compressed);
		u32 level = 0;
		size_t idx = FileName.find_last_of('_');
		std::string miplevel = FileName.substr(idx + 1, std::string::npos);
		if (miplevel.substr(0, miptag.length()) == miptag)
		{
			sscanf(miplevel.substr(3, std::string::npos).c_str(), "%i", &level);
			FileName = FileName.substr(0, idx);
		}
		HiresTextureCache::iterator iter = s_textureMap.find(FileName);
		u32 min_item_size = level + 1;
		if (iter == s_textureMap.end())
		{
			HiresTextureCacheItem item(min_item_size);
			if (is_normal_map)
			{
				item.normal_map.resize(min_item_size);
			}
			std::vector<hires_mip_level> &dst = is_normal_map ? item.normal_map : item.color_map;
			dst[level] = mip_level_detail;
			s_textureMap.emplace(FileName, item);
		}
		else
		{
			std::vector<hires_mip_level> &dst = is_normal_map ? iter->second.normal_map : iter->second.color_map;
			if (dst.size() < min_item_size)
			{
				dst.resize(min_item_size);
			}
			dst[level] = mip_level_detail;
		}
	}

	if (g_ActiveConfig.bCacheHiresTextures && s_textureMap.size() > 0)
	{
		// remove cached but deleted textures
		auto iter = s_textureCache.begin();
		while (iter != s_textureCache.end())
		{
			if (s_textureMap.find(iter->first) == s_textureMap.end())
			{
				size_sum.fetch_sub(iter->second->m_cached_data_size);
				iter = s_textureCache.erase(iter);
			}
			else
			{
				iter++;
			}
		}
		s_textureCacheAbortLoading.Clear();
		s_prefetcher = std::thread(Prefetch);
	}
}
Example #8
0
 void unlock() noexcept {
     state_.store( spinlock_status::unlocked, std::memory_order_release);
 }
 void unlock() noexcept {
     if ( 1 != value_.fetch_sub( 1, std::memory_order_acquire) ) {
         value_.store( 0, std::memory_order_release);
         futex_wake( & value_);
     }
 }
void test_apply_with_executor(Executor& exec)
{
    accumulator.store(0);

    {
        using hpx::util::placeholders::_1;

        hpx::apply(exec, &increment, 1);
        hpx::apply(exec, hpx::util::bind(&increment, 1));
        hpx::apply(exec, hpx::util::bind(&increment, _1), 1);
    }

    {
        hpx::promise<std::int32_t> p;
        hpx::shared_future<std::int32_t> f = p.get_future();

        p.set_value(1);

        using hpx::util::placeholders::_1;

        hpx::apply(exec, &increment_with_future, f);
        hpx::apply(exec, hpx::util::bind(&increment_with_future, f));
        hpx::apply(exec, hpx::util::bind(&increment_with_future, _1), f);
    }

    {
        using hpx::util::placeholders::_1;

        hpx::apply(exec, increment, 1);
        hpx::apply(exec, hpx::util::bind(increment, 1));
        hpx::apply(exec, hpx::util::bind(increment, _1), 1);
    }

    {
        increment_type inc;

        using hpx::util::placeholders::_1;
        using hpx::util::placeholders::_2;

        hpx::apply(exec, &increment_type::call, inc, 1);
        hpx::apply(exec, hpx::util::bind(&increment_type::call, inc, 1));
        hpx::apply(exec, hpx::util::bind(&increment_type::call, inc, _1), 1);
    }

    {
        increment_function_object obj;

        using hpx::util::placeholders::_1;
        using hpx::util::placeholders::_2;

        hpx::apply(exec, obj, 1);
        hpx::apply(exec, hpx::util::bind(obj, 1));
        hpx::apply(exec, hpx::util::bind(obj, _1), 1);
    }

    {
        using hpx::util::placeholders::_1;
        using hpx::util::placeholders::_2;

        hpx::apply(exec, increment_lambda, 1);
        hpx::apply(exec, hpx::util::bind(increment_lambda, 1));
        hpx::apply(exec, hpx::util::bind(increment_lambda, _1), 1);
    }

    hpx::lcos::local::no_mutex result_mutex;
    std::unique_lock<hpx::lcos::local::no_mutex> l(result_mutex);
    result_cv.wait_for(l, std::chrono::seconds(1),
        hpx::util::bind(std::equal_to<std::int32_t>(),
            std::ref(accumulator), 18));

    HPX_TEST_EQ(accumulator.load(), 18);
}
Example #11
0
File: main.cpp Project: CCJY/coliru
void producer()
{
    std::string* p  = new std::string("Hello");
    data = 42;
    ptr.store(p, std::memory_order_release);
}
Example #12
0
	/* A method run in a backround thread, to keep filling the queue with new
	 * audio over time.
	 */
	void backgroundProc()
	{
		/* Temporary storage to read samples into, before passing to OpenAL.
		 * Kept here to avoid reallocating it during playback.
		 */
		std::vector<char> buffer(sBufferFrames * mFrameSize);

		while (!mQuit.load())
		{
			/* First, make sure the buffer queue is filled. */
			fillBufferQueue(buffer);

			ALint state;
			alGetSourcei(mSource, AL_SOURCE_STATE, &state);
			if (state != AL_PLAYING && state != AL_PAUSED)
			{
				/* If the source is not playing or paused, it either underrun
				 * or hasn't started at all yet. So remove any buffers that
				 * have been played (will be 0 when first starting).
				 */
				ALint processed;
				alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
				while (processed > 0)
				{
					ALuint bufid;
					alSourceUnqueueBuffers(mSource, 1, &bufid);
					--processed;
				}

				/* Make sure the buffer queue is still filled, in case another
				 * buffer had finished before checking the state and after the
				 * last fill. If the queue is empty, playback is over.
				 */
				if (fillBufferQueue(buffer) == 0)
				{
					mQuit.store(true);
					return;
				}

				/* Now start the sound source. */
				alSourcePlay(mSource);
			}

			ALint processed;
			alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
			if (processed == 0)
			{
				/* Wait until a buffer in the queue has been processed. */
				do {
					std::this_thread::sleep_for(std::chrono::milliseconds(50));
					if (mQuit.load()) break;
					alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
				} while (processed == 0);
			}
			/* Remove processed buffers, then restart the loop to keep the
			 * queue filled.
			 */
			while (processed > 0)
			{
				ALuint bufid;
				alSourceUnqueueBuffers(mSource, 1, &bufid);
				--processed;
			}
		}
	}
Example #13
0
// tick signal handler
void Ticked()
{
    hasTicked_.store(true);
    ++numTicked_;
    ticked_.notify_all();              
}
Example #14
0
int hpx_main()
{
    // count_down_and_wait
    {
        hpx::lcos::local::latch l(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));

        HPX_TEST(!l.is_ready());

        // Wait for all threads to reach this point.
        l.count_down_and_wait();

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // count_down
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        hpx::future<void> f = hpx::async(&test_count_down, std::ref(l));

        HPX_TEST(!l.is_ready());
        l.count_down_and_wait();

        f.get();

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), std::size_t(1));
    }

    // wait
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(NUM_THREADS);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i)
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));

        hpx::wait_all(results);

        l.wait();

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // count_up
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
            l.count_up(1);
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
        }

        HPX_TEST(!l.is_ready());

        // Wait for all threads to reach this point.
        l.count_down_and_wait();

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    // reset
    {
        num_threads.store(0);

        hpx::lcos::local::latch l(0);
        l.reset(NUM_THREADS+1);
        HPX_TEST(!l.is_ready());

        std::vector<hpx::future<void> > results;
        for (std::ptrdiff_t i = 0; i != NUM_THREADS; ++i){
            results.push_back(hpx::async(&test_count_down_and_wait, std::ref(l)));
        }

        HPX_TEST(!l.is_ready());

        // Wait for all threads to reach this point.
        l.count_down_and_wait();

        hpx::wait_all(results);

        HPX_TEST(l.is_ready());
        HPX_TEST_EQ(num_threads.load(), NUM_THREADS);
    }

    HPX_TEST_EQ(hpx::finalize(), 0);
    return 0;
}
void write_x()
{
	// x.store(true, std::memory_order_seq_cst);
	// x.store(true, std::memory_order_release);
	x.store(true, std::memory_order_relaxed);
}
Example #16
0
 void SetFixedRandomSeed(unsigned long fixedRandomSeed)
 {
     s_fixedRandomSeed.store(fixedRandomSeed);
 }
Example #17
0
 chase_lev_deque() : buf(NULL), bottom(0l), top(0l) {
   capacity.store(0l);
 }
void write_x_then_y()
{
    x.store(true,std::memory_order_relaxed);
    std::atomic_thread_fence(std::memory_order_release);
    y.store(true,std::memory_order_relaxed);
}
void writing(){  
  x.store(2000);  
  y.store(11);
}
Example #20
0
 void commit(int n) {
     m_count.store(n, std::memory_order_relaxed);
 }
void setNotSynchronized()
{
    isSynchronized.store(false, std::memory_order_release);
}
Example #22
0
        REQUIRE(expr);\
    }

TEST_CASE("Connect and disconnect from local host", "[Host]")
{
    std::atomic<bool> listening;
    listening.store(false);

    std::thread server_thread([&]
    {
        bool connect_event = false;
        bool disconnect_event = false;

        Host host(_maxPeerCount, _channelCount, _port);

        listening.store(true);

        while (true)
        {
            PeerEvent event;
            if (host.poll_event(event))
            {
                if (event.type == PeerEventType::Connect)
                {
                    connect_event = true;
                }
                else if (event.type == PeerEventType::Disconnect)
                {
                    disconnect_event = true;
                    break;
                }
Example #23
0
 explicit TrueAtExit(std::atomic<bool>* f) : flag(f) {
    flag->store(false);
 }
Example #24
0
void ReloadInputDevicesRST() {
    is_device_reload_pending.store(true);
}
Example #25
0
 void reset() {
     signal_counter.store(0, std::memory_order_relaxed);
 }
Example #26
0
 void unlock() {
     m_lock.store(to_underlying(lock_state::UNLOCKED), std::memory_order_relaxed);
 }
Example #27
0
void write_x()
{
    x.store(true, std::memory_order_seq_cst);
}
Example #28
0
 void reset(long val = 1) {
     m_count.store(val, std::memory_order_release);
 }
Example #29
0
 void    set_terminate_flag(bool state)
 {
     terminated_flag_.store(state);
 }
void write_y() {
    y.store(true, std::memory_order_release);
}