Exemplo n.º 1
0
 inline void
 lock()
 {
     while (m_spin.exchange(true)) {
         if (yield) {
             std::this_thread::yield();
         }
     }
 }
Exemplo n.º 2
0
 ~ThreadPool() {
     stoped.exchange(true);
     for (auto& cond: thread_cond) {
         cond.notify_one();
     }
     for (auto& worker : workers) {
         if (worker.joinable()) worker.join();
     }
 }
Exemplo n.º 3
0
void
resumeAll()
{
   auto oldState = sIsPaused.exchange(false);
   decaf_check(oldState);
   for (auto i = 0; i < 3; ++i) {
      sCorePauseState[i] = nullptr;
   }
   sPauseReleaseCond.notify_all();
}
Exemplo n.º 4
0
/**
 * Stop the IPC thread.
 */
void
ipcShutdown()
{
   std::unique_lock<std::mutex> lock { sIpcMutex };

   if (sIpcThreadRunning.exchange(false)) {
      sIpcCond.notify_all();
      lock.unlock();

      sIpcThread.join();
   }
}
Exemplo n.º 5
0
void stopwatch() {
    /* Setup Terminal */
    std::cout << hide_cursor << std::setfill('0');
    setup_terminal();

    auto start    = std::chrono::high_resolution_clock::now();
    using jiffies = std::chrono::duration<int, std::centi>;

    while(!die) {
        auto delta = std::chrono::duration_cast<jiffies>(
            std::chrono::high_resolution_clock::now() - start
            ).count();

        auto cs = delta%100;
        auto s = delta/100;
        auto m = s/60; s %= 60;
        auto h = m/60; m %= 60;

        std::cout << to_first_column
            << std::setw(2) << h << ':'
            << std::setw(2) << m << ':'
            << std::setw(2) << s << '.'
            << std::setw(2) << cs
            << std::flush;

        if(lap.exchange(false)) {
            std::cout << std::endl;
        }
        
        /* justification: something about Nyquist frequencies, etc.
         * don't want to thrash my CPU to death */
        std::this_thread::sleep_for(std::chrono::milliseconds{4});
    }

    /* Reset Terminal */
    reset_terminal();
    std::cout << show_cursor << std::endl;
    std::exit(0);
}
Exemplo n.º 6
0
void Ozette::run() {
	if (_editors.empty()) show_browser();
	timeout(100);
	do {
		if (sig_io_flag.exchange(false)) {
			_shell.poll();
		}
		int ch = fix_control_quirks(getch());
		switch (ch) {
			case Control::UpArrow: show_browser(); break;
			case Control::NewFile: new_file(); break;
			case Control::Open: open_file(); break;
			case Control::Directory: change_directory(); break;
			case Control::Help: show_help(); break;
			case Control::Execute: execute(); break;
			case KEY_F(4): search(); break;
			case KEY_F(5): build(); break;
			default: _done |= !_shell.process(ch);
		}
		update_panels();
		doupdate();
	} while (!_done);
}