Skip to content

Commit

Permalink
Keep a single, portable implementation of OS::get_processor_count()
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Oct 5, 2022
1 parent d331b80 commit 6bf02c0
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 19 deletions.
3 changes: 2 additions & 1 deletion core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "core/version_generated.gen.h"

#include <stdarg.h>
#include <thread>

OS *OS::singleton = nullptr;
uint64_t OS::target_ticks = 0;
Expand Down Expand Up @@ -321,7 +322,7 @@ String OS::get_unique_id() const {
}

int OS::get_processor_count() const {
return 1;
return std::thread::hardware_concurrency();
}

String OS::get_processor_name() const {
Expand Down
4 changes: 0 additions & 4 deletions drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,6 @@ bool OS_Unix::set_environment(const String &p_var, const String &p_value) const
return setenv(p_var.utf8().get_data(), p_value.utf8().get_data(), /* overwrite: */ true) == 0;
}

int OS_Unix::get_processor_count() const {
return sysconf(_SC_NPROCESSORS_CONF);
}

String OS_Unix::get_user_data_dir() const {
String appname = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name"));
if (!appname.is_empty()) {
Expand Down
2 changes: 0 additions & 2 deletions drivers/unix/os_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class OS_Unix : public OS {
virtual bool set_environment(const String &p_var, const String &p_value) const override;
virtual String get_locale() const override;

virtual int get_processor_count() const override;

virtual void initialize_debugging() override;

virtual String get_executable_path() const override;
Expand Down
11 changes: 0 additions & 11 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,17 +870,6 @@ BOOL is_wow64() {
return wow64;
}

int OS_Windows::get_processor_count() const {
SYSTEM_INFO sysinfo;
if (is_wow64()) {
GetNativeSystemInfo(&sysinfo);
} else {
GetSystemInfo(&sysinfo);
}

return sysinfo.dwNumberOfProcessors;
}

String OS_Windows::get_processor_name() const {
const String id = "Hardware\\Description\\System\\CentralProcessor\\0";

Expand Down
1 change: 0 additions & 1 deletion platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class OS_Windows : public OS {

virtual String get_locale() const override;

virtual int get_processor_count() const override;
virtual String get_processor_name() const override;

virtual uint64_t get_embedded_pck_offset() const override;
Expand Down

0 comments on commit 6bf02c0

Please sign in to comment.