3 * Copyright 2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gcell/gc_jd_queue.h>
23 #include <gcell/memory_barrier.h>
24 #include <mutex_init.h>
25 #include <mutex_lock.h>
26 #include <mutex_unlock.h>
29 gc_jd_queue_init(gc_jd_queue_t *q)
31 _mutex_init(ptr_to_ea(&q->mutex));
38 gc_jd_queue_enqueue(gc_jd_queue_t *q, gc_job_desc_t *item)
41 _mutex_lock(ptr_to_ea(&q->mutex));
42 smp_rmb(); // import barrier
44 if (q->tail == 0){ // currently empty
45 q->tail = q->head = jdp_to_ea(item);
47 else { // not empty, append
48 ea_to_jdp(q->tail)->sys.next = jdp_to_ea(item);
49 q->tail = jdp_to_ea(item);
52 smp_wmb(); // orders stores above before clearing of mutex
53 _mutex_unlock(ptr_to_ea(&q->mutex));
57 gc_jd_queue_dequeue(gc_jd_queue_t *q)
59 _mutex_lock(ptr_to_ea(&q->mutex));
60 smp_rmb(); // import barrier
62 gc_eaddr_t item_ea = q->head;
63 if (item_ea == 0){ // empty
64 _mutex_unlock(ptr_to_ea(&q->mutex));
68 q->head = ea_to_jdp(item_ea)->sys.next;
69 if (q->head == 0) // now emtpy
72 gc_job_desc_t *item = ea_to_jdp(item_ea);
75 smp_wmb(); // orders stores above before clearing of mutex
76 _mutex_unlock(ptr_to_ea(&q->mutex));