浏览代码

Added some query methods.

Brucey 3 年之前
父节点
当前提交
58a91cf5fc
共有 2 个文件被更改,包括 21 次插入1 次删除
  1. 1 1
      threadpool.mod/examples/example_01.bmx
  2. 20 0
      threadpool.mod/threadpool.bmx

+ 1 - 1
threadpool.mod/examples/example_01.bmx

@@ -2,7 +2,7 @@ SuperStrict
 
 Framework BRL.Standardio
 Import BRL.ThreadPool
-Import BRL.Random
+Import BRL.RandomDefault
 
 
 Print "Thread pool with 4 threads"

+ 20 - 0
threadpool.mod/threadpool.bmx

@@ -264,6 +264,19 @@ Type TThreadPoolExecutor Extends TExecutor
 
 	End Method
 	
+	Rem
+	bbdoc: Returns the approximate number of threads that are actively executing tasks.
+	end rem
+	Method getActiveCount:Int()
+		countLock.Lock()
+		Local count:Int = threadsWorking
+		countLock.unlock()
+		return count
+	End Method
+	
+	Method IsQueueEmpty:Int()
+		return jobQueue.IsEmpty()
+	end method
 End Type
 
 Private
@@ -360,6 +373,13 @@ Type TJobQueue
 		Return job
 	End Method
 
+	Method IsEmpty:Int()
+		Lock()
+		Local empty:Int = jobs.IsEmpty()
+		UnLock()
+		return empty
+	End Method
+
 	Method Lock()
 		mutex.Lock()
 	End Method