From c84ef8c975bfaa4ee9be2f8172e7ac42294a40b2 Mon Sep 17 00:00:00 2001 From: Christopher Bertels Date: Wed, 20 Jun 2012 05:29:49 +0200 Subject: [PATCH] cleanup old code --- lib/boot.fy | 1 - lib/future.fy | 41 ------------------ lib/thread_pool.fy | 102 --------------------------------------------- 3 files changed, 144 deletions(-) delete mode 100644 lib/thread_pool.fy diff --git a/lib/boot.fy b/lib/boot.fy index bba92251..8d6baf3e 100644 --- a/lib/boot.fy +++ b/lib/boot.fy @@ -36,7 +36,6 @@ require: "set" require: "symbol" require: "stack" require: "proxy" -require: "thread_pool" require: "fiber" require: "future" require: "struct" diff --git a/lib/future.fy b/lib/future.fy index 549a273c..4465245d 100644 --- a/lib/future.fy +++ b/lib/future.fy @@ -185,47 +185,6 @@ class FutureSend { } } -class PooledFuture { - @@thread_pool = nil - @@pool_size = 10 - WaitInterval = 0.1 - - def PooledFuture pool: n { - @@pool_size = match n { - case 0 -> 10 - case _ -> n - } - } - - def PooledFuture join! { - @@thread_pool join - } - - def initialize: @block { - { @@thread_pool = ThreadPool new: @@pool_size } unless: @@thread_pool - @@thread_pool execute: @block - } - - def when_done: block { - PooledFuture new: { - block call: [value] - } - } - - def && block { - when_done: block - } - - def completed? { - @block complete? - } - - def value { - { Thread sleep: WaitInterval } until: { completed? } - @block completed_value - } -} - class FutureCollection { include: Fancy Enumerable diff --git a/lib/thread_pool.fy b/lib/thread_pool.fy deleted file mode 100644 index 14666d56..00000000 --- a/lib/thread_pool.fy +++ /dev/null @@ -1,102 +0,0 @@ -# This ThreadPool class is adapted from the Ruby code at: -# https://github.com/fizx/thread_pool/ - -class ThreadPool { - class Executor { - read_slot: 'active - - def initialize: queue mutex: mutex { - @thread = Thread new: { - loop: { - mutex synchronize() { @tuple = queue shift() } - if: @tuple then: { - args, block = @tuple - @active = true - val = nil - try { - val = block call: args - } catch StandardError => e { - e message println - e backtrace() join: "\n" . println - } - block complete: true - block completed_value: val - } else: { - @active = false - Thread sleep: 0.1 - } - } - } - } - - def close { - @thread exit - } - } - - read_write_slot: 'queue_limit - - # Initialize with number of threads to run - def initialize: @count limit: @queue_limit (0) { - @mutex = Mutex new() - @executors = [] - @queue = [] - @count times: { @executors << (Executor new: @queue mutex: @mutex) } - } - - # Runs the block at some time in the near future - def execute: block with_args: args ([]) { - init_completable: block - - if: (@queue_limit > 0) then: { - { Thread sleep: 0.1 } until: { @queue size < @queue_limit } - } - - @mutex synchronize() { - @queue << [args, block] - } - } - - # Runs the block at some time in the near future, and blocks until complete - def execute_synchronous: block with_args: args ([]) { - execute: block with_args: args - { Thread sleep: 0.1 } until: { block complete? } - block completed_value - } - - # Size of the task queue - def waiting { - @queue size - } - - # Size of the thread pool - def size { - @count - } - - # Kills all threads - def close { - @executors each: @{ close } - } - - # Sleeps and blocks until the task queue is finished executing - def join { - { Thread sleep: 0.1 } until: { { @queue empty? } && { @executors all?: @{ active not } } } - } - - class Completable { - read_write_slot: 'completed_value - def complete: @complete { - } - - def complete? { - @complete not not - } - } - - def init_completable: block { - block extend(Completable) - block complete: false - } - protected: 'init_completable: -} \ No newline at end of file