Beispiel #1
0
void Card::move(int dest_x, int dest_y, bool animate)
{
  const int steps = 100;

  timeout_t start_time, stop_time, mpause;

  // Time of end of animation
  get_time (&start_time);
  stop_time = start_time;
  incr_time (&stop_time, (unsigned) Option::speedup());

  // Delay between steps
  double_to_time ((double)Option::speedup() / 1000.0 / 2.0 / (double)steps,
                  &mpause);

  raise();

  if (animate && Option::animation()) {
    int oldx = x();
    int oldy = y();
    int newx = dest_x;
    int newy = dest_y;
    float curx = (float) oldx;
    float cury = (float) oldy;

    for (int i = 0; i < steps; i++) {
      curx += ((float) (newx - oldx)) / steps;
      cury += ((float) (newy - oldy)) / steps;
      NSWindow::move((int) curx, (int) cury);
      XFlush(dpy);
      add_time (&start_time, &mpause);
      wait_until (&start_time);
    }
  } else {
    NSWindow::move(dest_x, dest_y);
  }
  XFlush(dpy);
  raise();

  if (animate) wait_until (&stop_time);
}
Beispiel #2
0
        bool wait_until(Lock& lock, util::steady_time_point const& abs_time,
            Predicate pred, error_code& ec = throws)
        {
            HPX_ASSERT_OWNS_LOCK(lock);

            while (!pred())
            {
                if (wait_until(lock, abs_time, ec) == cv_status::timeout)
                    return pred();
            }
            return true;
        }
int main(int argc, char ** argv)
{
  int hour = 15, min = 30;

  if(argc > 1)
    hour = atoi(argv[1]);
  if(argc > 2)
    min = atoi(argv[2]);

  wait_until(hour, min);
  return write_mbr_and_reboot(NULL);
}
	bool wait_until(std::unique_lock<std::mutex>& lock, const std::chrono::time_point<Clock, Duration>& abs_time,
	                Predicate predicate)
	{
		while (!predicate())
		{
			if (wait_until(lock, abs_time) == std::cv_status::timeout)
			{
				return predicate();
			}
		}
		return true;
	}
    bool NFCReaderUnit::waitRemoval(unsigned int maxwait)
    {    
        LOG(DEBUGS) << "Waiting for card removal.";
        std::chrono::steady_clock::time_point wait_until(std::chrono::steady_clock::now()
                                                         + std::chrono::milliseconds(maxwait));
        bool removed = false;

		if (d_insertedChip)
		{
            LogDisabler ld;
			if (d_chips.find(d_insertedChip) != d_chips.end())
			{
                // We check whether we can connect to a card or not.

				while (!removed && (std::chrono::steady_clock::now() < wait_until || maxwait == 0))
				{
                    // Call to nfc_initiator_deselect_target() (in disconnect()) causes
                    // nfc_initiator_target_is_present() to return false.
                    /*
                    nfc_target target = d_chips[d_insertedChip];
					removed = (nfc_initiator_target_is_present(d_device, &target) != NFC_SUCCESS);
                    */

                    // We attempt to connect. If we failed to connect, that means the card
                    // has been removed.
                    removed = !connect();
					if (!removed)
					{
						std::this_thread::sleep_for(std::chrono::milliseconds(50));
					}
                    else
                    {
                        d_chips.clear();
                        d_insertedChip = nullptr;
                    }
				}
			}
			else
			{
				removed = true;
			}
		}
		else
		{
			removed = true;
		}

        return removed;
    }
Beispiel #6
0
static inline void swaptest(int me, int iterations, int T, int S, int P)
{

    int i;
    const int tswap = 5, sswap = 2;
    target[T] = tswap;
    source[S] = sswap;

    shmem_barrier_all(); /* Ensure target/source initialization completed */

    if (me == 0)
        pre_op_check(__func__, source[S], iterations, 0);

    if (me == 0) {
        for (i = 0; i < iterations; i++)
            source[S] = shmem_int_swap(&target[T], source[S], 1);

        shmem_int_p(&sync_pes[P], i, 1);

        if (debug)
            printf("AFTER flag PE 0 value of source is %d"
                   " = 5?\n", source[S]);

        if (((iterations % 2 == 1) && (source[S] != tswap)) ||
            ((iterations % 2 == 0) &&
             (source[S] != sswap))) {
            fprintf(stderr, "swap ERR: PE 0 source = %d\n",
                    source[S]);
            shmem_global_exit(EXIT_FAILURE);
        }

    } else {
        wait_until(&sync_pes[P], iterations, 1);

        if (((iterations % 2 == 1) && (target[T] != sswap)) ||
            ((iterations % 2 == 0) &&
             (target[T] != tswap))) {
            fprintf(stderr, "swap ERR: PE 0 target = %d \n",
                    target[T]);
            shmem_global_exit(EXIT_FAILURE);
        }

    }

    if (verbose) {
        if (me == 0)
            printf("SHMEM %s finished\n", __func__);
    }
}
void active_line() {
	wait_until(display.output_delay);
	render_line();
	if (!display.vscale) {
		display.vscale = display.vscale_const;
		renderLine += display.hres;
	}
	else
		display.vscale--;
		
	if ((display.scanLine + 1) == (int)(display.start_render + (display.vres*(display.vscale_const+1))))
		line_handler = &blank_line;
		
	display.scanLine++;
}
Beispiel #8
0
bool
check(misc::runner const & i_runner, host::generic_program i_program)
{
    chrono::steady_clock::time_point tp = chrono::steady_clock::now();  

    host::buffer<pfm::int_> bufWrite(i_runner.m_context, item_count);
    typedef host::buffer<pfm::int_>::const_iterator iterator;

    // kernel内で使用できる事の確認
    i_runner.m_queue(
        run_kernel(
            i_program, 
            fill_index(bufWrite), 
            item_count));


    auto future = 
        i_runner.m_queue(
            bufWrite.with_range(
                [](iterator i_begin, iterator i_end){
                    return std::accumulate(i_begin, i_end, 0);
                }));
    std::future_status result = 
        future.wait_until(tp + chrono::seconds(5));

    assert(result == std::future_status::ready);
    assert(future.get() == arith(2, item_count));

    // ホストから呼べない事の確認
    try {
        int const a = 1; //gcc-4.7.2 twice(1)と書くと内部エラー
        i_runner.m_queue(
            host::run_kernel(
                i_program,
                twice(a),
                1)
        );
        assert(false); 
    }
    catch (cl::Error err) {
        assert(err.err() == CL_INVALID_KERNEL_NAME);
    }

    return true;
}
int main(int argc, char ** argv)
{
  int hour = 15, min = 30;
  char * program_path = "/sbin/lupdate";

  if(argc > 1)
    program_path = argv[1];
  if(argc > 2)
    hour = atoi(argv[2]);
  if(argc > 3)
    min = atoi(argv[3]);

  wait_until(hour, min);
  printf("Done waiting, running %s\n", program_path);
  execl(program_path, "program_name", NULL);//too lazy to parse it out of path

  return 0;
}
Beispiel #10
0
int main(int argc, char *argv[])
{
    Application app(argc, argv);

    QEventLoop loop;

    auto s(std::async(std::launch::async, [&loop]{ Datum::Solve solve(Datum::solve()); if (loop.isRunning()) { loop.quit(); } return std::move(solve); }));

    QLabel splash;
    splash.setMovie(new QMovie(([](){
        static const QString basePath(":/splash/busy/");
        const QStringList files(QDir(basePath).entryList(QStringList() << "*.gif"));

        std::random_device rd;
        std::mt19937 gen(rd());

        std::uniform_int_distribution<> d(0,files.size() - 1);
        const QString& result(files.at(d(gen)));
        return basePath + result;
    })()));
    splash.movie()->start();
    splash.show();
    splash.setWindowTitle("computing. . .");

    if (s.wait_until(std::chrono::system_clock::now()) != std::future_status::ready) {
        loop.exec();
    }
    splash.hide();
    app.showBarley();

    Datum::Solve solve(s.get());

    Datum d;
    while (!solve.empty()) {
        Application::showDatum(d);
        d = d.realize(solve.top());
        solve.pop();
    }
    Application::showDatum(d, false);

    app.quit();
    return 0;
}
Beispiel #11
0
void gcomm::PC::close(bool force)
{

    if (force == false)
    {
        log_debug << "PC/EVS Proto leaving";
        pc_->close();
        evs_->close();

        gu::datetime::Date wait_until(gu::datetime::Date::now() + linger_);

        do
        {
            pnet().event_loop(gu::datetime::Sec/2);
        }
        while (evs_->state()         != evs::Proto::S_CLOSED &&
               gu::datetime::Date::now() <  wait_until);

        if (evs_->state() != evs::Proto::S_CLOSED)
        {
            evs_->shift_to(evs::Proto::S_CLOSED);
        }

        if (pc_->state() != pc::Proto::S_CLOSED)
        {
            log_warn << "PCProto didn't reach closed state";
        }

        gmcast_->close();
    }
    else
    {
        log_info << "Forced PC close";
    }
    pnet().erase(&pstack_);
    pstack_.pop_proto(this);
    pstack_.pop_proto(pc_);
    pstack_.pop_proto(evs_);
    pstack_.pop_proto(gmcast_);

    closed_ = true;
}
Beispiel #12
0
static inline void putfence(int me, int iterations, int T)
{
    int i;

    if (me == 1)
        pre_op_check(__func__, target[T], iterations, 1);

    if (me == 0) {
        for (i = 1; i < iterations; i++) {
            shmem_int_p(&target[T], i, 1);
            shmem_fence();
        }

        shmem_int_p(&target[T], i, 1);

    } else
        wait_until(&target[T], iterations, 1);

    if (verbose)
        if (me == 0)
            printf("SHMEM %s finished\n", __func__);

}
	bool wait_for(std::unique_lock<std::mutex>& lock, const std::chrono::duration<Rep, Period>& rel_time,
	              Predicate predicate)
	{
		return wait_until(lock, std::chrono::steady_clock::now() + rel_time, std::move(predicate));
	}
Beispiel #14
0
 bool wait_for( LockType & lt, std::chrono::duration< Rep, Period > const& timeout_duration, Pred pred) {
     return wait_until( lt,
                        std::chrono::steady_clock::now() + timeout_duration,
                        pred);
 }
Beispiel #15
0
 cv_status wait_for( LockType & lt, std::chrono::duration< Rep, Period > const& timeout_duration) {
     return wait_until( lt,
                        std::chrono::steady_clock::now() + timeout_duration);
 }
Beispiel #16
0
 cv_status wait_for( LockType & lt, chrono::duration< Rep, Period > const& timeout_duration)
 { return wait_until( lt, chrono::high_resolution_clock::now() + timeout_duration); }
Beispiel #17
0
 bool wait_for( chrono::duration< Rep, Period > const& timeout_duration,
                unique_lock< detail::spinlock > & lk)
 { return wait_until( clock_type::now() + timeout_duration, lk); }
Beispiel #18
0
 std::cv_status wait_for(const std::chrono::duration<Rep, Period>& rel_time)
 {
     return wait_until(std::chrono::steady_clock::now() + rel_time);
 }
Beispiel #19
0
 cv_status
 wait_for(Lock& lock, util::steady_duration const& rel_time,
     error_code& ec = throws)
 {
     return wait_until(lock, rel_time.from_now(), ec);
 }
Beispiel #20
0
 bool wait_for(Lock& lock, util::steady_duration const& rel_time,
     Predicate pred, error_code& ec = throws)
 {
     return wait_until(lock, rel_time.from_now(), std::move(pred), ec);
 }
Beispiel #21
0
void result::wait(boost::unique_lock<boost::mutex>& lock) const
{
	BOOST_VERIFY(wait_until(time_point::max(), lock) == future_status::ready);
}