forked from DeckerSU/yiimp-stratum-equihash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
job_core.cpp
132 lines (98 loc) · 2.5 KB
/
job_core.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "stratum.h"
void job_sort()
{
for(CLI li = g_list_job.first; li && li->next; li = li->next)
{
YAAMP_JOB *job1 = (YAAMP_JOB *)li->data;
YAAMP_JOB *job2 = (YAAMP_JOB *)li->next->data;
if(job1->profit < job2->profit)
{
g_list_job.Swap(li, li->next);
job_sort();
return;
}
}
}
bool job_has_free_client()
{
g_list_client.Enter();
for(CLI li = g_list_client.first; li; li = li->next)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
if(client->deleted) continue;
if(!client->jobid_next)
{
g_list_client.Leave();
return true;
}
}
g_list_client.Leave();
return false;
}
void job_reset_clients(YAAMP_JOB *job)
{
g_list_client.Enter();
for(CLI li = g_list_client.first; li; li = li->next)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
if(client->deleted) continue;
if(!job || job->id == client->jobid_next)
client->jobid_next = 0;
}
g_list_client.Leave();
}
void job_relock_clients(int jobid_old, int jobid_new)
{
if(!jobid_old || !jobid_new) return;
g_list_client.Enter();
for(CLI li = g_list_client.first; li; li = li->next)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
if(client->jobid_locked != jobid_old) continue;
// debuglog("relock job %x to %x\n", client->jobid_locked, jobid_new);
client->jobid_locked = jobid_new;
}
g_list_client.Leave();
}
void job_assign_locked_clients(YAAMP_JOB *job)
{
if(!job) return;
job->speed = 0;
job->count = 0;
g_list_client.Enter();
for(CLI li = g_list_client.first; li; li = li->next)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
if(client->jobid_locked != job->id) continue;
// debuglog("assign job %x %x\n", client->jobid_locked, job->id);
client->jobid_next = job->id;
job->remote_subids[client->extranonce1_id] = true;
job->speed += client->speed;
job->count++;
}
g_list_client.Leave();
}
void job_unlock_clients(YAAMP_JOB *job)
{
g_list_client.Enter();
for(CLI li = g_list_client.first; li; li = li->next)
{
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
if(client->deleted) continue;
if(!client->jobid_locked) continue;
if(client->jobid_locked == client->jobid_next) continue;
if(job && client->jobid_locked != job->id) continue;
// debuglog("unlock job %x %x\n", client->jobid_locked, job->id);
client->jobid_locked = 0;
}
g_list_client.Leave();
}
bool job_can_mine(YAAMP_JOB *job)
{
if(job->deleted) return false;
if(job->remote)
return remote_can_mine(job->remote);
else if(job->coind)
return coind_can_mine(job->coind);
return false;
}