Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Name : threadglobals.h
16 * Part of : PThread library
17 * Data structures needed for ptherad library
24 #ifndef THREADGLOBALS_H
25 #define THREADGLOBALS_H
34 //the semaphore structure
44 int iCount; //iCount and iMutex pair needed
45 //because of need for implementing trywait
47 RSemaphore iSemaphore;
48 /*******************************************************************
49 Overloading new and delete operators so that they will
50 allocate and deallocare memory from/to the private heap of backend
51 ********************************************************************/
52 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
54 Mem::FillZ(aBase, aSize); return aBase;
57 inline TAny* operator new(TUint aSize) __NO_THROW
59 return Backend()->Alloc(aSize);
62 inline TAny* operator new(TUint aSize, TLeave)
64 TAny* ptr = Backend()->Alloc(aSize);
67 User::Leave(KErrNoMemory);
72 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
74 return Backend()->Alloc(aSize + aExtraSize);
77 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
79 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
82 User::Leave(KErrNoMemory);
87 inline void operator delete(TAny *aPtr) __NO_THROW
89 Backend()->Free( aPtr );
93 typedef struct _sem_node
95 struct _sem_node *next;
97 /*******************************************************************
98 Overloading new and delete operators so that they will
99 allocate and deallocare memory from/to the private heap of backend
100 ********************************************************************/
101 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
103 Mem::FillZ(aBase, aSize); return aBase;
106 inline TAny* operator new(TUint aSize) __NO_THROW
108 return Backend()->Alloc(aSize);
111 inline TAny* operator new(TUint aSize, TLeave)
113 TAny* ptr = Backend()->Alloc(aSize);
116 User::Leave(KErrNoMemory);
121 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
123 return Backend()->Alloc(aSize + aExtraSize);
126 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
128 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
131 User::Leave(KErrNoMemory);
136 inline void operator delete(TAny *aPtr) __NO_THROW
138 Backend()->Free( aPtr );
143 // Thread default attributes
144 #define DEFAULT_STACK_SIZE 0x2000
145 #define DEFAULT_DETACH_STATE PTHREAD_CREATE_JOINABLE
147 #define THR_DISABLE_PTHREAD_TRACE 1
149 #define DEFAULT_THREAD_PRIORITY 100
151 #ifdef THR_DISABLE_PTHREAD_TRACE
153 #define THR_PRINTF(string) \
157 #else //THR_DISABLE_PTHREAD_TRACE
159 #define THR_PRINTF(string) \
162 RDebug::Printf(string);\
166 #endif //THR_DISABLE_PTHREAD_TRACE
168 #define THR_NULL_ASSERT(x,val,format) \
172 THR_PRINTF(format); \
177 #define STAT_FLAG_SIZE (PTHREAD_KEYS_MAX / 32)
202 destructor_routine destr;
205 // TLS Keys link list node
206 typedef struct _pkey_node
209 struct _pkey_node *next;
211 /*******************************************************************
212 Overloading new and delete operators so that they will
213 allocate and deallocare memory from/to the private heap of backend
214 ********************************************************************/
215 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
217 Mem::FillZ(aBase, aSize); return aBase;
220 inline TAny* operator new(TUint aSize) __NO_THROW
222 return Backend()->Alloc(aSize);
225 inline TAny* operator new(TUint aSize, TLeave)
227 TAny* ptr = Backend()->Alloc(aSize);
230 User::Leave(KErrNoMemory);
235 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
237 return Backend()->Alloc(aSize + aExtraSize);
240 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
242 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
245 User::Leave(KErrNoMemory);
250 inline void operator delete(TAny *aPtr) __NO_THROW
252 Backend()->Free( aPtr );
256 typedef struct _pthread_node _pthread_node_t;
258 // MinGW GCC compiler does not like typedef struct definitions with no tag
259 typedef struct _global_data_tag
261 typedef struct _global_data_t
264 _pthread_node_t *start;
265 unsigned int threadCount;
266 RMutex lockThreadTable;
267 RMutex globalLockForMutex;
269 _pthread_key_node pthread_key_list[PTHREAD_KEYS_MAX];
270 unsigned int statusflag[STAT_FLAG_SIZE];
272 _sem_node_t *semStart;
274 /*******************************************************************
275 Overloading new and delete operators so that they will
276 allocate and deallocare memory from/to the private heap of backend
277 ********************************************************************/
279 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
281 Mem::FillZ(aBase, aSize); return aBase;
284 inline TAny* operator new(TUint aSize) __NO_THROW
286 return Backend()->Alloc(aSize);
289 inline TAny* operator new(TUint aSize, TLeave)
291 TAny* ptr = Backend()->Alloc(aSize);
294 User::Leave(KErrNoMemory);
299 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
301 return Backend()->Alloc(aSize + aExtraSize);
304 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
306 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
309 User::Leave(KErrNoMemory);
314 inline void operator delete(TAny *aPtr) __NO_THROW
316 Backend()->Free( aPtr );
319 inline void operator delete(TAny *aPtr, TLeave)
321 Backend()->Free( aPtr );
325 inline void operator delete(TAny *aPtr, TAny* aBase) __NO_THROW
328 Backend()->Free( aPtr );
332 inline void operator delete(TAny *aPtr, TUint aExtraSize) __NO_THROW
334 aExtraSize = aExtraSize;
335 Backend()->Free( aPtr );
339 inline void operator delete(TAny *aPtr, TLeave, TUint aExtraSize)
341 aExtraSize = aExtraSize;
342 Backend()->Free( aPtr );
352 _global_data_t* GetGlobals();
353 #define glbHeadNode GetGlobals()
355 typedef struct _pthread_node
357 struct _pthread_node *next;
359 _global_data_t *glbDataPtr;
360 unsigned int detachState;
361 unsigned int threadState;
363 TBool hasAnyThreadJoined;
365 unsigned int threadId;
366 // void *tls[PTHREAD_KEYS_MAX];
367 _pkey_node_t *tlsHead;
371 /*******************************************************************
372 Overloading new and delete operators so that they will
373 allocate and deallocare memory from/to the private heap of backend
374 ********************************************************************/
375 inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW
377 Mem::FillZ(aBase, aSize); return aBase;
380 inline TAny* operator new(TUint aSize) __NO_THROW
382 return Backend()->Alloc(aSize);
385 inline TAny* operator new(TUint aSize, TLeave)
387 TAny* ptr = Backend()->Alloc(aSize);
390 User::Leave(KErrNoMemory);
395 inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW
397 return Backend()->Alloc(aSize + aExtraSize);
400 inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize)
402 TAny* ptr = Backend()->Alloc(aSize + aExtraSize);
405 User::Leave(KErrNoMemory);
410 inline void operator delete(TAny *aPtr) __NO_THROW
412 Backend()->Free( aPtr );
419 #endif //THREADGLOBALS_H