VirtualBox

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

Last change on this file since 25611 was 25611, checked in by vboxsync, 15 years ago

iprt/lockvaldiator,++: owner record management and some other stuff. Disabled lock strictness for everyeone but me.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/* $Id: thread.h 25611 2009-12-31 14:54:25Z vboxsync $ */
2/** @file
3 * IPRT - Internal RTThread header.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___thread_h
32#define ___thread_h
33
34#include <iprt/types.h>
35#include <iprt/thread.h>
36#include <iprt/avl.h>
37#ifdef IN_RING3
38# include <iprt/process.h>
39# include <iprt/critsect.h>
40#endif
41#include "internal/lockvalidator.h"
42#include "internal/magics.h"
43
44RT_C_DECLS_BEGIN
45
46
47
48
49/** Max thread name length. */
50#define RTTHREAD_NAME_LEN 16
51#ifdef IPRT_WITH_GENERIC_TLS
52/** The number of TLS entries for the generic implementation. */
53# define RTTHREAD_TLS_ENTRIES 64
54#endif
55
56/**
57 * Internal represenation of a thread.
58 */
59typedef struct RTTHREADINT
60{
61 /** Avl node core - the key is the native thread id. */
62 AVLPVNODECORE Core;
63 /** Magic value (RTTHREADINT_MAGIC). */
64 uint32_t u32Magic;
65 /** Reference counter. */
66 uint32_t volatile cRefs;
67 /** The current thread state. */
68 RTTHREADSTATE volatile enmState;
69#if defined(RT_OS_WINDOWS) && defined(IN_RING3)
70 /** The thread handle
71 * This is not valid until the create function has returned! */
72 uintptr_t hThread;
73#endif
74 /** The user event semaphore. */
75 RTSEMEVENTMULTI EventUser;
76 /** The terminated event semaphore. */
77 RTSEMEVENTMULTI EventTerminated;
78 /** The thread type. */
79 RTTHREADTYPE enmType;
80 /** The thread creation flags. (RTTHREADFLAGS) */
81 unsigned fFlags;
82 /** Internal flags. (RTTHREADINT_FLAGS_ *) */
83 uint32_t fIntFlags;
84 /** The result code. */
85 int rc;
86 /** Thread function. */
87 PFNRTTHREAD pfnThread;
88 /** Thread function argument. */
89 void *pvUser;
90 /** Actual stack size. */
91 size_t cbStack;
92#ifdef IN_RING3
93 /** The lock validator data. */
94 RTLOCKVALPERTHREAD LockValidator;
95#endif /* IN_RING3 */
96#ifdef IPRT_WITH_GENERIC_TLS
97 /** The TLS entries for this thread. */
98 void *apvTlsEntries[RTTHREAD_TLS_ENTRIES];
99#endif
100 /** Thread name. */
101 char szName[RTTHREAD_NAME_LEN];
102} RTTHREADINT;
103/** Pointer to the internal representation of a thread. */
104typedef RTTHREADINT *PRTTHREADINT;
105
106
107/** @name RTTHREADINT::fIntFlags Masks and Bits.
108 * @{ */
109/** Set if the thread is an alien thread.
110 * Clear if the thread was created by IPRT. */
111#define RTTHREADINT_FLAGS_ALIEN RT_BIT(0)
112/** Set if the thread has terminated.
113 * Clear if the thread is running. */
114#define RTTHREADINT_FLAGS_TERMINATED RT_BIT(1)
115/** This bit is set if the thread is in the AVL tree. */
116#define RTTHREADINT_FLAG_IN_TREE_BIT 2
117/** @copydoc RTTHREADINT_FLAG_IN_TREE_BIT */
118#define RTTHREADINT_FLAG_IN_TREE RT_BIT(RTTHREADINT_FLAG_IN_TREE_BIT)
119/** Set if it's the main thread. */
120#define RTTHREADINT_FLAGS_MAIN RT_BIT(3)
121/** @} */
122
123
124/**
125 * Initialize the native part of the thread management.
126 *
127 * Generally a TLS entry will be allocated at this point (Ring-3).
128 *
129 * @returns iprt status code.
130 */
131int rtThreadNativeInit(void);
132
133/**
134 * Create a native thread.
135 * This creates the thread as described in pThreadInt and stores the thread id in *pThread.
136 *
137 * @returns iprt status code.
138 * @param pThreadInt The thread data structure for the thread.
139 * @param pNativeThread Where to store the native thread identifier.
140 */
141int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread);
142
143/**
144 * Adopts a thread, this is called immediately after allocating the
145 * thread structure.
146 *
147 * @param pThread Pointer to the thread structure.
148 */
149int rtThreadNativeAdopt(PRTTHREADINT pThread);
150
151/**
152 * Sets the priority of the thread according to the thread type
153 * and current process priority.
154 *
155 * The RTTHREADINT::enmType member has not yet been updated and will be updated by
156 * the caller on a successful return.
157 *
158 * @returns iprt status code.
159 * @param pThread The thread in question.
160 * @param enmType The thread type.
161 * @remark Located in sched.
162 */
163int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType);
164
165#ifdef IN_RING3
166# ifdef RT_OS_WINDOWS
167/**
168 * Callback for when a native thread is detaching.
169 *
170 * It give the Win32/64 backend a chance to terminate alien
171 * threads properly.
172 */
173void rtThreadNativeDetach(void);
174# endif
175#endif /* !IN_RING0 */
176
177
178/* thread.cpp */
179int rtThreadMain(PRTTHREADINT pThread, RTNATIVETHREAD NativeThread, const char *pszThreadName);
180void rtThreadBlocking(PRTTHREADINT pThread, RTTHREADSTATE enmState, uint64_t u64Block,
181 const char *pszFile, unsigned uLine, RTUINTPTR uId);
182void rtThreadUnblocked(PRTTHREADINT pThread, RTTHREADSTATE enmCurState);
183uint32_t rtThreadRelease(PRTTHREADINT pThread);
184void rtThreadTerminate(PRTTHREADINT pThread, int rc);
185PRTTHREADINT rtThreadGetByNative(RTNATIVETHREAD NativeThread);
186PRTTHREADINT rtThreadGet(RTTHREAD Thread);
187int rtThreadInit(void);
188void rtThreadTerm(void);
189void rtThreadInsert(PRTTHREADINT pThread, RTNATIVETHREAD NativeThread);
190#ifdef IN_RING3
191int rtThreadDoSetProcPriority(RTPROCPRIORITY enmPriority);
192#endif /* !IN_RING0 */
193#ifdef IPRT_WITH_GENERIC_TLS
194void rtThreadClearTlsEntry(RTTLS iTls);
195void rtThreadTlsDestruction(PRTTHREADINT pThread); /* in tls-generic.cpp */
196#endif
197
198/**
199 * Gets the thread state.
200 *
201 * @returns The thread state.
202 * @param pThread The thread.
203 */
204DECLINLINE(RTTHREADSTATE) rtThreadGetState(PRTTHREADINT pThread)
205{
206 return pThread->enmState;
207}
208
209RT_C_DECLS_END
210
211#endif
Note: See TracBrowser for help on using the repository browser.

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