Skip to content

Commit a303f40

Browse files
committed
Add utility to ensure that a kernel with arbitrary workers exist.
1 parent 9c11f40 commit a303f40

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/kernel/core.lisp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ MAKE-KERNEL and STORE-VALUE restarts. Returns `*kernel*'."
275275
(check-type value kernel)
276276
(setf *kernel* value)))))
277277

278+
(defun ensure-kernel (worker-count &rest other-keys)
279+
"Return `*kernel*', a kernel instance featuring WORKER-COUNT."
280+
;; Notice that when *kernel* exists with 2 workers, then calling:
281+
;; (ensure-kernel 2 :name "a-different-name-from-the-one-set-in-*kernel*")
282+
;; has no effect since the number of workers matches.
283+
(if (and *kernel*
284+
(eq (length (workers *kernel*)) worker-count))
285+
*kernel*
286+
(setf *kernel* (apply #'make-kernel worker-count other-keys))))
287+
278288
(defmacro define-worker-info-reader (name slot &optional (result slot))
279289
`(defun ,name ()
280290
,(format nil "Return the ~a passed to `make-kernel'."

src/kernel/package.lisp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#+lparallel.with-stealing-scheduler #:lparallel.spin-queue)
4343
(:export #:make-kernel
4444
#:check-kernel
45+
#:ensure-kernel
4546
#:end-kernel
4647
#:kernel-worker-count
4748
#:kernel-worker-index

0 commit comments

Comments
 (0)