From 3b1750c6604b053155eda5eac437046e6f514741 Mon Sep 17 00:00:00 2001 From: Taichiro Suzuki Date: Sun, 20 May 2018 14:38:49 +0900 Subject: [PATCH] threads => process (#186) --- src/cli/modules/global_optionparser.cr | 24 ++++++++++++------------ src/cli/sushi/config.cr | 4 ++-- src/cli/sushim.cr | 4 ++-- src/core/miner/miner.cr | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/cli/modules/global_optionparser.cr b/src/cli/modules/global_optionparser.cr index 2ec965c2..93141e95 100644 --- a/src/cli/modules/global_optionparser.cr +++ b/src/cli/modules/global_optionparser.cr @@ -38,7 +38,7 @@ module ::Sushi::Interface @header : Bool = false - @threads : Int32 = 1 + @processes : Int32 = 1 @encrypted : Bool = false @@ -51,7 +51,7 @@ module ::Sushi::Interface @node_id : String? - module Options + enum Options # common options CONNECT_NODE = 0 WALLET_PATH = 1 @@ -77,7 +77,7 @@ module ::Sushi::Interface # for blockchain HEADER = 19 # for miners - THREADS = 20 + PROCESSES = 20 # for wallet ENCRYPTED = 21 # for scars @@ -91,7 +91,7 @@ module ::Sushi::Interface NODE_ID = 26 end - def create_option_parser(actives : Array(Int32)) : OptionParser + def create_option_parser(actives : Array(Options)) : OptionParser OptionParser.new do |parser| parser.on("-n NODE", "--node=NODE", "a url of the connect node") { |connect_node| @connect_node = connect_node @@ -192,9 +192,9 @@ module ::Sushi::Interface @header = true } if is_active?(actives, Options::HEADER) - parser.on("--threads=THREADS", "# of the work threads (default is 1)") { |threads| - @threads = threads.to_i - } if is_active?(actives, Options::THREADS) + parser.on("--process=PROCESSES", "# of the work processes (default is 1)") { |processes| + @processes = processes.to_i + } if is_active?(actives, Options::PROCESSES) parser.on("-e", "--encrypted", "set this flag when creating a wallet to create an encrypted wallet") { @encrypted = true @@ -224,7 +224,7 @@ module ::Sushi::Interface end end - def is_active?(actives : Array(Int32), option : Int32) : Bool + def is_active?(actives : Array(Options), option : Options) : Bool actives.includes?(option) end @@ -312,10 +312,10 @@ module ::Sushi::Interface @header end - def __threads : Int32 - return @threads if @threads != 1 - return cm.get_i32("threads", @config_name).not_nil! if cm.get_i32("threads", @config_name) - @threads + def __processes : Int32 + return @processes if @processes != 1 + return cm.get_i32("processes", @config_name).not_nil! if cm.get_i32("processes", @config_name) + @processes end def __encrypted : Bool diff --git a/src/cli/sushi/config.cr b/src/cli/sushi/config.cr index ea9e61c2..b018eaac 100644 --- a/src/cli/sushi/config.cr +++ b/src/cli/sushi/config.cr @@ -65,7 +65,7 @@ module ::Sushi::Interface::Sushi # Options::BLOCK_INDEX, # Options::TRANSACTION_ID, # Options::HEADER, - Options::THREADS, + Options::PROCESSES, Options::ENCRYPTED, Options::CONFIG_NAME, ]) @@ -105,7 +105,7 @@ module ::Sushi::Interface::Sushi cm.set("bind_port", __bind_port) cm.set("public_url", __public_url) cm.set("database_path", __database_path) - cm.set("threads", __threads) + cm.set("processes", __processes) cm.set("encrypted", __encrypted) cm.set("wallet_password", __wallet_password) cm.set("address", __address) diff --git a/src/cli/sushim.cr b/src/cli/sushim.cr index 0ea28d09..8947b223 100644 --- a/src/cli/sushim.cr +++ b/src/cli/sushim.cr @@ -24,7 +24,7 @@ module ::Sushi::Interface::SushiM Options::WALLET_PATH, Options::WALLET_PASSWORD, Options::IS_TESTNET, - Options::THREADS, + Options::PROCESSES, Options::CONFIG_NAME, ]) end @@ -44,7 +44,7 @@ module ::Sushi::Interface::SushiM raise "wallet type mismatch" if __is_testnet != wallet_is_testnet - miner = Core::Miner.new(__is_testnet, host, port, wallet, __threads, use_ssl) + miner = Core::Miner.new(__is_testnet, host, port, wallet, __processes, use_ssl) miner.run end diff --git a/src/core/miner/miner.cr b/src/core/miner/miner.cr index 90f8027e..3703f298 100644 --- a/src/core/miner/miner.cr +++ b/src/core/miner/miner.cr @@ -17,10 +17,10 @@ module ::Sushi::Core @workers : Array(Tokoroten::Worker) = [] of Tokoroten::Worker - def initialize(@is_testnet : Bool, @host : String, @port : Int32, @wallet : Wallet, @num_threads : Int32, @use_ssl : Bool) + def initialize(@is_testnet : Bool, @host : String, @port : Int32, @wallet : Wallet, @num_processes : Int32, @use_ssl : Bool) welcome - info "launched #{@num_threads} processes..." + info "launched #{@num_processes} processes..." end def run @@ -116,7 +116,7 @@ module ::Sushi::Core end def start_workers(difficulty, latest_index, latest_hash) - @workers = MinerWorker.create(@num_threads) + @workers = MinerWorker.create(@num_processes) @workers.each do |w| spawn do loop do