]>
git.saurik.com Git - apple/libc.git/blob - threads/cprocs.c
72b6f5b447e7c225539d6858ffab07a68165e2cd
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
34 * 22-July-93 Blaine Garst
35 * fixed kernel cache set up of cproc info
37 * 05-April-90 Morris Meyer (mmeyer) at NeXT
38 * Fixed bug in cproc_fork_child() where the first cproc would
39 * try doing a msg_rpc() with an invalid reply port.
44 * cprocs.c - by Eric Cooper
46 * Implementation of cprocs (lightweight processes)
47 * and primitive synchronization operations.
50 #include "pthread_internals.h"
52 #include "cthread_internals.h"
53 #include <mach/message.h>
58 extern void stack_init();
59 extern void alloc_stack(), _dealloc_stack();
64 extern mach_port_t
mach_thread_self();
65 extern boolean_t
swtch_pri();
67 private int cprocs_started
= FALSE
;
87 ASSERT(SHOULDNT_HAPPEN
);
91 cthread_name(p
->incarnation
), s
);
95 print_cproc_queue(name
, queue
)
97 cthread_queue_t queue
;
99 printf("[%s] %s:", cthread_name(cthread_self()), name
);
100 cthread_queue_map(queue
, cproc_t
, print_cproc
);
103 #endif CTHREADS_DEBUG
105 private int cproc_lock
= 0; /* unlocked */
106 private cproc_t cprocs
= NO_CPROC
; /* linked list of cprocs */
108 #ifdef CTHREADS_DEBUG
114 printf("[%s] cprocs:", cthread_name(cthread_self()));
115 for (p
= cprocs
; p
!= NO_CPROC
; p
= p
->link
)
119 #endif CTHREADS_DEBUG
122 * Routines for supporting fork() of multi-threaded programs.
125 void _cproc_fork_child()
127 * Called in the child after a fork(). Resets cproc data structures to
128 * coincide with the reality that we now have a single cproc and cthread.
133 pself
= pthread_self();
134 pself
->reply_port
= MACH_PORT_NULL
;
138 * Support for a per-thread UNIX errno.
143 void cthread_set_errno_self(error
)
149 if (t
&& (t
->sig
== _PTHREAD_SIG
)) {