]>
git.saurik.com Git - apple/libc.git/blob - threads/cprocs.c
   2  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * The contents of this file constitute Original Code as defined in and 
   7  * are subject to the Apple Public Source License Version 1.1 (the 
   8  * "License").  You may not use this file except in compliance with the 
   9  * License.  Please obtain a copy of the License at 
  10  * http://www.apple.com/publicsource and read it before using this file. 
  12  * This Original Code and all software distributed under the License are 
  13  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  14  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  15  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  16  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the 
  17  * License for the specific language governing rights and limitations 
  20  * @APPLE_LICENSE_HEADER_END@ 
  23  * Mach Operating System 
  24  * Copyright (c) 1989 Carnegie-Mellon University 
  25  * All rights reserved.  The CMU software License Agreement specifies 
  26  * the terms and conditions for use and redistribution. 
  31  * 22-July-93 Blaine Garst 
  32  *      fixed kernel cache set up of cproc info 
  34  * 05-April-90  Morris Meyer (mmeyer) at NeXT 
  35  *      Fixed bug in cproc_fork_child() where the first cproc would 
  36  *      try doing a msg_rpc() with an invalid reply port. 
  41  * cprocs.c - by Eric Cooper 
  43  * Implementation of cprocs (lightweight processes) 
  44  * and primitive synchronization operations. 
  47 #include "pthread_internals.h" 
  49 #include "cthread_internals.h" 
  50 #include <mach/message.h> 
  55 extern void stack_init(); 
  56 extern void alloc_stack(), _dealloc_stack(); 
  61 extern mach_port_t 
mach_thread_self(); 
  62 extern boolean_t 
swtch_pri(); 
  64 private int cprocs_started 
= FALSE
; 
  84                 ASSERT(SHOULDNT_HAPPEN
); 
  88                 cthread_name(p
->incarnation
), s
); 
  92 print_cproc_queue(name
, queue
) 
  94         cthread_queue_t queue
; 
  96         printf("[%s] %s:", cthread_name(cthread_self()), name
); 
  97         cthread_queue_map(queue
, cproc_t
, print_cproc
); 
 100 #endif  CTHREADS_DEBUG 
 102 private int cproc_lock 
= 0;             /* unlocked */ 
 103 private cproc_t cprocs 
= NO_CPROC
;      /* linked list of cprocs */ 
 105 #ifdef  CTHREADS_DEBUG 
 111         printf("[%s] cprocs:", cthread_name(cthread_self())); 
 112         for (p 
= cprocs
; p 
!= NO_CPROC
; p 
= p
->link
) 
 116 #endif  CTHREADS_DEBUG 
 119  * Routines for supporting fork() of multi-threaded programs. 
 122 void _cproc_fork_child() 
 124  * Called in the child after a fork().  Resets cproc data structures to 
 125  * coincide with the reality that we now have a single cproc and cthread. 
 130         pself 
= pthread_self(); 
 131         pself
->reply_port 
= MACH_PORT_NULL
; 
 135  *      Support for a per-thread UNIX errno. 
 140 void cthread_set_errno_self(error
) 
 146         if (t 
&& (t
->sig 
== _PTHREAD_SIG
)) {