reformat code
This commit is contained in:
parent
2432c6fbdf
commit
720de00eb7
1 changed files with 58 additions and 67 deletions
|
@ -1,23 +1,20 @@
|
|||
#include "nvapi.h"
|
||||
|
||||
// TODO: remove
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <libloaderapi.h>
|
||||
# include <libloaderapi.h>
|
||||
#elif __linux__
|
||||
#include <dlfcn.h>
|
||||
# include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
/////
|
||||
|
||||
static void* lib;
|
||||
static void * lib;
|
||||
|
||||
static bool load_success;
|
||||
|
||||
typedef void* (*nvapi_QueryInterface_t)(int);
|
||||
typedef int (*NvAPI_EnumPhysicalGPUs_t)(void*, void*);
|
||||
typedef int (*NvAPI_GPU_SetForcePstate_t)(void*, int, int);
|
||||
typedef void * (*nvapi_QueryInterface_t)(int);
|
||||
typedef int (*NvAPI_EnumPhysicalGPUs_t)(void *, void *);
|
||||
typedef int (*NvAPI_GPU_SetForcePstate_t)(void *, int, int);
|
||||
typedef int (*NvAPI_Initialize_t)();
|
||||
typedef int (*NvAPI_Unload_t)();
|
||||
|
||||
|
@ -31,7 +28,7 @@ static NvAPI_Unload_t NvAPI_Unload;
|
|||
|
||||
void nvapi_init() {
|
||||
// load library
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
if (!lib) {
|
||||
lib = LoadLibrary("nvapi64.dll");
|
||||
}
|
||||
|
@ -39,7 +36,7 @@ void nvapi_init() {
|
|||
if (!lib) {
|
||||
lib = LoadLibrary("nvapi.dll");
|
||||
}
|
||||
#elif __linux__
|
||||
#elif __linux__
|
||||
if (!lib) {
|
||||
lib = dlopen("libnvidia-api.so.1", RTLD_LAZY);
|
||||
}
|
||||
|
@ -47,19 +44,15 @@ void nvapi_init() {
|
|||
if (!lib) {
|
||||
lib = dlopen("libnvidia-api.so", RTLD_LAZY);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// lookup QueryInterface
|
||||
if (lib) {
|
||||
#ifdef _WIN32
|
||||
if (!nvapi_QueryInterface) {
|
||||
#ifdef _WIN32
|
||||
nvapi_QueryInterface = (nvapi_QueryInterface_t) GetProcAddress(lib, "nvapi_QueryInterface");
|
||||
}
|
||||
#elif __linux__
|
||||
if (!nvapi_QueryInterface) {
|
||||
#elif __linux__
|
||||
nvapi_QueryInterface = (nvapi_QueryInterface_t) dlsym(lib, "nvapi_QueryInterface");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// resolve functions
|
||||
|
@ -83,15 +76,13 @@ void nvapi_free() {
|
|||
}
|
||||
|
||||
// free library
|
||||
#ifdef _WIN32
|
||||
if (lib) {
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(lib);
|
||||
}
|
||||
#elif __linux__
|
||||
if (lib) {
|
||||
#elif __linux__
|
||||
dlclose(lib);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// invalidate pointers
|
||||
lib = nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue