示例#1
0
文件: pingtest.c 项目: beekhof/dlm
int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        printf("usage: %s <maxnodes> <us>\n", argv[0]);
	return 2;
    }
    maxnode = atoi(argv[1]);
    us = atoi(argv[2]);

    start_lock();
    while(1)
	sys$hiber();

    return SS$_NORMAL;
}
示例#2
0
文件: pingtest.c 项目: beekhof/dlm
int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        printf("usage: %s <maxnodes> <us>\n", argv[0]);
	return 2;
    }
    maxnode = atoi(argv[1]);
    us = atoi(argv[2]);

    dlm_pthread_init();
    start_lock();
    while(1)
	    sleep(100000);
    return 0;
}
示例#3
0
void PeopleEventRegister<T>::startProcess()
{
  boost::mutex::scoped_lock start_lock(mutex_);
  if (!isStarted_)
  {
    if(!serviceId)
    {
      //std::string serviceName = std::string("ROS-Driver-") + typeid(T).name();
      std::string serviceName = std::string("ROS-Driver-") + keys_[0];
      serviceId = session_->registerService(serviceName, this->shared_from_this());
      for(std::vector<std::string>::const_iterator it = keys_.begin(); it != keys_.end(); ++it) {
        std::cerr << *it << std::endl;
        p_memory_.call<void>("subscribeToEvent",it->c_str(), serviceName, "peopleCallback");
      }
      std::cout << serviceName << " : Start" << std::endl;
    }
    isStarted_ = true;
  }
}
示例#4
0
void AudioEventRegister::startProcess()
{
  boost::mutex::scoped_lock start_lock(subscription_mutex_);
  if (!isStarted_)
  {
    if(!serviceId)
    {
      serviceId = session_->registerService("ROS-Driver-Audio", shared_from_this());
      p_audio_.call<void>(
              "setClientPreferences",
              "ROS-Driver-Audio",
              48000,
              0,
              0
              );
      p_audio_.call<void>("subscribe","ROS-Driver-Audio");
      std::cout << "Audio Extractor: Start" << std::endl;
    }
    isStarted_ = true;
  }
}
示例#5
0
void DrawerCommandQueue::Finish()
{
	auto queue = Instance();
	if (queue->commands.empty())
		return;

	// Give worker threads something to do:

	std::unique_lock<std::mutex> start_lock(queue->start_mutex);
	queue->active_commands.swap(queue->commands);
	queue->run_id++;
	start_lock.unlock();

	queue->StartThreads();
	queue->start_condition.notify_all();

	// Do one thread ourselves:

	DrawerThread thread;
	thread.core = 0;
	thread.num_cores = (int)(queue->threads.size() + 1);

	struct TryCatchData
	{
		DrawerCommandQueue *queue;
		DrawerThread *thread;
		size_t command_index;
	} data;

	data.queue = queue;
	data.thread = &thread;
	data.command_index = 0;
	VectoredTryCatch(&data,
	[](void *data)
	{
		TryCatchData *d = (TryCatchData*)data;

		for (int pass = 0; pass < d->queue->num_passes; pass++)
		{
			d->thread->pass_start_y = pass * d->queue->rows_in_pass;
			d->thread->pass_end_y = (pass + 1) * d->queue->rows_in_pass;
			if (pass + 1 == d->queue->num_passes)
				d->thread->pass_end_y = MAX(d->thread->pass_end_y, MAXHEIGHT);

			size_t size = d->queue->active_commands.size();
			for (d->command_index = 0; d->command_index < size; d->command_index++)
			{
				auto &command = d->queue->active_commands[d->command_index];
				command->Execute(d->thread);
			}
		}
	},
	[](void *data, const char *reason, bool fatal)
	{
		TryCatchData *d = (TryCatchData*)data;
		ReportDrawerError(d->queue->active_commands[d->command_index], true, reason, fatal);
	});

	// Wait for everyone to finish:

	std::unique_lock<std::mutex> end_lock(queue->end_mutex);
	queue->end_condition.wait(end_lock, [&]() { return queue->finished_threads == queue->threads.size(); });

	if (!queue->thread_error.IsEmpty())
	{
		static bool first = true;
		if (queue->thread_error_fatal)
			I_FatalError("%s", queue->thread_error.GetChars());
		else if (first)
			Printf("%s\n", queue->thread_error.GetChars());
		first = false;
	}

	// Clean up batch:

	for (auto &command : queue->active_commands)
		command->~DrawerCommand();
	queue->active_commands.clear();
	queue->memorypool_pos = 0;
	queue->finished_threads = 0;
}
示例#6
0
void DrawerCommandQueue::StartThreads()
{
	if (!threads.empty())
		return;

	int num_threads = std::thread::hardware_concurrency();
	if (num_threads == 0)
		num_threads = 4;

	threads.resize(num_threads - 1);

	for (int i = 0; i < num_threads - 1; i++)
	{
		DrawerCommandQueue *queue = this;
		DrawerThread *thread = &threads[i];
		thread->core = i + 1;
		thread->num_cores = num_threads;
		thread->thread = std::thread([=]()
		{
			int run_id = 0;
			while (true)
			{
				// Wait until we are signalled to run:
				std::unique_lock<std::mutex> start_lock(queue->start_mutex);
				queue->start_condition.wait(start_lock, [&]() { return queue->run_id != run_id || queue->shutdown_flag; });
				if (queue->shutdown_flag)
					break;
				run_id = queue->run_id;
				start_lock.unlock();

				// Do the work:

				struct TryCatchData
				{
					DrawerCommandQueue *queue;
					DrawerThread *thread;
					size_t command_index;
				} data;

				data.queue = queue;
				data.thread = thread;
				data.command_index = 0;
				VectoredTryCatch(&data,
				[](void *data)
				{
					TryCatchData *d = (TryCatchData*)data;

					for (int pass = 0; pass < d->queue->num_passes; pass++)
					{
						d->thread->pass_start_y = pass * d->queue->rows_in_pass;
						d->thread->pass_end_y = (pass + 1) * d->queue->rows_in_pass;
						if (pass + 1 == d->queue->num_passes)
							d->thread->pass_end_y = MAX(d->thread->pass_end_y, MAXHEIGHT);

						size_t size = d->queue->active_commands.size();
						for (d->command_index = 0; d->command_index < size; d->command_index++)
						{
							auto &command = d->queue->active_commands[d->command_index];
							command->Execute(d->thread);
						}
					}
				},
				[](void *data, const char *reason, bool fatal)
				{
					TryCatchData *d = (TryCatchData*)data;
					ReportDrawerError(d->queue->active_commands[d->command_index], true, reason, fatal);
				});

				// Notify main thread that we finished:
				std::unique_lock<std::mutex> end_lock(queue->end_mutex);
				queue->finished_threads++;
				end_lock.unlock();
				queue->end_condition.notify_all();
			}
		});
	}
}