api.c poolpriority changes
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
diff --git a/API-README b/API-README
index 6ea5a53..6c43929 100644
--- a/API-README
+++ b/API-README
@@ -321,7 +321,14 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
-API V1.14
+API V1.15
+
+Added API commands:
+ 'poolpriority'
+
+----------
+
+API V1.14 (cgminer v2.5.0)
Modified API commands:
'stats' - more icarus timing stats added
diff --git a/api.c b/api.c
index bfa3fca..b9f0f53 100644
--- a/api.c
+++ b/api.c
@@ -166,7 +166,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.14";
+static const char *APIVERSION = "1.15";
static const char *DEAD = "Dead";
static const char *SICK = "Sick";
static const char *NOSTART = "NoStart";
@@ -339,7 +339,6 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_ACCDENY 45
#define MSG_ACCOK 46
#define MSG_ENAPOOL 47
-#define MSG_POOLPRIO 73
#define MSG_DISPOOL 48
#define MSG_ALRENAP 49
#define MSG_ALRDISP 50
@@ -373,6 +372,8 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_MINESTATS 70
#define MSG_MISCHK 71
#define MSG_CHECK 72
+#define MSG_POOLPRIO 73
+#define MSG_DUPPID 74
enum code_severity {
SEVERITY_ERR,
@@ -386,6 +387,7 @@ enum code_parameters {
PARAM_GPU,
PARAM_PGA,
PARAM_CPU,
+ PARAM_PID,
PARAM_GPUMAX,
PARAM_PGAMAX,
PARAM_CPUMAX,
@@ -503,6 +505,7 @@ struct CODES {
{ SEVERITY_SUCC, MSG_ACCOK, PARAM_NONE, "Privileged access OK" },
{ SEVERITY_SUCC, MSG_ENAPOOL, PARAM_POOL, "Enabling pool %d:'%s'" },
{ SEVERITY_SUCC, MSG_POOLPRIO,PARAM_NONE, "Changed pool priorities" },
+ { SEVERITY_ERR, MSG_DUPPID, PARAM_PID, "Duplicate pool specified %d" },
{ SEVERITY_SUCC, MSG_DISPOOL, PARAM_POOL, "Disabling pool %d:'%s'" },
{ SEVERITY_INFO, MSG_ALRENAP, PARAM_POOL, "Pool %d:'%s' already enabled" },
{ SEVERITY_INFO, MSG_ALRDISP, PARAM_POOL, "Pool %d:'%s' already disabled" },
@@ -1064,6 +1067,7 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
case PARAM_GPU:
case PARAM_PGA:
case PARAM_CPU:
+ case PARAM_PID:
sprintf(buf, codes[i].description, paramid);
break;
case PARAM_POOL:
@@ -2132,46 +2136,62 @@ static void enablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __
static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
{
- SETUP_STRTOK_TS;
- int total_pools_ = total_pools; // Keep a local copy, to be more threadsafe
- char *a;
- int i, prio = 0, e = -1;
+ char *ptr, *next;
+ int i, pr, prio = 0;
- if (total_pools_ == 0) {
+ // TODO: all cgminer code needs a mutex added everywhere for change
+ // access to total_pools and also parts of the pools[] array,
+ // just copying total_pools here wont solve that
+
+ if (total_pools == 0) {
strcpy(io_buffer, message(MSG_NOPOOL, 0, NULL, isjson));
return;
}
- bool pools_changed[total_pools_];
- for (i = 0; i < total_pools_; ++i)
+ if (param == NULL || *param == '\0') {
+ strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson));
+ return;
+ }
+
+ bool pools_changed[total_pools];
+ for (i = 0; i < total_pools; ++i)
pools_changed[i] = false;
- a = strtok_ts(param, ",");
- do {
- i = strtol(a, &a, 10);
- if (unlikely(*a > 0x20 || i < 0 || i >= total_pools)) {
- e = (*a > 0x20) ? -2 : i;
- continue;
+ next = param;
+ while (next && *next) {
+ ptr = next;
+ next = strchr(ptr, ',');
+ if (next)
+ *(next++) = '\0';
+
+ i = atoi(ptr);
+ if (i < 0 || i >= total_pools) {
+ strcpy(io_buffer, message(MSG_INVPID, i, NULL, isjson));
+ return;
}
+
+ if (pools_changed[i]) {
+ strcpy(io_buffer, message(MSG_DUPPID, i, NULL, isjson));
+ return;
+ }
+
pools[i]->prio = prio++;
pools_changed[i] = true;
- } while ( (a = strtok_ts(NULL, ",")) );
+ }
- for (i = 0; i < total_pools_; ++i)
- if (!pools_changed[i])
- pools[i]->prio = prio++;
+ // In priority order, cycle through the unchanged pools and append them
+ for (pr = 0; pr < total_pools; pr++)
+ for (i = 0; i < total_pools; i++) {
+ if (!pools_changed[i] && pools[i]->prio == pr) {
+ pools[i]->prio = prio++;
+ pools_changed[i] = true;
+ break;
+ }
+ }
if (current_pool()->prio)
switch_pools(NULL);
- if (e != -1) {
- if (e == -2)
- strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson));
- else
- strcpy(io_buffer, message(MSG_INVPID, e, NULL, isjson));
- return;
- }
-
strcpy(io_buffer, message(MSG_POOLPRIO, 0, NULL, isjson));
}
diff --git a/compat.h b/compat.h
index 19a14f0..c6e38d8 100644
--- a/compat.h
+++ b/compat.h
@@ -9,10 +9,6 @@
#include <windows.h>
-// NOTE: Windows strtok uses a thread-local static buffer, so this is safe
-#define SETUP_STRTOK_TS /*nothing needed*/
-#define strtok_ts strtok
-
#include "miner.h" // for timersub
static inline int nanosleep(const struct timespec *req, struct timespec *rem)
@@ -76,13 +72,8 @@ typedef long suseconds_t;
#endif
#define PTH(thr) ((thr)->pth.p)
-#else /* ! WIN32 */
-
+#else
#define PTH(thr) ((thr)->pth)
-
-#define SETUP_STRTOK_TS char*_strtok_ts_saveptr
-#define strtok_ts(str, delim) strtok_r(str, delim, &_strtok_ts_saveptr)
-
#endif /* WIN32 */
#endif /* __COMPAT_H__ */