nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit d5242aad49c093bcb44eb9be304e355a4f5796bd
parent 9f2ee7898e20a0182b2cd6bd6e4c3d1ac3aabcb4
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  1 Dec 2023 13:20:05 -0800

add missing cpu.h

oops

Diffstat:
MMakefile | 2+-
Acpu.h | 34++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ CFLAGS = -Wall -Wno-misleading-indentation -Wno-unused-function -Werror -O2 -g -Ideps/secp256k1/include -Ideps/lmdb -Ideps/flatcc/include -HEADERS = sha256.h nostrdb.h cursor.h hex.h jsmn.h config.h sha256.h random.h memchr.h $(C_BINDINGS) +HEADERS = sha256.h nostrdb.h cursor.h hex.h jsmn.h config.h sha256.h random.h memchr.h cpu.h $(C_BINDINGS) FLATCC_SRCS=deps/flatcc/src/runtime/json_parser.c deps/flatcc/src/runtime/verifier.c deps/flatcc/src/runtime/builder.c deps/flatcc/src/runtime/emitter.c deps/flatcc/src/runtime/refmap.c SRCS = nostrdb.c sha256.c bech32.c $(FLATCC_SRCS) LDS = $(SRCS) $(ARS) diff --git a/cpu.h b/cpu.h @@ -0,0 +1,34 @@ + +#if defined(_WIN32) || defined(_WIN64) + #include <windows.h> +#elif defined(__linux__) + #include <unistd.h> +#elif defined(__APPLE__) + #include <sys/types.h> + #include <sys/sysctl.h> +#else + #error "Unsupported platform" +#endif + +static inline int get_physical_cores() { + int num_cores = 0; + + // Windows + #if defined(_WIN32) || defined(_WIN64) + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + num_cores = sysinfo.dwNumberOfProcessors; // This returns logical processors + // Further use GetLogicalProcessorInformation for physical cores... + // Linux + #elif defined(__linux__) + num_cores = sysconf(_SC_NPROCESSORS_ONLN); // This returns logical processors + // macOS + #elif defined(__APPLE__) + size_t size = sizeof(num_cores); + sysctlbyname("hw.physicalcpu", &num_cores, &size, NULL, 0); + #else + num_cores = -1; // Unsupported platform + #endif + + return num_cores; +}