3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-12-05 11:36:49 +00:00

Make coverage data thread-safe

This commit is contained in:
Robert O'Callahan 2025-11-25 02:19:51 +00:00
parent 10fd97821e
commit 7f9de6e48f
2 changed files with 7 additions and 5 deletions

View file

@ -720,7 +720,7 @@ dict<std::string, std::pair<std::string, int>> get_coverage_data()
if (coverage_data.count(p->id))
log_warning("found duplicate coverage id \"%s\".\n", p->id);
coverage_data[p->id].first = stringf("%s:%d:%s", p->file, p->line, p->func);
coverage_data[p->id].second += p->counter;
coverage_data[p->id].second += p->counter.load(std::memory_order_relaxed);
}
for (auto &it : coverage_data)

View file

@ -24,6 +24,7 @@
#include <time.h>
#include <atomic>
#include <regex>
#define YS_REGEX_COMPILE(param) std::regex(param, \
std::regex_constants::nosubs | \
@ -298,15 +299,16 @@ void log_abort_internal(const char *file, int line);
#define cover(_id) do { \
static CoverData __d __attribute__((section("yosys_cover_list"), aligned(1), used)) = { __FILE__, __FUNCTION__, _id, __LINE__, 0 }; \
__d.counter++; \
__d.counter.fetch_add(1, std::memory_order_relaxed); \
} while (0)
struct CoverData {
const char *file, *func, *id;
int line, counter;
} YS_ATTRIBUTE(packed);
int line;
std::atomic<int> counter;
};
// this two symbols are created by the linker for the "yosys_cover_list" ELF section
// this two symbols are created by the linker __start_yosys_cover_listfor the "yosys_cover_list" ELF section
extern "C" struct CoverData __start_yosys_cover_list[];
extern "C" struct CoverData __stop_yosys_cover_list[];