thread.h revision f4db180328f833f9fc9cb07a1a4a0bc948a47afe
/* $Id$ */
/** @file
* InnoTek Portable Runtime - Internal RTThread header.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifndef __thread_h__
#define __thread_h__
#ifdef IN_RING3
# include <iprt/critsect.h>
#endif
/**
* The thread state.
*/
typedef enum RTTHREADSTATE
{
/** The usual invalid 0 value. */
/** The thread is being initialized. */
/** The thread has terminated */
/** Probably running. */
/** Waiting on a critical section. */
/** Waiting on a mutex. */
/** Waiting on a event semaphore. */
/** Waiting on a event multiple wakeup semaphore. */
/** The thread is sleeping. */
/** The usual 32-bit size hack. */
RTTHREADSTATE_32BIT_HACK = 0x7fffffff
/** Checks if a thread state indicates that the thread is sleeping. */
|| (enmState) == RTTHREADSTATE_MUTEX \
|| (enmState) == RTTHREADSTATE_EVENT \
|| (enmState) == RTTHREADSTATE_EVENTMULTI \
|| (enmState) == RTTHREADSTATE_SLEEP \
)
/** Max thread name length. */
#define RTTHREAD_NAME_LEN 16
/**
* Internal represenation of a thread.
*/
typedef struct RTTHREADINT
{
/** Avl node core - the key is the native thread id. */
/** Magic value (RTTHREADINT_MAGIC). */
/** Reference counter. */
/** The current thread state. */
RTTHREADSTATE volatile enmState;
/** The thread handle.
* This is not valid until the create function has returned! */
#endif
/** The user event semaphore. */
/** The terminated event semaphore. */
/** The thread type. */
/** The thread creation flags. (RTTHREADFLAGS) */
unsigned fFlags;
/** Internal flags. (RTTHREADINT_FLAGS_ *) */
/** The result code. */
int rc;
/** Thread function. */
/** Thread function argument. */
void *pvUser;
/** Actual stack size. */
#ifdef IN_RING3
/** What we're blocking on. */
union RTTHREADINTBLOCKID
{
} Block;
/** Where we're blocking. */
const char volatile *pszBlockFile;
/** Where we're blocking. */
unsigned volatile uBlockLine;
/** Where we're blocking. */
#endif /* IN_RING3 */
/** Thread name. */
char szName[RTTHREAD_NAME_LEN];
} RTTHREADINT, *PRTTHREADINT;
/** RTTHREADINT::u32Magic value. (Gilbert Keith Chesterton) */
#define RTTHREADINT_MAGIC 0x18740529
/** RTTHREADINT::u32Magic value for a dead thread. */
#define RTTHREADINT_MAGIC_DEAD 0x19360614
/** @name RTTHREADINT::fIntFlags Masks and Bits.
* @{ */
/** Set if the thread is an alien thread.
* Clear if the thread was created by IPRT. */
#define RTTHREADINT_FLAGS_ALIEN BIT(0)
/** Set if the thread has terminated.
* Clear if the thread is running. */
/** This bit is set if the thread is in the AVL tree. */
#define RTTHREADINT_FLAG_IN_TREE_BIT 2
/** @copydoc RTTHREADINT_FLAG_IN_TREE_BIT */
/** @} */
/**
* Initialize the native part of the thread management.
*
* Generally a TLS entry will be allocated at this point (Ring-3).
*
* @returns iprt status code.
*/
int rtThreadNativeInit(void);
/**
* Create a native thread.
* This creates the thread as described in pThreadInt and stores the thread id in *pThread.
*
* @returns iprt status code.
* @param pThreadInt The thread data structure for the thread.
* @param pNativeThread Where to store the native thread identifier.
*/
/**
* Adopts a thread, this is called immediately after allocating the
* thread structure.
*
* @param pThread Pointer to the thread structure.
*/
/**
* 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 Thread The thread in question.
* @param enmType The thread type.
* @remark Located in sched.
*/
#ifdef IN_RING3
# ifdef __WIN__
/**
* Callback for when a native thread is detaching.
*
* It give the Win32/64 backend a chance to terminate alien
* threads properly.
*/
void rtThreadNativeDetach(void);
# endif
#endif /* !IN_RING0 */
/* thread.cpp */
int rtThreadInit(void);
void rtThreadTerm(void);
#ifdef IN_RING3
#endif /* !IN_RING0 */
#endif