Skip to content

Commit

Permalink
fix: make get hardware info function thread-safe (#1956)
Browse files Browse the repository at this point in the history
Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Feb 11, 2025
1 parent 36222f1 commit 4eba4ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions engine/services/hardware_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bool TryConnectToServer(const std::string& host, int port) {

HardwareInfo HardwareService::GetHardwareInfo() {
// append active state
std::lock_guard<std::mutex> l(mtx_);
auto gpus = cortex::hw::GetGPUInfo();
auto res = db_service_->LoadHardwareList();
if (res.has_value()) {
Expand Down
2 changes: 2 additions & 0 deletions engine/services/hardware_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdint.h>
#include <string>
#include <vector>
#include <mutex>

#include "common/hardware_config.h"
#include "database_service.h"
Expand Down Expand Up @@ -39,4 +40,5 @@ class HardwareService {
private:
std::shared_ptr<DatabaseService> db_service_ = nullptr;
std::optional<cortex::hw::ActivateHardwareConfig> ahc_;
std::mutex mtx_;
};

0 comments on commit 4eba4ee

Please sign in to comment.