#include <string.h>
#include <sched.h>
#include "xassert.h"
#include "xatexit.h"
#include "xsched.h"

extern int no_sched;

void xsched_cleanup (void)
{
	struct sched_param parm;

	memset (&parm, 0, sizeof(parm));
	parm.sched_priority = sched_get_priority_min(SCHED_OTHER);
	sched_setscheduler (0, SCHED_OTHER, &parm);
}

void xsched_init (void)
{
	struct sched_param parm;

	if (no_sched)
		return;

	memset (&parm, 0, sizeof(parm));
	xassert ((parm.sched_priority = sched_get_priority_max(SCHED_FIFO)) != -1, 
		"Ustawianie priorytetu schedulera: %m.");

	xassert (sched_setscheduler(0, SCHED_FIFO, &parm) != -1, 
		"Ustawianie polityki schedulera: %m.");

	xatexit (xsched_cleanup);
}
