Skip to content

Commit

Permalink
threads => process (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrand committed May 20, 2018
1 parent 7c03e4c commit 3b1750c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/cli/modules/global_optionparser.cr
Expand Up @@ -38,7 +38,7 @@ module ::Sushi::Interface

@header : Bool = false

@threads : Int32 = 1
@processes : Int32 = 1

@encrypted : Bool = false

Expand All @@ -51,7 +51,7 @@ module ::Sushi::Interface

@node_id : String?

module Options
enum Options
# common options
CONNECT_NODE = 0
WALLET_PATH = 1
Expand All @@ -77,7 +77,7 @@ module ::Sushi::Interface
# for blockchain
HEADER = 19
# for miners
THREADS = 20
PROCESSES = 20
# for wallet
ENCRYPTED = 21
# for scars
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cli/sushi/config.cr
Expand Up @@ -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,
])
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cli/sushim.cr
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/core/miner/miner.cr
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3b1750c

Please sign in to comment.