thread.h revision 27f4d2f49f23fdb722ed0e3d78045d58756497bf
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * IPRT - Threads.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2013 Oracle Corporation
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The contents of this file may alternatively be used under the terms
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * of the Common Development and Distribution License Version 1.0
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VirtualBox OSE distribution, in which case the provisions of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * CDDL are applicable instead of those of the GPL.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * You may elect to license modified versions of this file under the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * terms and conditions of either the GPL or the CDDL or both.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** @defgroup grp_rt_thread RTThread - Thread Management
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @ingroup grp_rt
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The thread state.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The usual invalid 0 value. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The thread is being initialized. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The thread has terminated */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Probably running. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a critical section. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a event semaphore. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a event multiple wakeup semaphore. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a fast mutex. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a mutex. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a read write semaphore, read (shared) access. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a read write semaphore, write (exclusive) access. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The thread is sleeping. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Waiting on a spin mutex. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** End of the thread states. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The usual 32-bit size hack. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** Checks if a thread state indicates that the thread is sleeping. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define RTTHREAD_IS_SLEEPING(enmState) ((enmState) >= RTTHREADSTATE_CRITSECT)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Thread types.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Besides identifying the purpose of the thread, the thread type is
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * used to select the scheduling properties.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The types in are placed in a rough order of ascending priority.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Invalid type. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Infrequent poller thread.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This type of thread will sleep for the most of the time, and do
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * infrequent polls on resources at 0.5 sec or higher intervals.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Main heavy worker thread.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Thread of this type is driving asynchronous tasks in the Main
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * API which takes a long time and might involve a bit of CPU. Like
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * for instance creating a fixed sized VDI.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The emulation thread type.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * While being a thread with very high workload it still is vital
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * that it gets scheduled frequently. When possible all other thread
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * types except DEFAULT and GUI should interrupt this one ASAP when
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * they become ready.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The default thread type.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Since it doesn't say much about the purpose of the thread
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * nothing special is normally done to the scheduling. This type
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * should be avoided.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The main thread is registered with default type during RTR3Init()
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * and that's what the default process priority is derived from.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The GUI thread type
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The GUI normally have a low workload but is frequently scheduled
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * to handle events. When possible the scheduler should not leave
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * threads of this kind waiting for too long (~50ms).
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Main worker thread.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Thread of this type is driving asynchronous tasks in the Main API.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * In most cases this means little work an a lot of waiting.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** VRDP I/O thread.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * These threads are I/O threads in the RDP server will hang around
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * waiting for data, process it and pass it on.
} RTTHREADTYPE;
#ifndef IN_RC
typedef enum RTTHREADFLAGS
# ifdef IN_RING0
typedef struct RTTHREADPREEMPTSTATE
# ifdef RT_OS_WINDOWS
unsigned char uchOldIrql;
typedef enum RTTHREADCTXEVENT
RTDECL(int) RTThreadCtxHooksRegister(RTTHREADCTX hThreadCtx, PFNRTTHREADCTXHOOK pfnThreadHook, void *pvUser);
# ifdef IN_RING3
RTDECL(int) RTThreadAdopt(RTTHREADTYPE enmType, unsigned fFlags, const char *pszName, PRTTHREAD pThread);
typedef enum RTTHREADNATIVESTATE