Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added callable class that may be added to the pool instead of a funct…

…ion.

This solves the dynamic binding problem that normally wouldn't be possible.
  • Loading branch information...
commit 4b005c487e20ba137ea3fcd9098a682cde75100b 1 parent 9666450
@kiuma authored
Showing with 17 additions and 3 deletions.
  1. +4 −1 src/package.lisp
  2. +13 −2 src/thread-pool.lisp
View
5 src/package.lisp
@@ -35,5 +35,8 @@
#:start-pool
#:stop-pool
#:add-to-pool
- #:pool-size)
+ #:pool-size
+ #:callable
+ #:callable-call
+ #:callable-handler-func)
(:documentation "A simple thread pool system"))
View
15 src/thread-pool.lisp
@@ -29,6 +29,14 @@
(in-package :thread-pool)
+(defgeneric callable-call (call))
+
+(defclass callable ()
+ ((handler-func :accessor callable-handler-func :initarg :handler-func)))
+
+(defmethod callable-call ((callable callable))
+ (funcall (callable-handler-func callable)))
+
(defgeneric start-pool (thread-pool)
(:documentation "Starts serving jobs"))
(defgeneric stop-pool (thread-pool)
@@ -117,8 +125,11 @@
(bordeaux-threads:with-lock-held (pool-lock)
(setf (nth ix threads) nil
func (arnesi:dequeue jobs)))
- (when func
- (funcall func))
+ (when func
+ (format t "Calling func: ~a~%" func)
+ (if (typep func 'callable)
+ (callable-call func)
+ (funcall func)))
(bordeaux-threads:with-lock-held (pool-lock)
(setf (nth ix threads) th))
(bordeaux-threads:condition-notify pool-condition)))))
Please sign in to comment.
Something went wrong with that request. Please try again.