Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 4eba4ee

Browse files
fix: make get hardware info function thread-safe (#1956)
Co-authored-by: vansangpfiev <[email protected]>
1 parent 36222f1 commit 4eba4ee

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

engine/services/hardware_service.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool TryConnectToServer(const std::string& host, int port) {
3535

3636
HardwareInfo HardwareService::GetHardwareInfo() {
3737
// append active state
38+
std::lock_guard<std::mutex> l(mtx_);
3839
auto gpus = cortex::hw::GetGPUInfo();
3940
auto res = db_service_->LoadHardwareList();
4041
if (res.has_value()) {

engine/services/hardware_service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdint.h>
33
#include <string>
44
#include <vector>
5+
#include <mutex>
56

67
#include "common/hardware_config.h"
78
#include "database_service.h"
@@ -39,4 +40,5 @@ class HardwareService {
3940
private:
4041
std::shared_ptr<DatabaseService> db_service_ = nullptr;
4142
std::optional<cortex::hw::ActivateHardwareConfig> ahc_;
43+
std::mutex mtx_;
4244
};

0 commit comments

Comments
 (0)