Deleted Added
full compact
thr_priority_queue.c (113661) thr_priority_queue.c (114187)
1/*
2 * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
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

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

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
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

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

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: head/lib/libkse/thread/thr_priority_queue.c 113661 2003-04-18 07:09:43Z deischen $
32 * $FreeBSD: head/lib/libkse/thread/thr_priority_queue.c 114187 2003-04-28 23:56:12Z deischen $
33 */
34#include <stdlib.h>
35#include <sys/queue.h>
36#include <string.h>
37#include <pthread.h>
38#include "thr_private.h"
39
40/* Prototypes: */

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

121 for (i = 0; i < pq->pq_size; i++) {
122 TAILQ_INIT(&pq->pq_lists[i].pl_head);
123 pq->pq_lists[i].pl_prio = i;
124 pq->pq_lists[i].pl_queued = 0;
125 }
126 /* Initialize the priority queue: */
127 TAILQ_INIT(&pq->pq_queue);
128 pq->pq_flags = 0;
33 */
34#include <stdlib.h>
35#include <sys/queue.h>
36#include <string.h>
37#include <pthread.h>
38#include "thr_private.h"
39
40/* Prototypes: */

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

121 for (i = 0; i < pq->pq_size; i++) {
122 TAILQ_INIT(&pq->pq_lists[i].pl_head);
123 pq->pq_lists[i].pl_prio = i;
124 pq->pq_lists[i].pl_queued = 0;
125 }
126 /* Initialize the priority queue: */
127 TAILQ_INIT(&pq->pq_queue);
128 pq->pq_flags = 0;
129 pq->pq_threads = 0;
129 }
130 return (ret);
131}
132
133void
134_pq_remove(pq_queue_t *pq, pthread_t pthread)
135{
136 int prio = pthread->active_priority;

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

146 * Remove this thread from priority list. Note that if
147 * the priority list becomes empty, it is not removed
148 * from the priority queue because another thread may be
149 * added to the priority list (resulting in a needless
150 * removal/insertion). Priority lists are only removed
151 * from the priority queue when _pq_first is called.
152 */
153 TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe);
130 }
131 return (ret);
132}
133
134void
135_pq_remove(pq_queue_t *pq, pthread_t pthread)
136{
137 int prio = pthread->active_priority;

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

147 * Remove this thread from priority list. Note that if
148 * the priority list becomes empty, it is not removed
149 * from the priority queue because another thread may be
150 * added to the priority list (resulting in a needless
151 * removal/insertion). Priority lists are only removed
152 * from the priority queue when _pq_first is called.
153 */
154 TAILQ_REMOVE(&pq->pq_lists[prio].pl_head, pthread, pqe);
154
155 pq->pq_threads--;
155 /* This thread is now longer in the priority queue. */
156 pthread->flags &= ~THR_FLAGS_IN_RUNQ;
156 /* This thread is now longer in the priority queue. */
157 pthread->flags &= ~THR_FLAGS_IN_RUNQ;
157
158
158 PQ_CLEAR_ACTIVE(pq);
159}
160
161
162void
163_pq_insert_head(pq_queue_t *pq, pthread_t pthread)
164{
165 int prio;

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

172 PQ_ASSERT_NOT_QUEUED(pthread,
173 "_pq_insert_head: Already in priority queue");
174
175 prio = pthread->active_priority;
176 TAILQ_INSERT_HEAD(&pq->pq_lists[prio].pl_head, pthread, pqe);
177 if (pq->pq_lists[prio].pl_queued == 0)
178 /* Insert the list into the priority queue: */
179 pq_insert_prio_list(pq, prio);
159 PQ_CLEAR_ACTIVE(pq);
160}
161
162
163void
164_pq_insert_head(pq_queue_t *pq, pthread_t pthread)
165{
166 int prio;

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

173 PQ_ASSERT_NOT_QUEUED(pthread,
174 "_pq_insert_head: Already in priority queue");
175
176 prio = pthread->active_priority;
177 TAILQ_INSERT_HEAD(&pq->pq_lists[prio].pl_head, pthread, pqe);
178 if (pq->pq_lists[prio].pl_queued == 0)
179 /* Insert the list into the priority queue: */
180 pq_insert_prio_list(pq, prio);
180
181 pq->pq_threads++;
181 /* Mark this thread as being in the priority queue. */
182 pthread->flags |= THR_FLAGS_IN_RUNQ;
183
184 PQ_CLEAR_ACTIVE(pq);
185}
186
187
188void

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

198 PQ_ASSERT_NOT_QUEUED(pthread,
199 "_pq_insert_tail: Already in priority queue");
200
201 prio = pthread->active_priority;
202 TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe);
203 if (pq->pq_lists[prio].pl_queued == 0)
204 /* Insert the list into the priority queue: */
205 pq_insert_prio_list(pq, prio);
182 /* Mark this thread as being in the priority queue. */
183 pthread->flags |= THR_FLAGS_IN_RUNQ;
184
185 PQ_CLEAR_ACTIVE(pq);
186}
187
188
189void

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

199 PQ_ASSERT_NOT_QUEUED(pthread,
200 "_pq_insert_tail: Already in priority queue");
201
202 prio = pthread->active_priority;
203 TAILQ_INSERT_TAIL(&pq->pq_lists[prio].pl_head, pthread, pqe);
204 if (pq->pq_lists[prio].pl_queued == 0)
205 /* Insert the list into the priority queue: */
206 pq_insert_prio_list(pq, prio);
206
207 pq->pq_threads++;
207 /* Mark this thread as being in the priority queue. */
208 pthread->flags |= THR_FLAGS_IN_RUNQ;
209
210 PQ_CLEAR_ACTIVE(pq);
211}
212
213
214pthread_t

--- 58 unchanged lines hidden ---
208 /* Mark this thread as being in the priority queue. */
209 pthread->flags |= THR_FLAGS_IN_RUNQ;
210
211 PQ_CLEAR_ACTIVE(pq);
212}
213
214
215pthread_t

--- 58 unchanged lines hidden ---