sched-os2.cpp revision b81824898d989ddac97abd4544d38447a8eea0f7
/* $Id$ */
/** @file
* innotek Portable Runtime - Scheduling, OS/2
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/** @def OS2_SCHED_ENABLED
* Enables the priority scheme. */
#define OS2_SCHED_ENABLED
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_THREAD
#define INCL_BASE
#define INCL_ERRORS
#include <os2.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Configuration of one priority.
*/
typedef struct
{
/** The priority. */
/** The name of this priority. */
const char *pszName;
/** Array scheduler attributes corresponding to each of the thread types. */
struct
{
/** For sanity include the array index. */
/** The OS/2 priority class. */
/** The OS/2 priority delta. */
} PROCPRIORITY;
/** Matches any process priority class. */
#define ANY_PROCESS_PRIORITY_CLASS (~0U)
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Array of static priority configurations.
*/
static const PROCPRIORITY g_aPriorities[] =
{
{
RTPROCPRIORITY_FLAT, "Flat",
{
{ RTTHREADTYPE_INVALID, ~0, ~0 },
{ RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_DEFAULT, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_GUI, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_MAIN_WORKER, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_IO, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_TIMER, PRTYC_REGULAR, 0 }
}
},
{
RTPROCPRIORITY_LOW, "Low",
{
{ RTTHREADTYPE_INVALID, ~0 },
{ RTTHREADTYPE_EMULATION, PRTYC_IDLETIME, 0 },
{ RTTHREADTYPE_VRDP_IO, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_DEBUGGER, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_MSG_PUMP, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_IO, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_TIMER, PRTYC_REGULAR, 0 }
}
},
{
RTPROCPRIORITY_NORMAL, "Normal",
{
{ RTTHREADTYPE_INVALID, ~0 },
{ RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_TIMER, PRTYC_TIMECRITICAL, 0 }
}
},
{
RTPROCPRIORITY_HIGH, "High",
{
{ RTTHREADTYPE_INVALID, ~0 },
{ RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
}
}
};
/**
* The dynamic default priority configuration.
*
* This can be recalulated at runtime depending on what the
* system allow us to do. Presently we don't do this as it's
* generally not a bit issue on OS/2 hosts.
*/
static PROCPRIORITY g_aDefaultPriority =
{
RTPROCPRIORITY_LOW, "Default",
{
{ RTTHREADTYPE_INVALID, ~0 },
{ RTTHREADTYPE_EMULATION, PRTYC_REGULAR, 0 },
{ RTTHREADTYPE_TIMER, PRTYC_TIMECRITICAL, 0 }
}
};
/** Pointer to the current priority configuration. */
/**
* Calculate the scheduling properties for all the threads in the default
* process priority, assuming the current thread have the type enmType.
*
* @returns iprt status code.
* @param enmType The thread type to be assumed for the current thread.
*/
{
return VINF_SUCCESS;
}
/**
* Validates and sets the process priority.
* This will check that all rtThreadNativeSetPriority() will success for all the
* thread types when applied to the current thread.
*
* @returns iprt status code.
* @param enmPriority The priority to validate and set.
* @remark Located in sched.
*/
{
return VINF_SUCCESS;
}
/**
* Sets the priority of the thread according to the thread type
* and current process priority.
*
* The RTTHREADINT::enmType member has not yet been updated and will be updated by
* the caller on a successful return.
*
* @returns iprt status code.
* @param pThread The thread in question.
* @param enmType The thread type.
* @remark Located in sched.
*/
{
#ifdef OS2_SCHED_ENABLED
APIRET rc = DosSetPriority(PRTYS_THREAD, g_pProcessPriority->aTypes[enmType].ulClass, g_pProcessPriority->aTypes[enmType].ulDelta, (ULONG)pThread->Core.Key & 0xffff /*tid*/);
return RTErrConvertFromOS2(rc);
#else
return VINF_SUCCESS;
#endif
}