diff options
| author | David Lovemore | 2012-08-09 16:09:07 +0100 |
|---|---|---|
| committer | David Lovemore | 2012-08-09 16:09:07 +0100 |
| commit | 0720be47b8bf3aa1d7e8d3bc1636b2dad59e8a3c (patch) | |
| tree | 512d6e3fd4b6a3fc29002ab83a11d2f07689a7a4 /mps/code | |
| parent | be8a839d8344942f7e4ba8d22d2e1bdc63d3e002 (diff) | |
| download | emacs-0720be47b8bf3aa1d7e8d3bc1636b2dad59e8a3c.tar.gz emacs-0720be47b8bf3aa1d7e8d3bc1636b2dad59e8a3c.zip | |
Deleted no longer used thlii4.c -- renamed to thli.c
Copied from Perforce
Change: 178877
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
| -rw-r--r-- | mps/code/thlii4.c | 346 |
1 files changed, 0 insertions, 346 deletions
diff --git a/mps/code/thlii4.c b/mps/code/thlii4.c deleted file mode 100644 index 4f96e9c5fb1..00000000000 --- a/mps/code/thlii4.c +++ /dev/null | |||
| @@ -1,346 +0,0 @@ | |||
| 1 | /* thlii4.c: Threads Manager for Intel x86 systems with LinuxThreads | ||
| 2 | * | ||
| 3 | * $Id$ | ||
| 4 | * Copyright (c) 2001 Ravenbrook Limited. See end of file for license. | ||
| 5 | * | ||
| 6 | * .purpose: This is a pthreads implementation of the threads manager. | ||
| 7 | * This implements <code/th.h>. | ||
| 8 | * | ||
| 9 | * .design: See <design/thread-manager/>. | ||
| 10 | * | ||
| 11 | * .thread.id: The thread id is used to identify the current thread. | ||
| 12 | * | ||
| 13 | * ASSUMPTIONS | ||
| 14 | * | ||
| 15 | * .error.resume: PThreadextResume is assumed to succeed unless the thread | ||
| 16 | * has been destroyed. | ||
| 17 | * .error.suspend: PThreadextSuspend is assumed to succeed unless the thread | ||
| 18 | * has been destroyed. In this case, the suspend context is set to NULL; | ||
| 19 | * | ||
| 20 | * .stack.full-descend: assumes full descending stack. | ||
| 21 | * i.e. stack pointer points to the last allocated location; | ||
| 22 | * stack grows downwards. | ||
| 23 | * | ||
| 24 | * .stack.below-bottom: it's legal for the stack pointer to be at a | ||
| 25 | * higher address than the registered bottom of stack. This might | ||
| 26 | * happen if the stack of another thread doesn't contain any frames | ||
| 27 | * belonging to the client language. In this case, the stack should | ||
| 28 | * not be scanned. | ||
| 29 | * | ||
| 30 | * .stack.align: assume roots on the stack are always word-aligned, | ||
| 31 | * but don't assume that the stack pointer is necessarily | ||
| 32 | * word-aligned at the time of reading the context of another thread. | ||
| 33 | * | ||
| 34 | * .sp: The stack pointer in the context is ESP. | ||
| 35 | * .context.regroots: The root regs are EDI, ESI, EBX, EDX, ECX, EAX are | ||
| 36 | * assumed to be recorded in the context at pointer-aligned boundaries. | ||
| 37 | */ | ||
| 38 | |||
| 39 | #include "prmcix.h" | ||
| 40 | #include "mpm.h" | ||
| 41 | |||
| 42 | #if !defined(MPS_OS_LI) || !defined(MPS_ARCH_I4) | ||
| 43 | #error "Compiling thlii4 when MPS_OS_LI or MPS_ARCH_I4 not defined." | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #include <pthread.h> | ||
| 47 | #include "pthrdext.h" | ||
| 48 | |||
| 49 | SRCID(thlii4, "$Id$"); | ||
| 50 | |||
| 51 | |||
| 52 | /* ThreadStruct -- thread desriptor */ | ||
| 53 | |||
| 54 | typedef struct ThreadStruct { /* PThreads thread structure */ | ||
| 55 | Sig sig; /* <design/sig/> */ | ||
| 56 | Serial serial; /* from arena->threadSerial */ | ||
| 57 | Arena arena; /* owning arena */ | ||
| 58 | RingStruct arenaRing; /* threads attached to arena */ | ||
| 59 | PThreadextStruct thrextStruct; /* PThreads extension */ | ||
| 60 | pthread_t id; /* Pthread object of thread */ | ||
| 61 | MutatorFaultContext mfc; /* Context if thread is suspended */ | ||
| 62 | } ThreadStruct; | ||
| 63 | |||
| 64 | |||
| 65 | /* ThreadCheck -- check a thread */ | ||
| 66 | |||
| 67 | Bool ThreadCheck(Thread thread) | ||
| 68 | { | ||
| 69 | CHECKS(Thread, thread); | ||
| 70 | CHECKU(Arena, thread->arena); | ||
| 71 | CHECKL(thread->serial < thread->arena->threadSerial); | ||
| 72 | CHECKL(RingCheck(&thread->arenaRing)); | ||
| 73 | CHECKD(PThreadext, &thread->thrextStruct); | ||
| 74 | return TRUE; | ||
| 75 | } | ||
| 76 | |||
| 77 | Bool ThreadCheckSimple(Thread thread) | ||
| 78 | { | ||
| 79 | CHECKS(Thread, thread); | ||
| 80 | return TRUE; | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | /* ThreadRegister -- register a thread with an arena */ | ||
| 85 | |||
| 86 | Res ThreadRegister(Thread *threadReturn, Arena arena) | ||
| 87 | { | ||
| 88 | Res res; | ||
| 89 | Thread thread; | ||
| 90 | void *p; | ||
| 91 | |||
| 92 | AVER(threadReturn != NULL); | ||
| 93 | AVERT(Arena, arena); | ||
| 94 | |||
| 95 | res = ControlAlloc(&p, arena, sizeof(ThreadStruct), | ||
| 96 | /* withReservoirPermit */ FALSE); | ||
| 97 | if(res != ResOK) | ||
| 98 | return res; | ||
| 99 | thread = (Thread)p; | ||
| 100 | |||
| 101 | thread->id = pthread_self(); | ||
| 102 | |||
| 103 | RingInit(&thread->arenaRing); | ||
| 104 | |||
| 105 | thread->sig = ThreadSig; | ||
| 106 | thread->serial = arena->threadSerial; | ||
| 107 | ++arena->threadSerial; | ||
| 108 | thread->arena = arena; | ||
| 109 | thread->mfc = NULL; | ||
| 110 | |||
| 111 | PThreadextInit(&thread->thrextStruct, thread->id); | ||
| 112 | |||
| 113 | AVERT(Thread, thread); | ||
| 114 | |||
| 115 | RingAppend(ArenaThreadRing(arena), &thread->arenaRing); | ||
| 116 | |||
| 117 | *threadReturn = thread; | ||
| 118 | return ResOK; | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | /* ThreadDeregister -- deregister a thread from an arena */ | ||
| 123 | |||
| 124 | void ThreadDeregister(Thread thread, Arena arena) | ||
| 125 | { | ||
| 126 | AVERT(Thread, thread); | ||
| 127 | AVERT(Arena, arena); | ||
| 128 | |||
| 129 | RingRemove(&thread->arenaRing); | ||
| 130 | |||
| 131 | thread->sig = SigInvalid; | ||
| 132 | |||
| 133 | RingFinish(&thread->arenaRing); | ||
| 134 | |||
| 135 | PThreadextFinish(&thread->thrextStruct); | ||
| 136 | |||
| 137 | ControlFree(arena, thread, sizeof(ThreadStruct)); | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | /* mapThreadRing -- map over threads on ring calling a function on each one | ||
| 142 | * except the current thread | ||
| 143 | */ | ||
| 144 | |||
| 145 | static void mapThreadRing(Ring threadRing, void (*func)(Thread)) | ||
| 146 | { | ||
| 147 | Ring node, next; | ||
| 148 | pthread_t self; | ||
| 149 | |||
| 150 | AVERT(Ring, threadRing); | ||
| 151 | |||
| 152 | self = pthread_self(); | ||
| 153 | RING_FOR(node, threadRing, next) { | ||
| 154 | Thread thread = RING_ELT(Thread, arenaRing, node); | ||
| 155 | AVERT(Thread, thread); | ||
| 156 | if(! pthread_equal(self, thread->id)) /* .thread.id */ | ||
| 157 | (*func)(thread); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | /* ThreadRingSuspend -- suspend all threads on a ring, expect the current one */ | ||
| 163 | |||
| 164 | |||
| 165 | static void threadSuspend(Thread thread) | ||
| 166 | { | ||
| 167 | /* .error.suspend */ | ||
| 168 | /* In the error case (PThreadextSuspend returning ResFAIL), we */ | ||
| 169 | /* assume the thread has been destroyed. */ | ||
| 170 | /* In which case we simply continue. */ | ||
| 171 | Res res; | ||
| 172 | res = PThreadextSuspend(&thread->thrextStruct, &thread->mfc); | ||
| 173 | if(res != ResOK) | ||
| 174 | thread->mfc = NULL; | ||
| 175 | } | ||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | void ThreadRingSuspend(Ring threadRing) | ||
| 180 | { | ||
| 181 | mapThreadRing(threadRing, threadSuspend); | ||
| 182 | } | ||
| 183 | |||
| 184 | |||
| 185 | /* ThreadRingResume -- resume all threads on a ring (expect the current one) */ | ||
| 186 | |||
| 187 | |||
| 188 | static void threadResume(Thread thread) | ||
| 189 | { | ||
| 190 | /* .error.resume */ | ||
| 191 | /* If the previous suspend failed (thread->mfc == NULL), */ | ||
| 192 | /* or in the error case (PThreadextResume returning ResFAIL), */ | ||
| 193 | /* assume the thread has been destroyed. */ | ||
| 194 | /* In which case we simply continue. */ | ||
| 195 | if(thread->mfc != NULL) { | ||
| 196 | (void)PThreadextResume(&thread->thrextStruct); | ||
| 197 | thread->mfc = NULL; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | void ThreadRingResume(Ring threadRing) | ||
| 202 | { | ||
| 203 | mapThreadRing(threadRing, threadResume); | ||
| 204 | } | ||
| 205 | |||
| 206 | |||
| 207 | /* ThreadRingThread -- return the thread at the given ring element */ | ||
| 208 | |||
| 209 | Thread ThreadRingThread(Ring threadRing) | ||
| 210 | { | ||
| 211 | Thread thread; | ||
| 212 | AVERT(Ring, threadRing); | ||
| 213 | thread = RING_ELT(Thread, arenaRing, threadRing); | ||
| 214 | AVERT(Thread, thread); | ||
| 215 | return thread; | ||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | /* ThreadArena -- get the arena of a thread | ||
| 220 | * | ||
| 221 | * Must be thread-safe. See <design/interface-c/#thread-safety>. | ||
| 222 | */ | ||
| 223 | |||
| 224 | Arena ThreadArena(Thread thread) | ||
| 225 | { | ||
| 226 | /* Can't check thread as that would not be thread-safe. */ | ||
| 227 | return thread->arena; | ||
| 228 | } | ||
| 229 | |||
| 230 | |||
| 231 | /* ThreadScan -- scan the state of a thread (stack and regs) */ | ||
| 232 | |||
| 233 | Res ThreadScan(ScanState ss, Thread thread, void *stackBot) | ||
| 234 | { | ||
| 235 | pthread_t self; | ||
| 236 | Res res; | ||
| 237 | |||
| 238 | AVERT(Thread, thread); | ||
| 239 | self = pthread_self(); | ||
| 240 | if(pthread_equal(self, thread->id)) { | ||
| 241 | /* scan this thread's stack */ | ||
| 242 | res = StackScan(ss, stackBot); | ||
| 243 | if(res != ResOK) | ||
| 244 | return res; | ||
| 245 | } else { | ||
| 246 | MutatorFaultContext mfc; | ||
| 247 | Addr *stackBase, *stackLimit, stackPtr; | ||
| 248 | mcontext_t *mc; | ||
| 249 | mfc = thread->mfc; | ||
| 250 | if(mfc == NULL) { | ||
| 251 | /* .error.suspend */ | ||
| 252 | /* We assume that the thread must have been destroyed. */ | ||
| 253 | /* We ignore the situation by returning immediately. */ | ||
| 254 | return ResOK; | ||
| 255 | } | ||
| 256 | |||
| 257 | stackPtr = (Addr)mfc->ucontext->uc_stack.ss_sp; /* .i3.sp */ | ||
| 258 | /* .stack.align */ | ||
| 259 | stackBase = (Addr *)AddrAlignUp(stackPtr, sizeof(Addr)); | ||
| 260 | stackLimit = (Addr *)stackBot; | ||
| 261 | if (stackBase >= stackLimit) | ||
| 262 | return ResOK; /* .stack.below-bottom */ | ||
| 263 | |||
| 264 | /* scan stack inclusive of current sp and exclusive of | ||
| 265 | * stackBot (.stack.full-descend) | ||
| 266 | */ | ||
| 267 | res = TraceScanAreaTagged(ss, stackBase, stackLimit); | ||
| 268 | if(res != ResOK) | ||
| 269 | return res; | ||
| 270 | |||
| 271 | /* (.context.regroots) | ||
| 272 | * This scans the root registers (.context.regroots). It also | ||
| 273 | * unecessarily scans the rest of the context. The optimisation | ||
| 274 | * to scan only relevent parts would be machine dependent. | ||
| 275 | */ | ||
| 276 | mc = &mfc->ucontext->uc_mcontext; | ||
| 277 | res = TraceScanAreaTagged(ss, (Addr *)mc, | ||
| 278 | (Addr *)((char *)mc + sizeof(*mc))); | ||
| 279 | if(res != ResOK) | ||
| 280 | return res; | ||
| 281 | } | ||
| 282 | |||
| 283 | return ResOK; | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | /* ThreadDescribe -- describe a thread */ | ||
| 288 | |||
| 289 | Res ThreadDescribe(Thread thread, mps_lib_FILE *stream) | ||
| 290 | { | ||
| 291 | Res res; | ||
| 292 | |||
| 293 | res = WriteF(stream, | ||
| 294 | "Thread $P ($U) {\n", (WriteFP)thread, (WriteFU)thread->serial, | ||
| 295 | " arena $P ($U)\n", | ||
| 296 | (WriteFP)thread->arena, (WriteFU)thread->arena->serial, | ||
| 297 | " id $U\n", (WriteFU)thread->id, | ||
| 298 | "} Thread $P ($U)\n", (WriteFP)thread, (WriteFU)thread->serial, | ||
| 299 | NULL); | ||
| 300 | if(res != ResOK) | ||
| 301 | return res; | ||
| 302 | |||
| 303 | return ResOK; | ||
| 304 | } | ||
| 305 | |||
| 306 | |||
| 307 | /* C. COPYRIGHT AND LICENSE | ||
| 308 | * | ||
| 309 | * Copyright (C) 2001-2002 Ravenbrook Limited <http://www.ravenbrook.com/>. | ||
| 310 | * All rights reserved. This is an open source license. Contact | ||
| 311 | * Ravenbrook for commercial licensing options. | ||
| 312 | * | ||
| 313 | * Redistribution and use in source and binary forms, with or without | ||
| 314 | * modification, are permitted provided that the following conditions are | ||
| 315 | * met: | ||
| 316 | * | ||
| 317 | * 1. Redistributions of source code must retain the above copyright | ||
| 318 | * notice, this list of conditions and the following disclaimer. | ||
| 319 | * | ||
| 320 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 321 | * notice, this list of conditions and the following disclaimer in the | ||
| 322 | * documentation and/or other materials provided with the distribution. | ||
| 323 | * | ||
| 324 | * 3. Redistributions in any form must be accompanied by information on how | ||
| 325 | * to obtain complete source code for this software and any accompanying | ||
| 326 | * software that uses this software. The source code must either be | ||
| 327 | * included in the distribution or be available for no more than the cost | ||
| 328 | * of distribution plus a nominal fee, and must be freely redistributable | ||
| 329 | * under reasonable conditions. For an executable file, complete source | ||
| 330 | * code means the source code for all modules it contains. It does not | ||
| 331 | * include source code for modules or files that typically accompany the | ||
| 332 | * major components of the operating system on which the executable file | ||
| 333 | * runs. | ||
| 334 | * | ||
| 335 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 336 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 337 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 338 | * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 339 | * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 340 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 341 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
| 342 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| 343 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 344 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 345 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 346 | */ | ||