thread.h revision c98fb3e16fcd571a790eab772c0c66173d225205
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * innotek Portable Runtime - Threads.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * Copyright (C) 2006-2007 innotek GmbH
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * available from http://www.virtualbox.org. This file is free software;
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * General Public License as published by the Free Software Foundation,
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync# error "There are no threading APIs available Guest Context!"
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync/** @defgroup grp_rt_thread RTThread - Thread Management
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @ingroup grp_rt
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Get the thread handle of the current thread.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns Thread handle.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Get the native thread handle of the current thread.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns Native thread handle.
f05c9726893158b78436cc78907835367d922de9vboxsync * Millisecond granular sleep function.
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync * @returns VINF_SUCCESS on success.
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync * @returns VERR_INTERRUPTED if a signal or other asynchronous stuff happend
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync * which interrupt the peaceful sleep.
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync * @param cMillies Number of milliseconds to sleep.
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync * 0 milliseconds means yielding the timeslice - deprecated!
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync * @remark See RTThreadNanoSleep() for sleeping for smaller periods of time.
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync * Yields the CPU.
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync * @returns true if we yielded.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns false if it's probable that we didn't yield.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Thread function.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns 0 on success.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * @param ThreadSelf Thread handle to this thread.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param pvUser User argument.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsynctypedef DECLCALLBACK(int) FNRTTHREAD(RTTHREAD ThreadSelf, void *pvUser);
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/** Pointer to a FNRTTHREAD(). */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Thread types.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * Besides identifying the purpose of the thread, the thread type is
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * used to select the scheduling properties.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * The types in are placed in a rough order of ascending priority.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** Invalid type. */
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** Infrequent poller thread.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * This type of thread will sleep for the most of the time, and do
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * infrequent polls on resources at 0.5 sec or higher intervals.
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync /** Main heavy worker thread.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * Thread of this type is driving asynchronous tasks in the Main
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * API which takes a long time and might involve a bit of CPU. Like
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * for instance creating a fixed sized VDI.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** The emulation thread type.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * While being a thread with very high workload it still is vital
78d5c1f3e0c4c4dce02baa0be07e616bc212f441vboxsync * that it gets scheduled frequently. When possible all other thread
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * types except DEFAULT and GUI should interrupt this one ASAP when
38e7976384c17215607055e2574ae71d386ba7bbvboxsync * they become ready.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** The default thread type.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * Since it doesn't say much about the purpose of the thread
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * nothing special is normally done to the scheduling. This type
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * should be avoided.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * The main thread is registered with default type during RTR3Init()
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * and that's what the default process priority is derived from.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** The GUI thread type
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * The GUI normally have a low workload but is frequently scheduled
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * to handle events. When possible the scheduler should not leave
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * threads of this kind waiting for too long (~50ms).
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** Main worker thread.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Thread of this type is driving asynchronous tasks in the Main API.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * In most cases this means little work an a lot of waiting.
f55e40eab578fb43357fe057f8088cc16bb1a9e9vboxsync /** VRDP I/O thread.
f55e40eab578fb43357fe057f8088cc16bb1a9e9vboxsync * These threads are I/O threads in the RDP server will hang around
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * waiting for data, process it and pass it on.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** The debugger type.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Threads involved in servicing the debugger. It must remain
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * responsive even when things are running wild in.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** Message pump thread.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Thread pumping messages from one thread/process to another
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * thread/process. The workload is very small, most of the time
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * it's blocked waiting for messages to be procduced or processed.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * This type of thread will be favored after I/O threads.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** The I/O thread type.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Doing I/O means shuffling data, waiting for request to arrive and
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * for them to complete. The thread should be favored when competing
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * with any other threads except timer threads.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** The timer thread type.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * A timer thread is mostly waiting for the timer to tick
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * and then perform a little bit of work. Accuracy is important here,
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * so the thread should be favoured over all threads. If premention can
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * be configured at thread level, it could be made very short.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** Only used for validation. */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Thread creation flags.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * This flag is used to keep the thread structure around so it can
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * be waited on after termination.
#ifdef IN_RING3
RTDECL(int) RTThreadAdopt(RTTHREADTYPE enmType, unsigned fFlags, const char *pszName, PRTTHREAD pThread);