From f5efc5641e25c458b4ce1167095fd7eb659a8a6d Mon Sep 17 00:00:00 2001 From: dschmenk Date: Tue, 28 Feb 2023 12:57:49 -0800 Subject: [PATCH] Add count of active fibers --- src/inc/fiber.plh | 1 + src/libsrc/fiber.pla | 4 ++++ src/samplesrc/fibertest.pla | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/inc/fiber.plh b/src/inc/fiber.plh index b19dea3..efb8601 100644 --- a/src/inc/fiber.plh +++ b/src/inc/fiber.plh @@ -1,4 +1,5 @@ import fiber predef fbrInit(numPool), fbrStop(fid)#0, fbrExit#0, fbrStart(defaddr, param) predef fbrYield#0, fbrHalt#0, fbrResume(fid)#0 + byte fbrCount end diff --git a/src/libsrc/fiber.pla b/src/libsrc/fiber.pla index d098d9a..64915da 100644 --- a/src/libsrc/fiber.pla +++ b/src/libsrc/fiber.pla @@ -19,6 +19,7 @@ byte fbrNext[MAX_FIBERS] word fbrVMState[MAX_FIBERS] word fbrPool byte fbrRunning = 0 +export byte fbrCount = 0 // // Zero Page VM state and 6502 stack // @@ -136,6 +137,7 @@ export def fbrInit(numPool) else return -1 fin + fbrCount = 1 return 0 end // @@ -151,6 +153,7 @@ export def fbrStop(fid)#0 // // Remove fiber from RUN list and tag as free // + fbrCount-- fbrState[fid] = FIBER_FREE i = 0 while fbrNext[i] <> fid @@ -212,6 +215,7 @@ export def fbrStart(defaddr, param) // // Return fiber ID (index) // + fbrCount++ return i fin next diff --git a/src/samplesrc/fibertest.pla b/src/samplesrc/fibertest.pla index 3968e6d..529505b 100644 --- a/src/samplesrc/fibertest.pla +++ b/src/samplesrc/fibertest.pla @@ -19,6 +19,5 @@ fbrInit(4) fbrStart(@fbrTest, 3) fbrStart(@fbrTest, 2) fbrStart(@fbrTest, 1) -fbrYield; fbrYield; fbrYield; fbrYield - +while fbrCount > 1; fbrYield; loop done