Changed pthreads to std::thread

pull/142/head
FlightlessMango 4 years ago
parent c61d25da04
commit bff9958284

@ -26,7 +26,6 @@
#endif #endif
#include "file_utils.h" #include "file_utils.h"
pthread_t cpuTempThread;
void calculateCPUData(CPUData& cpuData, void calculateCPUData(CPUData& cpuData,
unsigned long long int usertime, unsigned long long int usertime,

@ -4,9 +4,8 @@
struct gpuInfo gpu_info; struct gpuInfo gpu_info;
FILE *amdGpuFile = nullptr, *amdTempFile = nullptr, *amdGpuVramTotalFile = nullptr, *amdGpuVramUsedFile = nullptr, *amdGpuCoreClockFile = nullptr, *amdGpuMemoryClockFile = nullptr; 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){ if (nvmlSuccess){
getNVMLInfo(); getNVMLInfo();
gpu_info.load = nvidiaUtilization.gpu; gpu_info.load = nvidiaUtilization.gpu;
@ -25,12 +24,9 @@ void *getNvidiaGpuInfo(void *){
gpu_info.MemClock = nvctrl_info.MemClock; gpu_info.MemClock = nvctrl_info.MemClock;
} }
#endif #endif
pthread_detach(gpuThread);
return NULL;
} }
void *getAmdGpuUsage(void *){ void getAmdGpuUsage(){
int64_t value = 0; int64_t value = 0;
if (amdGpuFile) { if (amdGpuFile) {
@ -87,7 +83,4 @@ void *getAmdGpuUsage(void *){
amdgpu.MemClock = value / 1000000; amdgpu.MemClock = value / 1000000;
gpu_info.MemClock = amdgpu.MemClock; gpu_info.MemClock = amdgpu.MemClock;
} }
pthread_detach(gpuThread);
return NULL;
} }

@ -7,7 +7,6 @@
using namespace std; using namespace std;
extern FILE *amdGpuFile, *amdTempFile, *amdGpuVramTotalFile, *amdGpuVramUsedFile, *amdGpuCoreClockFile, *amdGpuMemoryClockFile; extern FILE *amdGpuFile, *amdTempFile, *amdGpuVramTotalFile, *amdGpuVramUsedFile, *amdGpuCoreClockFile, *amdGpuMemoryClockFile;
extern pthread_t cpuThread, gpuThread, cpuInfoThread;
struct amdGpu { struct amdGpu {
int load; int load;
@ -30,6 +29,5 @@ struct gpuInfo{
extern struct amdGpu amdgpu; extern struct amdGpu amdgpu;
extern struct gpuInfo gpu_info; extern struct gpuInfo gpu_info;
void *getNvidiaInfo(void*); void getNvidiaGpuInfo(void);
void *getNvidiaGpuInfo(void*); void getAmdGpuUsage(void);
void *getAmdGpuUsage(void*);

@ -2,8 +2,7 @@
#include "string_utils.h" #include "string_utils.h"
#include <fstream> #include <fstream>
pthread_t ioThread; void getIoStats(void *args) {
void *getIoStats(void *args) {
iostats *io = reinterpret_cast<iostats *>(args); iostats *io = reinterpret_cast<iostats *>(args);
if (io) { if (io) {
io->prev.read_bytes = io->curr.read_bytes; 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.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); io->diff.write = (io->curr.write_bytes - io->prev.write_bytes) / (1024.f * 1024.f);
} }
pthread_detach(ioThread);
return NULL;
} }

@ -2,8 +2,6 @@
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
extern pthread_t ioThread;
struct iostats { struct iostats {
struct { struct {
unsigned long long read_bytes; unsigned long long read_bytes;
@ -19,4 +17,4 @@ struct iostats {
} diff; } diff;
}; };
void *getIoStats(void *args); void getIoStats(void *args);

@ -8,7 +8,6 @@ typedef unsigned long KeySym;
double elapsedF2, elapsedF12, elapsedReloadCfg; double elapsedF2, elapsedF12, elapsedReloadCfg;
uint64_t last_f2_press, last_f12_press, reload_cfg_press; uint64_t last_f2_press, last_f12_press, reload_cfg_press;
pthread_t f2;
#ifdef HAVE_X11 #ifdef HAVE_X11
bool key_is_pressed(KeySym ks) { bool key_is_pressed(KeySym ks) {

@ -37,7 +37,7 @@ void writeFile(string filename){
logArray.clear(); logArray.clear();
} }
void *logging(void *params_void){ void logging(void *params_void){
overlay_params *params = reinterpret_cast<overlay_params *>(params_void); overlay_params *params = reinterpret_cast<overlay_params *>(params_void);
time_t now_log = time(0); time_t now_log = time(0);
tm *log_time = localtime(&now_log); tm *log_time = localtime(&now_log);
@ -65,5 +65,4 @@ void *logging(void *params_void){
} }
writeFile(params->output_file + date); writeFile(params->output_file + date);
return NULL;
} }

@ -6,7 +6,6 @@
#include <thread> #include <thread>
struct memory_information mem_info; struct memory_information mem_info;
pthread_t memoryThread;
float memused, memmax; float memused, memmax;
FILE *open_file(const char *file, int *reported) { FILE *open_file(const char *file, int *reported) {
@ -25,7 +24,7 @@ FILE *open_file(const char *file, int *reported) {
return fp; return fp;
} }
void *update_meminfo(void *) { void update_meminfo(void) {
FILE *meminfo_fp; FILE *meminfo_fp;
static int reported = 0; static int reported = 0;
@ -97,6 +96,4 @@ void *update_meminfo(void *) {
memmax = float(mem_info.memmax) / (1024 * 1024); memmax = float(mem_info.memmax) / (1024 * 1024);
fclose(meminfo_fp); fclose(meminfo_fp);
pthread_detach(memoryThread);
return NULL;
} }

@ -1,7 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <thread> #include <thread>
extern pthread_t memoryThread;
extern float memused, memmax; extern float memused, memmax;
struct memory_information { struct memory_information {
@ -12,5 +11,5 @@ struct memory_information {
unsigned long long bufmem, buffers, cached; unsigned long long bufmem, buffers, cached;
}; };
void *update_meminfo(void*); void update_meminfo(void);
FILE *open_file(const char *file, int *reported); FILE *open_file(const char *file, int *reported);

@ -9,7 +9,7 @@
#define EVENT_SIZE ( sizeof (struct inotify_event) ) #define EVENT_SIZE ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) #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<notify_thread *>(params_void); notify_thread *nt = reinterpret_cast<notify_thread *>(params_void);
int length, i = 0; int length, i = 0;
char buffer[EVENT_BUF_LEN]; char buffer[EVENT_BUF_LEN];
@ -30,7 +30,6 @@ static void *fileChanged(void *params_void) {
i = 0; i = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
return nullptr;
} }
bool start_notifier(notify_thread& nt) bool start_notifier(notify_thread& nt)
@ -48,8 +47,7 @@ bool start_notifier(notify_thread& nt)
return false; return false;
} }
pthread_create(&nt.thread, NULL, &fileChanged, &nt); std::thread(fileChanged, &nt).detach();
return true; return true;
} }
@ -62,6 +60,4 @@ void stop_notifier(notify_thread& nt)
inotify_rm_watch(nt.fd, nt.wd); inotify_rm_watch(nt.fd, nt.wd);
close(nt.fd); close(nt.fd);
nt.fd = -1; nt.fd = -1;
pthread_join(nt.thread, nullptr);
} }

@ -8,7 +8,6 @@ struct notify_thread
overlay_params *params = nullptr; overlay_params *params = nullptr;
bool quit = false; bool quit = false;
std::mutex mutex; std::mutex mutex;
pthread_t thread;
}; };
bool start_notifier(notify_thread& nt); bool start_notifier(notify_thread& nt);

@ -870,7 +870,7 @@ void check_keybinds(struct overlay_params& params){
loggingOn = !loggingOn; loggingOn = !loggingOn;
if (loggingOn && log_period != 0) if (loggingOn && log_period != 0)
pthread_create(&f2, NULL, &logging, &params); std::thread(logging, &params).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 (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats]) {
if (vendorID == 0x1002) if (vendorID == 0x1002)
pthread_create(&gpuThread, NULL, &getAmdGpuUsage, NULL); std::thread(getAmdGpuUsage).detach();
if (vendorID == 0x10de) if (vendorID == 0x10de)
pthread_create(&gpuThread, NULL, &getNvidiaGpuInfo, NULL); std::thread(getNvidiaGpuInfo).detach();
} }
// get ram usage/max // get ram usage/max
if (params.enabled[OVERLAY_PARAM_ENABLED_ram]) 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]) 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; gpuLoadLog = gpu_info.load;
cpuLoadLog = sw_stats.total_cpu; cpuLoadLog = sw_stats.total_cpu;
sw_stats.fps = fps; sw_stats.fps = fps;

Loading…
Cancel
Save