Example #1
0
void workqueue_exit(struct workqueue *wq)
{
	unsigned int shutdown, sum_cnt = 0;
	struct submit_worker *sw;
	int i;

	for (i = 0; i < wq->max_workers; i++) {
		sw = &wq->workers[i];

		pthread_mutex_lock(&sw->lock);
		sw->flags |= SW_F_EXIT;
		pthread_cond_signal(&sw->cond);
		pthread_mutex_unlock(&sw->lock);
	}

	do {
		shutdown = 0;
		for (i = 0; i < wq->max_workers; i++) {
			sw = &wq->workers[i];
			if (sw->flags & SW_F_ACCOUNTED)
				continue;
			sw->flags |= SW_F_ACCOUNTED;
			shutdown_worker(sw, &sum_cnt);
			shutdown++;
		}
	} while (shutdown && shutdown != wq->max_workers);

	free(wq->workers);
	pthread_mutex_destroy(&wq->flush_lock);
	pthread_cond_destroy(&wq->flush_cond);
	pthread_mutex_destroy(&wq->stat_lock);
}
Example #2
0
int px4_shutdown_request(bool reboot, bool to_bootloader)
{
	// fail immediately if the board does not support the requested method
#if defined BOARD_HAS_NO_RESET
	if (reboot) {
		return -EINVAL;
	}

#endif
#if !defined(BOARD_HAS_POWER_CONTROL)

	if (!reboot) {
		return -EINVAL;
	}

#endif

	if (shutdown_args & SHUTDOWN_ARG_IN_PROGRESS) {
		return 0;
	}

	shutdown_args |= SHUTDOWN_ARG_IN_PROGRESS;

	if (reboot) {
		shutdown_args |= SHUTDOWN_ARG_REBOOT;
	}

	if (to_bootloader) {
		shutdown_args |= SHUTDOWN_ARG_TO_BOOTLOADER;
	}

	shutdown_worker(nullptr);
	return 0;
}