Permalink
Browse files

cleanup old code

  • Loading branch information...
1 parent 4ee8d83 commit c84ef8c975bfaa4ee9be2f8172e7ac42294a40b2 @bakkdoor committed Jun 20, 2012
Showing with 0 additions and 144 deletions.
  1. +0 −1 lib/boot.fy
  2. +0 −41 lib/future.fy
  3. +0 −102 lib/thread_pool.fy
View
@@ -36,7 +36,6 @@ require: "set"
require: "symbol"
require: "stack"
require: "proxy"
-require: "thread_pool"
require: "fiber"
require: "future"
require: "struct"
View
@@ -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
View
@@ -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:
-}

0 comments on commit c84ef8c

Please sign in to comment.