From 111f317d2029abb85218e352a1e165145583c090 Mon Sep 17 00:00:00 2001 From: Avril Date: Sat, 6 Apr 2019 18:41:56 +0100 Subject: [PATCH] remove unneeded dependancy --- cl-box.lisp | 7 +++---- cl-channel.asd | 3 +-- cl-channel.lisp | 28 +++++++++++++++++----------- cl-dispatcher.lisp | 10 ++++------ 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/cl-box.lisp b/cl-box.lisp index 2c90763..474fb0b 100644 --- a/cl-box.lisp +++ b/cl-box.lisp @@ -2,8 +2,6 @@ (in-package :cl-box) -(flan-utils:enable-all-readers) - (defstruct %box value lock) @@ -11,7 +9,8 @@ (defmacro %atomic (box &body re) `(bt:with-lock-held ((%box-lock ,box)) ,@re)) -[ +(mapc 'export (list + (defun make-box (&optional value) (let ((b (make-%box))) (setf (%box-value b) value) @@ -62,7 +61,7 @@ ,@things) (<-! ,name))))) -] +)) (defun test () (let ((box (make))) diff --git a/cl-channel.asd b/cl-channel.asd index 8d1740b..ab12114 100644 --- a/cl-channel.asd +++ b/cl-channel.asd @@ -6,8 +6,7 @@ :license "None" :version "0.0.1" :serial t - :depends-on ( :flan-utils - :bt-semaphore ) + :depends-on ( :bt-semaphore ) :components ((:file "package") (:file "cl-channel") (:file "cl-box") diff --git a/cl-channel.lisp b/cl-channel.lisp index 1ae8278..6a08d70 100644 --- a/cl-channel.lisp +++ b/cl-channel.lisp @@ -2,13 +2,13 @@ (in-package :cl-channel) -(flan-utils:enable-all-readers) (defstruct %queue internal mutex) -[ + +(mapc 'export (list (defun make-queue (&optional (from nil)) (let ((q (make-%queue))) (setf (%queue-internal q) from) @@ -31,7 +31,7 @@ (defun queue-clear (q) (bt:with-lock-held ((%queue-mutex q)) (setf (%queue-internal q) nil))) -] +)) (defstruct %channel internal @@ -49,7 +49,8 @@ (defun sigall (sem) (bt-sem:signal-semaphore sem (bt-sem:semaphore-waiters sem))) -[ +(mapc 'export (list + (defun make-channel (&optional (max 0)) (let ((c (make-%channel))) (setf (%channel-internal c) (make-queue)) @@ -71,7 +72,7 @@ (defun <- (chan) (let ((out nil) (rout nil)) - (loop while (and (null out) ¬(closed chan)) do + (loop while (and (null out) (not (closed chan))) do (progn (if (> (poll chan) 0) (%atomic chan @@ -83,15 +84,15 @@ (if (closed chan) (values nil nil) (values rout t)))) (defun -> (chan item) - (loop while (and ¬(closed chan) (> (%channel-max chan) 0) (%atomic chan (>= (queue-poll (%channel-internal chan)) (%channel-max chan)))) + (loop while (and (not (closed chan)) (> (%channel-max chan) 0) (%atomic chan (>= (queue-poll (%channel-internal chan)) (%channel-max chan)))) do (bt-sem:wait-on-semaphore (%channel-rel-send))) (let ((lv (%atomic chan - (if ¬(if (or (%channel-closed chan) (and (> (%channel-max chan) 0) (>= (queue-poll (%channel-internal chan)) (%channel-max chan)))) + (if (not (if (or (%channel-closed chan) (and (> (%channel-max chan) 0) (>= (queue-poll (%channel-internal chan)) (%channel-max chan)))) nil (progn (queue-> (%channel-internal chan) item) (bt-sem:signal-semaphore (%channel-rel-recv chan) 1) - t)) + t))) (if (%channel-closed chan) nil 'reset) t)))) (if (eq lv 'reset) @@ -110,9 +111,10 @@ (defmacro make () `(make-channel)) -] -(defun test () +)) + +#|(defun test () (let ((chan (make-channel))) $(progn (loop while ¬(closed chan) do (let ((val (<- chan))) @@ -122,5 +124,9 @@ (release chan)))) (print "Thread end") (print ".")) + $(loop while ¬(closed chan) do + (progn + (sleep 2) + (-> chan 'teste))) (loop while ¬(closed chan) do (-> chan (write-to-string (read))))) - (print "End")) + (print "End"))|# diff --git a/cl-dispatcher.lisp b/cl-dispatcher.lisp index 837e2f0..5b1c4b3 100644 --- a/cl-dispatcher.lisp +++ b/cl-dispatcher.lisp @@ -2,8 +2,6 @@ (in-package :cl-dispatcher) -(flan-utils:enable-all-readers) - (defstruct %dispatcher hooks lock) @@ -12,7 +10,8 @@ `(bt:with-lock-held ((%dispatcher-lock disp)) ,@thing)) -[ +(mapc 'export (list + (defun make-dispatcher () (let ((d (make-%dispatcher))) (setf (%dispatcher-hooks d ) nil) @@ -33,7 +32,7 @@ (let ((hooks (assoc name (%dispatcher-hooks disp)))) (if (null hooks) nil - (mapc #'(lambda (y) $(funcall y x)) (cdr hooks)))))) + (mapcar #'(lambda (y) (bt:make-thread (funcall y x))) (cdr hooks)))))) (defun sig-serial (disp name &optional (x nil)) (%atomic disp @@ -41,7 +40,7 @@ (if (null hooks) nil (mapc #'(lambda (y) (funcall y x)) (cdr hooks)))))) -] +)) (defun test () (let ((d (make))) @@ -51,4 +50,3 @@ (sig-serial d "test" 'uwu) (print 'signalled))) -