/***************************************************************************
 *   Copyright (C) 2011-2012 by Virginia Tech Real-Time Systems Lab        *
 *                                                                         *
 *   Author(s):                                                            *
 *       - Aaron Lindsay (aaron.lindsay@vt.edu)                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

package edu.vt.realtime;

public class ChronosUtil{

	/* Make sure libjchronos is loaded so we can access the native methods */
	static{
		System.loadLibrary("jchronos");
	}

	public static native void burnCpu(long exec_usec, double slope);

	public static native void usleep(long usec);

	public static final native void printAbortTime(int tid);

	public static final native int gettid();

	public static native int getPriority();

	/* These set/get the "nice" values */
	public static native boolean setPriority(int priority);

	public static boolean setLinuxScheduler(LinuxSchedulerType sched, int priority){
		return ChronosUtil.setLinuxScheduler(sched.getNativeId(), priority);
	}

	public static boolean setLinuxScheduler(LinuxSchedulerType sched){
		return ChronosUtil.setLinuxScheduler(sched.getNativeId(), sched==LinuxSchedulerType.SCHED_NORMAL?1:0);
	}

	private static native boolean setLinuxScheduler(int sched, int priority);

	public static LinuxSchedulerType getLinuxScheduler() {
		return LinuxSchedulerType.typeFromInt(ChronosUtil.chronos_getLinuxScheduler());
	}

	private static native int chronos_getLinuxScheduler();

	public static native boolean setAffinity(int pid, long mask);

	public static boolean setAffinity(long mask) {return ChronosUtil.setAffinity(0, mask); }

	public static native boolean memoryLock();
	public static native boolean memoryUnlock();
}
