-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpriority-cqueue.lisp
104 lines (81 loc) · 2.94 KB
/
priority-cqueue.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;;;; **************************************************************************
;;;; **************************************************************************
;;;; *
;;;; * A thread safe fibonacci queue implementation
;;;; * by Eric O'Connor
;;;; *
;;;; **************************************************************************
;;;; **************************************************************************
(in-package :queues)
(eval-when (:compile-toplevel :load-toplevel :execute)
(use-package :bordeaux-threads))
;;;
;;; Class
;;;
(defclass priority-cqueue (priority-queue)
((lock :initform (make-recursive-lock "queue-lock")
:accessor lock-of)))
;;;
;;; Methods
;;;
(defmethod make-queue ((type (eql :priority-cqueue)) &key compare copy)
(make-queue :priority-queue
:compare compare
:copy copy
:class 'priority-cqueue))
(defmethod qpush ((q priority-cqueue) el)
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod qpop ((q priority-cqueue) &optional empty)
(declare (ignore empty))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod qtop ((q priority-cqueue) &optional empty)
(declare (ignore empty))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod qsize ((q priority-cqueue))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod qclear ((q priority-cqueue))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod map-queue (fn (q priority-cqueue))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod print-queue ((q priority-cqueue)
&optional (stream *standard-output*))
(declare (ignore stream))
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
;;;
;;; Priority Queue-only methods
;;;
(defmethod queue-merge ((q1 priority-cqueue)
(q2 priority-cqueue))
(with-recursive-lock-held ((lock-of q1))
(with-recursive-lock-held ((lock-of q2))
(call-next-method))))
(defmethod queue-merge-safe ((q1 priority-cqueue)
(q2 priority-cqueue))
(with-recursive-lock-held ((lock-of q1))
(with-recursive-lock-held ((lock-of q2))
(call-next-method))))
(defmethod queue-find ((q priority-cqueue) predicate-or-key)
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod queue-change ((q priority-cqueue) node new-value)
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod queue-delete ((q priority-cqueue) node)
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod node-active-p ((q priority-cqueue) node)
(with-recursive-lock-held ((lock-of q))
(call-next-method)))
(defmethod queue-comparison ((q priority-cqueue))
"No need for synchronization, since the comparison is constant"
(call-next-method))
;;; ==================================================================
;;; EOF
;;; ==================================================================