sched-os2.cpp revision b81824898d989ddac97abd4544d38447a8eea0f7
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * innotek Portable Runtime - Scheduling, OS/2
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Copyright (C) 2006-2007 innotek GmbH
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * available from http://www.virtualbox.org. This file is free software;
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * General Public License as published by the Free Software Foundation,
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/** @def OS2_SCHED_ENABLED
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Enables the priority scheme. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/*******************************************************************************
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync* Header Files *
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync*******************************************************************************/
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/*******************************************************************************
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync* Structures and Typedefs *
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync*******************************************************************************/
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Configuration of one priority.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsynctypedef struct
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** The priority. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** The name of this priority. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync const char *pszName;
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** Array scheduler attributes corresponding to each of the thread types. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** For sanity include the array index. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** The OS/2 priority class. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync /** The OS/2 priority delta. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/** Matches any process priority class. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/*******************************************************************************
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync* Global Variables *
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync*******************************************************************************/
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Array of static priority configurations.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_REGULAR, 0 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_REGULAR, 0 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 0 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 0 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 31 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_REGULAR, 0 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * The dynamic default priority configuration.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * This can be recalulated at runtime depending on what the
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * system allow us to do. Presently we don't do this as it's
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * generally not a bit issue on OS/2 hosts.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_INFREQUENT_POLLER, PRTYC_IDLETIME, 30 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync { RTTHREADTYPE_MAIN_HEAVY_WORKER, PRTYC_IDLETIME, 31 },
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync/** Pointer to the current priority configuration. */
b81824898d989ddac97abd4544d38447a8eea0f7vboxsyncstatic const PROCPRIORITY *g_pProcessPriority = &g_aDefaultPriority;
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Calculate the scheduling properties for all the threads in the default
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * process priority, assuming the current thread have the type enmType.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @returns iprt status code.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @param enmType The thread type to be assumed for the current thread.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsyncint rtSchedNativeCalcDefaultPriority(RTTHREADTYPE enmType)
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync Assert(enmType > RTTHREADTYPE_INVALID && enmType < RTTHREADTYPE_END);
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Validates and sets the process priority.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * This will check that all rtThreadNativeSetPriority() will success for all the
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * thread types when applied to the current thread.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @returns iprt status code.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @param enmPriority The priority to validate and set.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @remark Located in sched.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsyncint rtProcNativeSetPriority(RTPROCPRIORITY enmPriority)
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync Assert(enmPriority > RTPROCPRIORITY_INVALID && enmPriority < RTPROCPRIORITY_LAST);
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * Sets the priority of the thread according to the thread type
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * and current process priority.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * The RTTHREADINT::enmType member has not yet been updated and will be updated by
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * the caller on a successful return.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @returns iprt status code.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @param pThread The thread in question.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @param enmType The thread type.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * @remark Located in sched.
b81824898d989ddac97abd4544d38447a8eea0f7vboxsyncint rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync Assert(enmType > RTTHREADTYPE_INVALID && enmType < RTTHREADTYPE_END);
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync AssertMsg(g_pProcessPriority && g_pProcessPriority->aTypes[enmType].enmType == enmType,
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync ("enmType=%d entry=%d\n", enmType, g_pProcessPriority->aTypes[enmType].enmType));
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync APIRET rc = DosSetPriority(PRTYS_THREAD, g_pProcessPriority->aTypes[enmType].ulClass, g_pProcessPriority->aTypes[enmType].ulDelta, (ULONG)pThread->Core.Key & 0xffff /*tid*/);