]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/pthread_support.c
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995-2005 Apple Computer, Inc. All Rights Reserved */
34 #define _PTHREAD_CONDATTR_T
35 #define _PTHREAD_COND_T
36 #define _PTHREAD_MUTEXATTR_T
37 #define _PTHREAD_MUTEX_T
38 #define _PTHREAD_RWLOCKATTR_T
39 #define _PTHREAD_RWLOCK_T
41 #undef pthread_mutexattr_t
42 #undef pthread_mutex_t
43 #undef pthread_condattr_t
45 #undef pthread_rwlockattr_t
46 #undef pthread_rwlock_t
48 #include <sys/param.h>
49 #include <sys/resourcevar.h>
50 #include <sys/proc_internal.h>
51 #include <sys/kauth.h>
52 #include <sys/systm.h>
53 #include <sys/timeb.h>
54 #include <sys/times.h>
56 #include <sys/file_internal.h>
57 #include <sys/kernel.h>
59 #include <sys/signalvar.h>
60 #include <sys/syslog.h>
63 #include <sys/kdebug.h>
65 #include <sys/mount.h>
66 #include <sys/sysproto.h>
69 #include <kern/task.h>
70 #include <kern/thread.h>
72 #include <sys/pthread_internal.h>
74 #define PTHREAD_SYNCH_MAX 256
75 static pthread_mutex_t
* pmutex_trans_array
[PTHREAD_SYNCH_MAX
];
76 static pthread_cond_t
* pcond_trans_array
[PTHREAD_SYNCH_MAX
];
77 //static pthread_rwlock_t * prwlock_trans_array[PTHREAD_SYNCH_MAX];
80 pthread_id_to_mutex(int mutexid
)
82 pthread_mutex_t
* mtx
= NULL
;
85 if (mutexid
>= 0 && mutexid
< PTHREAD_SYNCH_MAX
) {
87 mtx
= pmutex_trans_array
[mutexid
];
91 MTX_UNLOCK(mtx
->lock
);
93 pthread_list_unlock();
100 pthread_id_mutex_add(pthread_mutex_t
* mutex
)
105 for(i
= 1; i
< PTHREAD_SYNCH_MAX
; i
++) {
106 if (pmutex_trans_array
[i
] == 0) {
107 pmutex_trans_array
[i
] = mutex
;
111 pthread_list_unlock();
112 if (i
== PTHREAD_SYNCH_MAX
)
119 pthread_id_mutex_remove(int mutexid
)
122 if (pmutex_trans_array
[mutexid
]) {
123 pmutex_trans_array
[mutexid
] = 0;
125 pthread_list_unlock();
130 pthread_mutex_release(pthread_mutex_t
* mutex
)
132 MTX_LOCK(mutex
->lock
);
134 MTX_UNLOCK(mutex
->lock
);
139 pthread_id_to_cond(int condid
)
141 pthread_cond_t
* cond
= NULL
;
144 if (condid
>= 0 && condid
< PTHREAD_SYNCH_MAX
) {
146 cond
= pcond_trans_array
[condid
];
148 COND_LOCK(cond
->lock
);
150 COND_UNLOCK(cond
->lock
);
152 pthread_list_unlock();
159 pthread_id_cond_add(pthread_cond_t
* cond
)
164 for(i
= 1; i
< PTHREAD_SYNCH_MAX
; i
++) {
165 if (pcond_trans_array
[i
] == 0) {
166 pcond_trans_array
[i
] = cond
;
170 pthread_list_unlock();
171 if (i
== PTHREAD_SYNCH_MAX
)
178 pthread_id_cond_remove(int condid
)
181 if (pcond_trans_array
[condid
]) {
182 pcond_trans_array
[condid
] = 0;
184 pthread_list_unlock();
189 pthread_cond_release(pthread_cond_t
* cond
)
191 COND_LOCK(cond
->lock
);
193 COND_UNLOCK(cond
->lock
);