| 1 | /* $Id: thread.h 2254 2005-07-17 12:25:44Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | *
|
|---|
| 4 | * LIBC Thread Handling.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2004 knut st. osmundsen <[email protected]>
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of InnoTek LIBC.
|
|---|
| 10 | *
|
|---|
| 11 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
|---|
| 12 | * it under the terms of the GNU General Public License as published by
|
|---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 14 | * (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | * GNU General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU General Public License
|
|---|
| 22 | * along with InnoTek LIBC; if not, write to the Free Software
|
|---|
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 24 | *
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #ifndef __InnoTekLIBC_thread_h__
|
|---|
| 28 | #define __InnoTekLIBC_thread_h__
|
|---|
| 29 |
|
|---|
| 30 | /*******************************************************************************
|
|---|
| 31 | * Defined Constants And Macros *
|
|---|
| 32 | *******************************************************************************/
|
|---|
| 33 | /** Maximum number of TLS variables supported by LIBC.
|
|---|
| 34 | * The current limit (128) is higher than for instance WinNT. But if
|
|---|
| 35 | * you think we're wasting space, look at the page padding of the thread
|
|---|
| 36 | * structure... */
|
|---|
| 37 | #define __LIBC_TLS_MAX 128
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | /*******************************************************************************
|
|---|
| 41 | * Header Files *
|
|---|
| 42 | *******************************************************************************/
|
|---|
| 43 | #include <sys/cdefs.h>
|
|---|
| 44 | #include <time.h> /* struct tm; */
|
|---|
| 45 | #include <signal.h>
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | /*******************************************************************************
|
|---|
| 49 | * Structures and Typedefs *
|
|---|
| 50 | *******************************************************************************/
|
|---|
| 51 | struct _uheap;
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * sigwait,sigwaitinfo, sigtimedwait data.
|
|---|
| 55 | */
|
|---|
| 56 | typedef volatile struct __libc_thread_sigwait
|
|---|
| 57 | {
|
|---|
| 58 | /** Done waitin' indicator.*/
|
|---|
| 59 | volatile int fDone;
|
|---|
| 60 | /** The signals we're waiting for. */
|
|---|
| 61 | sigset_t SigSetWait;
|
|---|
| 62 | /** The where to return signal info. */
|
|---|
| 63 | siginfo_t SigInfo;
|
|---|
| 64 | } __LIBC_THREAD_SIGWAIT, *__LIBC_PTHREAD_SIGWAIT;
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | /**
|
|---|
| 68 | * sigsuspend data.
|
|---|
| 69 | */
|
|---|
| 70 | typedef volatile struct __libc_thread_sigsuspend
|
|---|
| 71 | {
|
|---|
| 72 | /** Done waitin' indicator.*/
|
|---|
| 73 | volatile int fDone;
|
|---|
| 74 | } __LIBC_THREAD_SIGSUSPEND, *__LIBC_PTHREAD_SIGSUSPEND;
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | /**
|
|---|
| 78 | * Signal notification callback function.
|
|---|
| 79 | *
|
|---|
| 80 | * This is a notification which can be used to correct the state of
|
|---|
| 81 | * a system object before any user code is executed.
|
|---|
| 82 | *
|
|---|
| 83 | * The semaphore lock is hold and signals are all on hold, so be very careful with waitin
|
|---|
| 84 | * on other semphores and stuff like that. Crashing is totally forbidden. :-)
|
|---|
| 85 | *
|
|---|
| 86 | * @param iSignalNo The signal number.
|
|---|
| 87 | * @param pvUser The user argument.
|
|---|
| 88 | */
|
|---|
| 89 | typedef void __LIBC_FNSIGCALLBACK(int iSignalNo, void *pvUser);
|
|---|
| 90 | /** Pointer to a signal callback function. */
|
|---|
| 91 | typedef __LIBC_FNSIGCALLBACK *__LIBC_PFNSIGCALLBACK;
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | /**
|
|---|
| 95 | * Per thread structure for LIBC.
|
|---|
| 96 | *
|
|---|
| 97 | * This structure contains buffers and variables which in a single threaded
|
|---|
| 98 | * LIBC would be static.
|
|---|
| 99 | *
|
|---|
| 100 | * Members most frequently used have been put together at the front.
|
|---|
| 101 | */
|
|---|
| 102 | typedef struct __libc_thread
|
|---|
| 103 | {
|
|---|
| 104 | /** errno value. (Comes first, see errnofun.s.) */
|
|---|
| 105 | int iErrNo;
|
|---|
| 106 | /** Default tiled heap. */
|
|---|
| 107 | struct _uheap * pTiledHeap;
|
|---|
| 108 | /** Default regular heap. */
|
|---|
| 109 | struct _uheap * pRegularHeap;
|
|---|
| 110 | /** Reference count. */
|
|---|
| 111 | volatile unsigned cRefs;
|
|---|
| 112 | /** Thread Id. */
|
|---|
| 113 | unsigned tid;
|
|---|
| 114 | /** Pointer to next thread in the list. */
|
|---|
| 115 | struct __libc_thread *pNext;
|
|---|
| 116 | /** New TLS variable array. */
|
|---|
| 117 | void *apvTLS[__LIBC_TLS_MAX];
|
|---|
| 118 | /** Old TLS variable. */
|
|---|
| 119 | void *pvThreadStoreVar;
|
|---|
| 120 |
|
|---|
| 121 | /** The nesting depth of the default logger. */
|
|---|
| 122 | unsigned cDefLoggerDepth;
|
|---|
| 123 | /** Buffer used by asctime() and indirectly by ctime() . (Adds two 2 bytes for padding). */
|
|---|
| 124 | char szAscTimeAndCTimeBuf[26+2];
|
|---|
| 125 | /** Buffer used by gmtime() and localtime(). */
|
|---|
| 126 | struct tm GmTimeAndLocalTimeBuf;
|
|---|
| 127 | /** Buffer used by tmpnam(). */
|
|---|
| 128 | char szTmpNamBuf[16];
|
|---|
| 129 | /** Current posistion of strtok(). */
|
|---|
| 130 | char *pszStrTokPos;
|
|---|
| 131 | /** Buffer used by strerror() to format unknown error values. */
|
|---|
| 132 | char szStrErrorBuf[28];
|
|---|
| 133 | /** Buffer used by _getvol(). */
|
|---|
| 134 | char szVolLabelBuf[12];
|
|---|
| 135 | /** Buffer used by ttyname(). */
|
|---|
| 136 | char szTTYNameBuf[32];
|
|---|
| 137 |
|
|---|
| 138 | /** Pending signals.
|
|---|
| 139 | * Protected by the signal semaphore. */
|
|---|
| 140 | sigset_t SigSetPending;
|
|---|
| 141 | /** Blocked signals.
|
|---|
| 142 | * Protected by the signal semaphore. */
|
|---|
| 143 | sigset_t SigSetBlocked;
|
|---|
| 144 | /** Old Blocked signals. Used by sigsuspend().
|
|---|
| 145 | * sigsuspend() sets this and fSigSetBlockedOld. When a signal is to be
|
|---|
| 146 | * delivered this member will be pushed on the stack for use on an eventual
|
|---|
| 147 | * return. fSigSetBlockOld will be clared.
|
|---|
| 148 | * Protected by the signal semaphore. */
|
|---|
| 149 | sigset_t SigSetBlockedOld;
|
|---|
| 150 |
|
|---|
| 151 | /** Signals queued for delivery on this thread.
|
|---|
| 152 | * Protected by the signal semaphore. */
|
|---|
| 153 | struct
|
|---|
| 154 | {
|
|---|
| 155 | struct SignalQueued *pHead;
|
|---|
| 156 | struct SignalQueued *pTail;
|
|---|
|
|---|