001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj;
006
007import edu.wpi.first.hal.ThreadsJNI;
008
009/** Thread utility functions. */
010public final class Threads {
011  /**
012   * Get the thread priority for the current thread.
013   *
014   * @return The current thread priority. For real-time, this is 1-99 with 99 being highest. For
015   *     non-real-time, this is 0. See "man 7 sched" for details.
016   */
017  public static int getCurrentThreadPriority() {
018    return ThreadsJNI.getCurrentThreadPriority();
019  }
020
021  /**
022   * Get if the current thread is real-time.
023   *
024   * @return If the current thread is real-time.
025   */
026  public static boolean getCurrentThreadIsRealTime() {
027    return ThreadsJNI.getCurrentThreadIsRealTime();
028  }
029
030  /**
031   * Sets the thread priority for the current thread.
032   *
033   * @param realTime Set to true to set a real-time priority, false for standard priority.
034   * @param priority Priority to set the thread to. For real-time, this is 1-99 with 99 being
035   *     highest. For non-real-time, this is forced to 0. See "man 7 sched" for details.
036   * @return True on success.
037   */
038  public static boolean setCurrentThreadPriority(boolean realTime, int priority) {
039    return ThreadsJNI.setCurrentThreadPriority(realTime, priority);
040  }
041
042  private Threads() {}
043}