Diff

Differences From Artifact [15325924cd]:

To Artifact [ed9cc0294e]:


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33






























34

35

36
37
38
39
40
41
42
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+







		db eval {INSERT INTO blocks (orderID, blockJSON) VALUES ($orderID, $block);}
	}
}

set ::initDB true
uplevel #0 $threadInit

set ::numberOfCPUs 2
set iterationCount 1

db eval {
	PRAGMA journal_mode = MEMORY;
	CREATE TABLE blocks (orderID INTEGER PRIMARY KEY, blockJSON TEXT NOT NULL);
}

## -- PROCESSES
proc numberOfThreads {} {
	# Windows puts it in an environment variable
	if {[info exists ::env(NUMBER_OF_PROCESSORS)]} {
		return $::env(NUMBER_OF_PROCESSORS)
	    }

	# Check for sysctl (OSX, BSD)
	set sysctl [auto_execok "sysctl"]
	if {[llength $sysctl]} {
		if {![catch {exec {*}$sysctl -n "hw.ncpu"} cores]} {
			if {[string is integer -strict $cores]} {
				return $cores
			}
		}
	}

	# Assume Linux, which has /proc/cpuinfo, but be careful
	if {![catch {open "/proc/cpuinfo"} f]} {
		set cores [regexp -all -line {^processor\s} [read $f]]
		close $f
		if {$cores > 0} {
			return $cores
		}
	}

	# No idea what the actual number of cores is; exhausted all our options
	# Fall back to returning 1; there must be at least that because we're running on it!
	return 1
}

set ::jobIDs [list]
set ::numberOfThreads [numberOfThreads]
set ::threadPool [::tpool::create -minworkers $::numberOfCPUs -maxworkers $::numberOfCPUs -initcmd $::threadInit]
set ::threadPool [::tpool::create -minworkers $numberOfThreads -maxworkers $numberOfThreads -initcmd $::threadInit]
set ::processBlock_orderID -1
proc processBlock {args} {
	updateStatus

	incr ::processBlock_orderID
	
	set jobID [::tpool::post $::threadPool [list processBlockWorker ${::processBlock_orderID} {*}$args]]