diff --git a/src/cpu.cpp b/src/cpu.cpp index 31a83e92..558c1e75 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -26,7 +26,6 @@ #endif #include "file_utils.h" -pthread_t cpuTempThread; void calculateCPUData(CPUData& cpuData, unsigned long long int usertime, diff --git a/src/gpu.cpp b/src/gpu.cpp index e53aef8b..d758fbc7 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -4,9 +4,8 @@ struct gpuInfo gpu_info; FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *amdGpuVramTotalFile = nullptr, *amdGpuVramUsedFile = nullptr, *amdGpuCoreClockFile = nullptr, *amdGpuMemoryClockFile = nullptr; -pthread_t cpuThread, gpuThread, cpuInfoThread; -void *getNvidiaGpuInfo(void *){ +void getNvidiaGpuInfo(){ if (nvmlSuccess){ getNVMLInfo(); gpu_info.load = nvidiaUtilization.gpu; @@ -25,12 +24,9 @@ void *getNvidiaGpuInfo(void *){ gpu_info.MemClock = nvctrl_info.MemClock; } #endif - - pthread_detach(gpuThread); - return NULL; } -void *getAmdGpuUsage(void *){ +void getAmdGpuUsage(){ int64_t value = 0; if (amdGpuFile) { @@ -87,7 +83,4 @@ void *getAmdGpuUsage(void *){ amdgpu.MemClock = value / 1000000; gpu_info.MemClock = amdgpu.MemClock; } - - pthread_detach(gpuThread); - return NULL; } \ No newline at end of file diff --git a/src/gpu.h b/src/gpu.h index 47ee7bb3..d8863335 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -7,7 +7,6 @@ using namespace std; extern FILE *amdGpuFile, *amdTempFile, *amdGpuVramTotalFile, *amdGpuVramUsedFile, *amdGpuCoreClockFile, *amdGpuMemoryClockFile; -extern pthread_t cpuThread, gpuThread, cpuInfoThread; struct amdGpu { int load; @@ -30,6 +29,5 @@ struct gpuInfo{ extern struct amdGpu amdgpu; extern struct gpuInfo gpu_info; -void *getNvidiaInfo(void*); -void *getNvidiaGpuInfo(void*); -void *getAmdGpuUsage(void*); \ No newline at end of file +void getNvidiaGpuInfo(void); +void getAmdGpuUsage(void); \ No newline at end of file diff --git a/src/iostats.cpp b/src/iostats.cpp index bd0ef5f5..9c740b95 100644 --- a/src/iostats.cpp +++ b/src/iostats.cpp @@ -2,8 +2,7 @@ #include "string_utils.h" #include -pthread_t ioThread; -void *getIoStats(void *args) { +void getIoStats(void *args) { iostats *io = reinterpret_cast(args); if (io) { io->prev.read_bytes = io->curr.read_bytes; @@ -22,6 +21,4 @@ void *getIoStats(void *args) { io->diff.read = (io->curr.read_bytes - io->prev.read_bytes) / (1024.f * 1024.f); io->diff.write = (io->curr.write_bytes - io->prev.write_bytes) / (1024.f * 1024.f); } - pthread_detach(ioThread); - return NULL; } diff --git a/src/iostats.h b/src/iostats.h index eae538c4..6e48840a 100644 --- a/src/iostats.h +++ b/src/iostats.h @@ -2,8 +2,6 @@ #include #include -extern pthread_t ioThread; - struct iostats { struct { unsigned long long read_bytes; @@ -19,4 +17,4 @@ struct iostats { } diff; }; -void *getIoStats(void *args); +void getIoStats(void *args); diff --git a/src/keybinds.h b/src/keybinds.h index 406bffee..c8945f27 100644 --- a/src/keybinds.h +++ b/src/keybinds.h @@ -8,7 +8,6 @@ typedef unsigned long KeySym; double elapsedF2, elapsedF12, elapsedReloadCfg; uint64_t last_f2_press, last_f12_press, reload_cfg_press; -pthread_t f2; #ifdef HAVE_X11 bool key_is_pressed(KeySym ks) { diff --git a/src/logging.h b/src/logging.h index 12329b2c..4eeead50 100644 --- a/src/logging.h +++ b/src/logging.h @@ -37,7 +37,7 @@ void writeFile(string filename){ logArray.clear(); } -void *logging(void *params_void){ +void logging(void *params_void){ overlay_params *params = reinterpret_cast(params_void); time_t now_log = time(0); tm *log_time = localtime(&now_log); @@ -65,5 +65,4 @@ void *logging(void *params_void){ } writeFile(params->output_file + date); - return NULL; } diff --git a/src/memory.cpp b/src/memory.cpp index e9412751..323e419d 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -6,7 +6,6 @@ #include struct memory_information mem_info; -pthread_t memoryThread; float memused, memmax; FILE *open_file(const char *file, int *reported) { @@ -25,7 +24,7 @@ FILE *open_file(const char *file, int *reported) { return fp; } -void *update_meminfo(void *) { +void update_meminfo(void) { FILE *meminfo_fp; static int reported = 0; @@ -97,6 +96,4 @@ void *update_meminfo(void *) { memmax = float(mem_info.memmax) / (1024 * 1024); fclose(meminfo_fp); - pthread_detach(memoryThread); - return NULL; } \ No newline at end of file diff --git a/src/memory.h b/src/memory.h index dadcd4b4..7b022a88 100644 --- a/src/memory.h +++ b/src/memory.h @@ -1,7 +1,6 @@ #include #include -extern pthread_t memoryThread; extern float memused, memmax; struct memory_information { @@ -12,5 +11,5 @@ struct memory_information { unsigned long long bufmem, buffers, cached; }; -void *update_meminfo(void*); +void update_meminfo(void); FILE *open_file(const char *file, int *reported); \ No newline at end of file diff --git a/src/notify.cpp b/src/notify.cpp index e31a9b54..c3750442 100644 --- a/src/notify.cpp +++ b/src/notify.cpp @@ -9,7 +9,7 @@ #define EVENT_SIZE ( sizeof (struct inotify_event) ) #define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) -static void *fileChanged(void *params_void) { +static void fileChanged(void *params_void) { notify_thread *nt = reinterpret_cast(params_void); int length, i = 0; char buffer[EVENT_BUF_LEN]; @@ -30,7 +30,6 @@ static void *fileChanged(void *params_void) { i = 0; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } - return nullptr; } bool start_notifier(notify_thread& nt) @@ -48,8 +47,7 @@ bool start_notifier(notify_thread& nt) return false; } - pthread_create(&nt.thread, NULL, &fileChanged, &nt); - + std::thread(fileChanged, &nt).detach(); return true; } @@ -62,6 +60,4 @@ void stop_notifier(notify_thread& nt) inotify_rm_watch(nt.fd, nt.wd); close(nt.fd); nt.fd = -1; - - pthread_join(nt.thread, nullptr); } diff --git a/src/notify.h b/src/notify.h index f5c4e77a..2ace865f 100644 --- a/src/notify.h +++ b/src/notify.h @@ -8,7 +8,6 @@ struct notify_thread overlay_params *params = nullptr; bool quit = false; std::mutex mutex; - pthread_t thread; }; bool start_notifier(notify_thread& nt); diff --git a/src/overlay.cpp b/src/overlay.cpp index e603fe03..e8ecc649 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -870,7 +870,7 @@ void check_keybinds(struct overlay_params& params){ loggingOn = !loggingOn; if (loggingOn && log_period != 0) - pthread_create(&f2, NULL, &logging, ¶ms); + std::thread(logging, ¶ms).detach(); } } @@ -927,18 +927,18 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats]) { if (vendorID == 0x1002) - pthread_create(&gpuThread, NULL, &getAmdGpuUsage, NULL); + std::thread(getAmdGpuUsage).detach(); if (vendorID == 0x10de) - pthread_create(&gpuThread, NULL, &getNvidiaGpuInfo, NULL); + std::thread(getNvidiaGpuInfo).detach(); } // get ram usage/max if (params.enabled[OVERLAY_PARAM_ENABLED_ram]) - pthread_create(&memoryThread, NULL, &update_meminfo, NULL); + std::thread(update_meminfo).detach(); if (params.enabled[OVERLAY_PARAM_ENABLED_io_read] || params.enabled[OVERLAY_PARAM_ENABLED_io_write]) - pthread_create(&ioThread, NULL, &getIoStats, &sw_stats.io); - + std::thread(getIoStats, &sw_stats.io).detach(); + gpuLoadLog = gpu_info.load; cpuLoadLog = sw_stats.total_cpu; sw_stats.fps = fps;