VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/thread.h@ 1

最後變更 在這個檔案從1是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 6.9 KB
 
1/* $Id: thread.h 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Internal RTThread header.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef __thread_h__
23#define __thread_h__
24
25#include <iprt/types.h>
26#include <iprt/thread.h>
27#include <iprt/process.h>
28#include <iprt/critsect.h>
29#include <iprt/avl.h>
30
31
32__BEGIN_DECLS
33
34#ifdef IN_RING3
35
36
37/**
38 * The thread state.
39 */
40typedef enum RTTHREADSTATE
41{
42 /** The usual invalid 0 value. */
43 RTTHREADSTATE_INVALID = 0,
44 /** The thread is being initialized. */
45 RTTHREADSTATE_INITIALIZING,
46 /** The thread has terminated */
47 RTTHREADSTATE_TERMINATED,
48 /** Probably running. */
49 RTTHREADSTATE_RUNNING,
50 /** Waiting on a critical section. */
51 RTTHREADSTATE_CRITSECT,
52 /** Waiting on a mutex. */
53 RTTHREADSTATE_MUTEX,
54 /** Waiting on a event semaphore. */
55 RTTHREADSTATE_EVENT,
56 /** Waiting on a event multiple wakeup semaphore. */
57 RTTHREADSTATE_EVENTMULTI,
58 /** The thread is sleeping. */
59 RTTHREADSTATE_SLEEP,
60 /** The usual 32-bit size hack. */
61 RTTHREADSTATE_32BIT_HACK = 0x7fffffff
62} RTTHREADSTATE;
63
64
65/** Checks if a thread state indicates that the thread is sleeping. */
66#define RTTHREAD_IS_SLEEPING(enmState) ( (enmState) == RTTHREADSTATE_CRITSECT \
67 || (enmState) == RTTHREADSTATE_MUTEX \
68 || (enmState) == RTTHREADSTATE_EVENT \
69 || (enmState) == RTTHREADSTATE_EVENTMULTI \
70 || (enmState) == RTTHREADSTATE_SLEEP \
71 )
72
73/** Max thread name length. */
74#define RTTHREAD_NAME_LEN 16
75
76/**
77 * Internal represenation of a thread.
78 */
79typedef struct RTTHREADINT
80{
81 /** Avl node core - the key is the native thread id. */
82 AVLPVNODECORE Core;
83 /** Magic value (RTTHREADINT_MAGIC). */
84 uint32_t u32Magic;
85 /** Reference counter. */
86 uint32_t volatile cRefs;
87 /** The current thread state. */
88 RTTHREADSTATE volatile enmState;
89#ifdef __WIN__
90 /** The thread handle.
91 * This is not valid until the create function has returned! */
92 uintptr_t hThread;
93#endif
94 /** The user event semaphore. */
95 RTSEMEVENTMULTI EventUser;
96 /** The terminated event semaphore. */
97 RTSEMEVENTMULTI EventTerminated;
98 /** The thread type. */
99 RTTHREADTYPE enmType;
100 /** The thread creation flags. (RTTHREADFLAGS) */
101 unsigned fFlags;
102 /** Internal flags. (RTTHREADINT_FLAGS_ *) */
103 uint32_t fIntFlags;
104 /** The result code. */
105 int rc;
106 /** Thread function. */
107 PFNRTTHREAD pfnThread;
108 /** Thread function argument. */
109 void *pvUser;
110 /** Actual stack size. */
111 size_t cbStack;
112 /** What we're blocking on. */
113 union RTTHREADINTBLOCKID
114 {
115 uint64_t u64;
116 PRTCRITSECT pCritSect;
117 RTSEMEVENT Event;
118 RTSEMEVENTMULTI EventMulti;
119 RTSEMMUTEX Mutex;
120 } Block;
121 /** Where we're blocking. */
122 const char volatile *pszBlockFile;
123 /** Where we're blocking. */
124 unsigned volatile uBlockLine;
125 /** Where we're blocking. */
126 RTUINTPTR volatile uBlockId;
127 /** Thread name. */
128 char szName[RTTHREAD_NAME_LEN];
129} RTTHREADINT, *PRTTHREADINT;
130
131/** RTTHREADINT::u32Magic value. (Gilbert Keith Chesterton) */
132#define RTTHREADINT_MAGIC 0x18740529
133/** RTTHREADINT::u32Magic value for a dead thread. */
134#define RTTHREADINT_MAGIC_DEAD 0x19360614
135
136/** @name RTTHREADINT::fIntFlags Masks and Bits.
137 * @{ */
138/** Set if the thread is an alien thread.
139 * Clear if the thread was created by IPRT. */
140#define RTTHREADINT_FLAGS_ALIEN BIT(0)
141/** Set if the thread has terminated.
142 * Clear if the thread is running. */
143#define RTTHREADINT_FLAGS_TERMINATED BIT(1)
144/** This bit is set if the thread is in the AVL tree. */
145#define RTTHREADINT_FLAG_IN_TREE_BIT 2
146/** @copydoc RTTHREADINT_FLAG_IN_TREE_BIT */
147#define RTTHREADINT_FLAG_IN_TREE BIT(RTTHREADINT_FLAG_IN_TREE_BIT)
148/** @} */
149
150
151/**
152 * Initialize the native part of the thread management.
153 *
154 * Generally a TLS entry will be allocated at this point.
155 *
156 * @returns iprt status code.
157 */
158int rtThreadNativeInit(void);
159
160/**
161 * Sets the priority of the thread according to the thread type
162 * and current process priority.
163 *
164 * The RTTHREADINT::enmType member has not yet been updated and will be updated by
165 * the caller on a successful return.
166 *
167 * @returns iprt status code.
168 * @param Thread The thread in question.
169 * @param enmType The thread type.
170 * @remark Located in sched.
171 */
172int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType);
173
174/**
175 * Create a native thread.
176 * This creates the thread as described in pThreadInt and stores the thread id in *pThread.
177 *
178 * @returns iprt status code.
179 * @param pThreadInt The thread data structure for the thread.
180 * @param pNativeThread Where to store the native thread identifier.
181 */
182int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread);
183
184/**
185 * Adopts a thread, this is called immediately after allocating the
186 * thread structure.
187 *
188 * @param pThread Pointer to the thread structure.
189 */
190int rtThreadNativeAdopt(PRTTHREADINT pThread);
191
192#ifdef __WIN__
193/**
194 * Callback for when a native thread is detaching.
195 *
196 * It give the Win32/64 backend a chance to terminate alien
197 * threads properly.
198 */
199void rtThreadNativeDetach(void);
200#endif
201
202int rtThreadInit(void);
203int rtThreadMain(PRTTHREADINT pThread, RTNATIVETHREAD NativeThread);
204void rtThreadInsert(PRTTHREADINT pThread, RTNATIVETHREAD NativeThread);
205PRTTHREADINT rtThreadGetByNative(RTNATIVETHREAD NativeThread);
206PRTTHREADINT rtThreadGet(RTTHREAD Thread);
207uint32_t rtThreadRelease(PRTTHREADINT pThread);
208int rtThreadDoSetProcPriority(RTPROCPRIORITY enmPriority);
209void rtThreadTerminate(PRTTHREADINT pThread, int rc);
210void rtThreadBlocking(PRTTHREADINT pThread, RTTHREADSTATE enmState, uint64_t u64Block,
211 const char *pszFile, unsigned uLine, RTUINTPTR uId);
212void rtThreadUnblocked(PRTTHREADINT pThread, RTTHREADSTATE enmCurState);
213
214#endif /* IN_RING3 */
215
216__END_DECLS
217
218#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette