Deleted Added
full compact
thr_sem.c (125522) thr_sem.c (139023)
1/*
2 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
1/*
2 * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $FreeBSD: head/lib/libkse/thread/thr_sem.c 125522 2004-02-06 15:20:56Z deischen $
29 * $FreeBSD: head/lib/libkse/thread/thr_sem.c 139023 2004-12-18 18:07:37Z deischen $
30 */
31
32#include "namespace.h"
33#include <sys/queue.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <pthread.h>
37#include <semaphore.h>

--- 80 unchanged lines hidden (view full) ---

118 return (sem);
119}
120
121int
122_sem_init(sem_t *sem, int pshared, unsigned int value)
123{
124 semid_t semid;
125
30 */
31
32#include "namespace.h"
33#include <sys/queue.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <pthread.h>
37#include <semaphore.h>

--- 80 unchanged lines hidden (view full) ---

118 return (sem);
119}
120
121int
122_sem_init(sem_t *sem, int pshared, unsigned int value)
123{
124 semid_t semid;
125
126 semid = SEM_USER;
126 semid = (semid_t)SEM_USER;
127 if ((pshared != 0) && (ksem_init(&semid, value) != 0))
128 return (-1);
129
130 (*sem) = sem_alloc(value, semid, pshared);
131 if ((*sem) == NULL) {
132 if (pshared != 0)
133 ksem_destroy(semid);
134 return (-1);

--- 5 unchanged lines hidden (view full) ---

140_sem_wait(sem_t *sem)
141{
142 struct pthread *curthread;
143 int retval;
144
145 if (sem_check_validity(sem) != 0)
146 return (-1);
147
127 if ((pshared != 0) && (ksem_init(&semid, value) != 0))
128 return (-1);
129
130 (*sem) = sem_alloc(value, semid, pshared);
131 if ((*sem) == NULL) {
132 if (pshared != 0)
133 ksem_destroy(semid);
134 return (-1);

--- 5 unchanged lines hidden (view full) ---

140_sem_wait(sem_t *sem)
141{
142 struct pthread *curthread;
143 int retval;
144
145 if (sem_check_validity(sem) != 0)
146 return (-1);
147
148 curthread = _get_curthread();
148 if ((*sem)->syssem != 0) {
149 if ((*sem)->syssem != 0) {
149 curthread = _get_curthread();
150 _thr_cancel_enter(curthread);
151 retval = ksem_wait((*sem)->semid);
152 _thr_cancel_leave(curthread, retval != 0);
153 }
154 else {
155 pthread_testcancel();
156 _pthread_mutex_lock(&(*sem)->lock);
157
158 while ((*sem)->count <= 0) {
159 (*sem)->nwaiters++;
150 _thr_cancel_enter(curthread);
151 retval = ksem_wait((*sem)->semid);
152 _thr_cancel_leave(curthread, retval != 0);
153 }
154 else {
155 pthread_testcancel();
156 _pthread_mutex_lock(&(*sem)->lock);
157
158 while ((*sem)->count <= 0) {
159 (*sem)->nwaiters++;
160 pthread_cleanup_push(decrease_nwaiters, sem);
160 THR_CLEANUP_PUSH(curthread, decrease_nwaiters, sem);
161 pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
161 pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
162 pthread_cleanup_pop(0);
162 THR_CLEANUP_POP(curthread, 0);
163 (*sem)->nwaiters--;
164 }
165 (*sem)->count--;
166
167 _pthread_mutex_unlock(&(*sem)->lock);
168
169 retval = 0;
170 }

--- 92 unchanged lines hidden ---
163 (*sem)->nwaiters--;
164 }
165 (*sem)->count--;
166
167 _pthread_mutex_unlock(&(*sem)->lock);
168
169 retval = 0;
170 }

--- 92 unchanged lines hidden ---