sched-os2.cpp revision 1c94c0a63ba68be1a7b2c640e70d7a06464e4fca
b81824898d989ddac97abd4544d38447a8eea0f7vboxsync * innotek Portable Runtime - Scheduling, OS/2
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * available from http://www.virtualbox.org. This file is free software;
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * you can redistribute it and/or modify it under the terms of the GNU
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * General Public License (GPL) as published by the Free Software
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * The contents of this file may alternatively be used under the terms
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * of the Common Development and Distribution License Version 1.0
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * VirtualBox OSE distribution, in which case the provisions of the
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * CDDL are applicable instead of those of the GPL.
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * You may elect to license modified versions of this file under the
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * terms and conditions of either the GPL or the CDDL or both.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
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*/);