fix: cross thread communictions of timeout variable

This commit is contained in:
iceman1001 2019-05-03 17:53:32 +02:00
parent 423d179da5
commit ed1950a0f5

View file

@ -250,7 +250,7 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
// packet->ng ? "NG" : "OLD", packet->magic, packet->length, packet->status, packet->crc, packet->cmd); // packet->ng ? "NG" : "OLD", packet->magic, packet->length, packet->status, packet->crc, packet->cmd);
// we got a packet, reset WaitForResponseTimeout timeout // we got a packet, reset WaitForResponseTimeout timeout
timeout_start_time = msclock(); __atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST);
switch (packet->cmd) { switch (packet->cmd) {
// First check if we are handling a debug message // First check if we are handling a debug message
@ -674,29 +674,29 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
if (ms_timeout != (size_t) -1) if (ms_timeout != (size_t) -1)
ms_timeout += communication_delay(); ms_timeout += communication_delay();
timeout_start_time = msclock(); __atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST);
uint64_t tmp_clk;
// Wait until the command is received // Wait until the command is received
while (true) { while (true) {
while (getReply(response)) { while (getReply(response)) {
if (cmd == CMD_UNKNOWN || response->cmd == cmd) { if (cmd == CMD_UNKNOWN || response->cmd == cmd) {
// PrintAndLogEx(INFO, "Waited %i ms", msclock() - timeout_start_time);
return true; return true;
} }
} }
if (msclock() - timeout_start_time > ms_timeout) tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
if (msclock() - tmp_clk > ms_timeout)
break; break;
if (msclock() - timeout_start_time > 3000 && show_warning) { if (msclock() - tmp_clk > 3000 && show_warning) {
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded) // 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
PrintAndLogEx(INFO, "Waiting for a response from the proxmark3..."); PrintAndLogEx(INFO, "Waiting for a response from the proxmark3...");
PrintAndLogEx(INFO, "You can cancel this operation by pressing the pm3 button"); PrintAndLogEx(INFO, "You can cancel this operation by pressing the pm3 button");
show_warning = false; show_warning = false;
} }
} }
// PrintAndLogEx(INFO, "Wait timeout after %i ms", msclock() - timeout_start_time);
return false; return false;
} }
@ -758,7 +758,8 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) { static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketResponseNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) {
uint32_t bytes_completed = 0; uint32_t bytes_completed = 0;
timeout_start_time = msclock(); __atomic_store_n(&timeout_start_time, msclock(), __ATOMIC_SEQ_CST);
uint64_t tmp_clk;
// Add delay depending on the communication channel & speed // Add delay depending on the communication channel & speed
if (ms_timeout != (size_t) -1) if (ms_timeout != (size_t) -1)
@ -795,12 +796,13 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, PacketRes
} }
} }
if (msclock() - timeout_start_time > ms_timeout) { tmp_clk = __atomic_load_n(&timeout_start_time, __ATOMIC_SEQ_CST);
if (msclock() - tmp_clk > ms_timeout) {
PrintAndLogEx(FAILED, "Timed out while trying to download data from device"); PrintAndLogEx(FAILED, "Timed out while trying to download data from device");
break; break;
} }
if (msclock() - timeout_start_time > 3000 && show_warning) { if (msclock() - tmp_clk > 3000 && show_warning) {
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded) // 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
PrintAndLogEx(NORMAL, "Waiting for a response from the Proxmark3..."); PrintAndLogEx(NORMAL, "Waiting for a response from the Proxmark3...");
PrintAndLogEx(NORMAL, "You can cancel this operation by pressing the pm3 button"); PrintAndLogEx(NORMAL, "You can cancel this operation by pressing the pm3 button");