bool wait_for(int64_t wait_time_us)
			{
				if (!sync)
					return false;
				unique_lock<mutex> lk{m};
				return cv.wait_for(lk, chrono::microseconds(wait_time_us), [this]{return rdy;});
			}
void test(SBDebugger &dbg, vector<string> args) {
  SBTarget target = dbg.CreateTarget(args.at(0).c_str());
  if (!target.IsValid()) throw Exception("invalid target");

  SBBreakpoint breakpoint = target.BreakpointCreateByName("next");
  if (!breakpoint.IsValid()) throw Exception("invalid breakpoint");
  breakpoint.SetCallback(BPCallback, 0);

  std::unique_ptr<char> working_dir(get_working_dir());
  SBProcess process = target.LaunchSimple (0, 0, working_dir.get());

  {
    unique_lock<mutex> lock(g_mutex);
    g_condition.wait_for(lock, chrono::seconds(5));
    if (g_breakpoint_hit_count != 1)
      throw Exception("Breakpoint hit count expected to be 1");
  }
}
void SwitcherData::Thread()
{
	chrono::duration<long long, milli> duration =
		chrono::milliseconds(interval);
	string lastTitle;
	string title;

	for (;;) {
		unique_lock<mutex> lock(m);
		OBSWeakSource scene;
		bool match = false;

		cv.wait_for(lock, duration);
		if (switcher->stop) {
			switcher->stop = false;
			break;
		}

		duration = chrono::milliseconds(interval);

		GetCurrentWindowTitle(title);

		if (lastTitle != title) {
			switcher->Prune();

			for (SceneSwitch &s : switches) {
				if (s.window == title) {
					match = true;
					scene = s.scene;
					break;
				}
			}

			/* try regex */
			if (!match) {
				for (SceneSwitch &s : switches) {
					try {
						bool matches = regex_match(
								title, s.re);
						if (matches) {
							match = true;
							scene = s.scene;
							break;
						}
					} catch (const regex_error &) {}
				}
			}

			if (!match && switchIfNotMatching &&
					nonMatchingScene) {
				match = true;
				scene = nonMatchingScene;
			}

			if (match) {
				obs_source_t *source =
					obs_weak_source_get_source(scene);
				obs_source_t *currentSource =
					obs_frontend_get_current_scene();

				if (source && source != currentSource)
					obs_frontend_set_current_scene(source);

				obs_source_release(currentSource);
				obs_source_release(source);
			}
		}

		lastTitle = title;
	}
}
示例#4
0
void CPU_WaitStatus(bool (*pred)()) {
	cpuThreadLock.lock();
	while (!pred())
		cpuThreadCond.wait_for(cpuThreadLock, 16);
	cpuThreadLock.unlock();
}
示例#5
0
 void waitForCountAndFailOnTimeout(unsigned int expectedCount,
                                   const milliseconds& time = milliseconds(100)) {
     unique_lock<mutex> lock(m);
     ASSERT_TRUE(wasExecuted.wait_for(lock, time, [&] {return expectedCount == count;}));
 }