Thread: add common thread abstraction layer, and make threading optional

This commit is contained in:
李通洲
2022-10-12 14:13:20 +08:00
parent d0f589bb3e
commit 1b594d9ed1
15 changed files with 151 additions and 143 deletions
+26 -12
View File
@@ -23,6 +23,17 @@ if(MSYS)
enable_language(CXX)
endif()
#############################
# Compile time dependencies #
#############################
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
find_package(PkgConfig REQUIRED)
include(CheckIncludeFile)
#####################
# Configure options #
#####################
@@ -52,21 +63,11 @@ cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR MSYS" OFF)
cmake_dependent_option(ENABLE_LIBCJSON "Enable libcjson" ON "LINUX OR MSYS" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND AND NOT ANDROID" OFF)
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
#############################
# Compile time dependencies #
#############################
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
include(CheckIncludeFile)
####################
# Compiler options #
####################
@@ -76,6 +77,15 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if(ENABLE_THREADS)
if(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Threads type: pthread")
else()
message(STATUS "Threads type: Win32 thread")
endif()
else()
message(STATUS "Threads type: disabled")
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
@@ -482,6 +492,11 @@ ff_lib_enable(OPENCL OpenCL)
ff_lib_enable(LIBCJSON libcjson)
ff_lib_enable(FREETYPE freetype2)
if(ENABLE_THREADS)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS)
target_link_libraries(libfastfetch PRIVATE Threads::Threads)
endif()
if(APPLE)
target_link_libraries(libfastfetch
PRIVATE "-framework CoreFoundation"
@@ -511,7 +526,6 @@ target_include_directories(libfastfetch
target_link_libraries(libfastfetch
PRIVATE ${CMAKE_DL_LIBS}
PRIVATE Threads::Threads
)
######################
+2 -1
View File
@@ -21,9 +21,10 @@ There are some premade config files in [`presets`](presets), including the ones
## Dependencies
Fastfetch dynamically loads needed libraries if they are available. Therefore its only hard dependencies are `libc` (any implementation of the c standard library), `libdl` and `libpthread`. They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most linux distributions, so you probably don't have to worry about it.
Fastfetch dynamically loads needed libraries if they are available. Therefore its only hard dependencies are `libc` (any implementation of the c standard library), `libdl`. They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most linux distributions, so you probably don't have to worry about it.
The following libraries are used if present at runtime:
* [`libpthread`](https://man7.org/linux/man-pages/man7/pthreads.7.html): For multithreading support, which may improve performance
* [`libpci`](https://github.com/pciutils/pciutils): GPU output.
* [`libvulkan`](https://www.vulkan.org/): Vulkan module & fallback for GPU output.
* [`libxcb-randr`](https://xcb.freedesktop.org/),
+21 -69
View File
@@ -1,6 +1,7 @@
#include "fastfetch.h"
#include "common/caching.h"
#include "common/parsing.h"
#include "common/thread.h"
#include "detection/qt.h"
#include "detection/gtk.h"
#include "detection/displayserver/displayserver.h"
@@ -9,7 +10,6 @@
#include <unistd.h>
#include <sys/stat.h>
#include <signal.h>
#include <pthread.h>
static bool strbufEqualsAdapter(const void* first, const void* second)
{
@@ -259,87 +259,39 @@ void ffInitInstance(FFinstance* instance)
defaultConfig(instance);
}
#if !defined(__ANDROID__) && !defined(_WIN32) && !defined(__MSYS__)
#ifdef FF_HAVE_THREADS
static void* connectDisplayServerThreadMain(void* instance)
{
ffConnectDisplayServer((FFinstance*)instance);
return NULL;
}
FF_THREAD_ENTRY_DECL_WRAPPER(ffConnectDisplayServer, FFinstance*)
#if !defined(__APPLE__)
#if !(defined(__APPLE__) || defined(__MSYS__) || defined(_WIN32))
static void* detectPlasmaThreadMain(void* instance)
{
ffDetectQt((FFinstance*)instance);
return NULL;
}
#define FF_DETECT_QT_GTK 1
static void* detectGTK2ThreadMain(void* instance)
{
ffDetectGTK2((FFinstance*)instance);
return NULL;
}
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectQt, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK2, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK3, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK4, FFinstance*)
static void* detectGTK3ThreadMain(void* instance)
{
ffDetectGTK3((FFinstance*)instance);
return NULL;
}
#endif //!(defined(__APPLE__) || defined(__MSYS__) || defined(_WIN32))
static void* detectGTK4ThreadMain(void* instance)
{
ffDetectGTK4((FFinstance*)instance);
return NULL;
}
static void* startThreadsThreadMain(void* instance)
{
pthread_t dsThread;
pthread_create(&dsThread, NULL, connectDisplayServerThreadMain, instance);
pthread_detach(dsThread);
pthread_t gtk2Thread;
pthread_create(&gtk2Thread, NULL, detectGTK2ThreadMain, instance);
pthread_detach(gtk2Thread);
pthread_t gtk3Thread;
pthread_create(&gtk3Thread, NULL, detectGTK3ThreadMain, instance);
pthread_detach(gtk3Thread);
pthread_t gtk4Thread;
pthread_create(&gtk4Thread, NULL, detectGTK4ThreadMain, instance);
pthread_detach(gtk4Thread);
pthread_t plasmaThread;
pthread_create(&plasmaThread, NULL, detectPlasmaThreadMain, instance);
pthread_detach(plasmaThread);
return NULL;
}
#endif //FF_HAVE_THREADS
void startDetectionThreads(FFinstance* instance)
{
pthread_t startThreadsThread;
pthread_create(&startThreadsThread, NULL, startThreadsThreadMain, instance);
pthread_detach(startThreadsThread);
}
#ifdef FF_HAVE_THREADS
ffThreadCreateAndDetach(ffConnectDisplayServerThreadMain, instance);
#else // !__APPLE__
void startDetectionThreads(FFinstance* instance)
{
pthread_t startThreadsThread;
pthread_create(&startThreadsThread, NULL, connectDisplayServerThreadMain, instance);
pthread_detach(startThreadsThread);
}
#endif // __APPLE__
#ifdef FF_DETECT_QT_GTK
ffThreadCreateAndDetach(ffDetectQtThreadMain, instance);
ffThreadCreateAndDetach(ffDetectGTK2ThreadMain, instance);
ffThreadCreateAndDetach(ffDetectGTK3ThreadMain, instance);
ffThreadCreateAndDetach(ffDetectGTK4ThreadMain, instance);
#endif
#else // !__ANDROID__
void startDetectionThreads(FFinstance* instance)
{
#else
FF_UNUSED(instance);
#endif
}
#endif // __ANDROID__
static volatile bool ffDisableLinewrap = true;
static volatile bool ffHideCursor = true;
+8 -8
View File
@@ -2,8 +2,8 @@
#include "common/settings.h"
#include "common/library.h"
#include "common/io.h"
#include "common/thread.h"
#include <pthread.h>
#include <string.h>
typedef enum FFInitState
@@ -15,18 +15,18 @@ typedef enum FFInitState
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
static dataObject data; \
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \
pthread_mutex_lock(&mutex); \
ffThreadMutexLock(&mutex); \
if(initState != FF_INITSTATE_UNINITIALIZED) {\
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return initState == FF_INITSTATE_SUCCESSFUL ? &data : NULL; \
} \
initState = FF_INITSTATE_SUCCESSFUL; \
void* libraryHandle = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL); \
if(libraryHandle == NULL) { \
initState = FF_INITSTATE_FAILED; \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return NULL; \
} \
@@ -35,20 +35,20 @@ typedef enum FFInitState
if(data.ff ## symbolName == NULL) { \
dlclose(libraryHandle); \
initState = FF_INITSTATE_FAILED; \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return NULL; \
}
#define FF_LIBRARY_DATA_LOAD_RETURN \
initState = FF_INITSTATE_SUCCESSFUL; \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return &data;
#define FF_LIBRARY_DATA_LOAD_ERROR \
{ \
dlclose(libraryHandle); \
initState = FF_INITSTATE_FAILED; \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return NULL; \
}
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#ifndef FF_INCLUDED_common_thread
#define FF_INCLUDED_common_thread
#include "fastfetch.h"
#ifdef FF_HAVE_THREADS
#if defined(_WIN32)
#include <handleapi.h>
#include <synchapi.h>
#include <process.h> // Win32 <process.h> isn't available on MSYS2
#define FF_THREAD_MUTEX_INITIALIZER SRWLOCK_INIT
typedef SRWLOCK FFThreadMutex;
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { AcquireSRWLockExclusive(mutex); }
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { ReleaseSRWLockExclusive(mutex); }
static inline void ffThreadCreateAndDetach(__stdcall unsigned (* func)(void*), void* data) {
uintptr_t newThread = _beginthreadex(func, 0, data, NULL, 0, NULL);
if(newThread != 0)
CloseHandle((HANDLE)newThread);
}
#define FF_THREAD_ENTRY_DECL_WRAPPER(fn, paramType) static __stdcall unsigned fn ## ThreadMain (void* data) { fn((paramType)data); return 0; }
#else
#include <pthread.h>
#define FF_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t FFThreadMutex;
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); }
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); }
static inline void ffThreadCreateAndDetach(void* (* func)(void*), void* data) {
pthread_t newThread;
if(pthread_create(&newThread, NULL, func, data) == 0)
pthread_detach(newThread);
}
#define FF_THREAD_ENTRY_DECL_WRAPPER(fn, paramType) static void* fn ## ThreadMain (void* data) { fn((paramType)data); return NULL; }
#endif
#else //FF_HAVE_THREADS
#define FF_THREAD_MUTEX_INITIALIZER 0
typedef char FFThreadMutex;
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { FF_UNUSED(mutex) }
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { FF_UNUSED(mutex) }
#endif //FF_HAVE_THREADS
#endif
+5 -5
View File
@@ -1,21 +1,21 @@
#include "fastfetch.h"
#include "detection/datetime.h"
#include "common/thread.h"
#include <time.h>
#include <pthread.h>
const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance)
{
FF_UNUSED(instance); //We may need it later for additional configuration
static FFDateTimeResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if (init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -68,6 +68,6 @@ const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance)
ffStrbufInitA(&result.secondPretty, FASTFETCH_STRBUF_DEFAULT_ALLOC);
result.secondPretty.length = (uint32_t) strftime(result.secondPretty.chars, ffStrbufGetFree(&result.secondPretty), "%S", tm);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
+4 -4
View File
@@ -6,7 +6,7 @@
#ifdef FF_HAVE_WAYLAND
#include "common/library.h"
#include "common/io.h"
#include <pthread.h>
#include "common/thread.h"
#include <wayland-client.h>
#include <sys/socket.h>
@@ -56,12 +56,12 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint
if(!(flags & WL_OUTPUT_MODE_CURRENT) || width <= 0 || height <= 0)
return;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&mutex);
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
ffThreadMutexLock(&mutex);
FFResolutionResult* result = ffListAdd(wldata->results);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
result->width = (uint32_t) width;
result->height = (uint32_t) height;
+9 -10
View File
@@ -1,11 +1,10 @@
#include "fastfetch.h"
#include "detection/gtk.h"
#include "common/properties.h"
#include "common/thread.h"
#include "common/settings.h"
#include "detection/displayserver/displayserver.h"
#include <pthread.h>
static inline bool allPropertiesSet(FFGTKResult* result)
{
return
@@ -34,7 +33,7 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName,
static void detectGTKFromSettings(const FFinstance* instance, FFGTKResult* result)
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static const char* themeName = NULL;
static const char* iconsName = NULL;
@@ -44,11 +43,11 @@ static void detectGTKFromSettings(const FFinstance* instance, FFGTKResult* resul
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
return;
}
@@ -90,7 +89,7 @@ static void detectGTKFromSettings(const FFinstance* instance, FFGTKResult* resul
cursorSize = ffSettingsGet(instance, "/org/gnome/desktop/interface/cursor-size", "org.gnome.desktop.interface", NULL, "cursor-size", FF_VARIANT_TYPE_INT).intValue;
}
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
}
@@ -168,12 +167,12 @@ static void detectGTK(const FFinstance* instance, const char* version, FFGTKResu
}
#define FF_DETECT_GTK_IMPL(version) \
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
static FFGTKResult result; \
static bool init = false; \
pthread_mutex_lock(&mutex); \
ffThreadMutexLock(&mutex); \
if(init){ \
pthread_mutex_unlock(&mutex);\
ffThreadMutexUnlock(&mutex);\
return &result; \
} \
init = true; \
@@ -183,7 +182,7 @@ static void detectGTK(const FFinstance* instance, const char* version, FFGTKResu
ffStrbufInit(&result.cursor); \
ffStrbufInit(&result.cursorSize); \
detectGTK(instance, #version, &result); \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return &result;
const FFGTKResult* ffDetectGTK2(const FFinstance* instance)
+5 -5
View File
@@ -3,21 +3,21 @@
#ifndef FF_INCLUDED_detection_internal
#define FF_INCLUDED_detection_internal
#include "pthread.h"
#include "common/thread.h"
#define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
static ResultType result; \
static bool init = false; \
pthread_mutex_lock(&mutex); \
ffThreadMutexLock(&mutex); \
if(init) \
{ \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return &result; \
} \
init = true; \
__VA_ARGS__; \
pthread_mutex_unlock(&mutex); \
ffThreadMutexUnlock(&mutex); \
return &result; \
#endif
+1 -1
View File
@@ -1,8 +1,8 @@
#include "fastfetch.h"
#include "detection/media/media.h"
#include "common/thread.h"
#include <string.h>
#include <pthread.h>
#define FF_DBUS_MPRIS_PREFIX "org.mpris.MediaPlayer2."
#define FF_DBUS_TIMEOUT_MILLISECONDS 35
+5 -5
View File
@@ -1,11 +1,11 @@
#include "fastfetch.h"
#include "detection/qt.h"
#include "common/properties.h"
#include "common/thread.h"
#include "detection/displayserver/displayserver.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
static inline bool allValuesSet(const FFQtResult* result)
{
@@ -135,12 +135,12 @@ const FFQtResult* ffDetectQt(const FFinstance* instance)
{
static FFQtResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -157,6 +157,6 @@ const FFQtResult* ffDetectQt(const FFinstance* instance)
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "LXQt") == 0)
detectLXQt(instance, &result);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
+7 -7
View File
@@ -1,9 +1,9 @@
#include "fastfetch.h"
#include "common/io.h"
#include "common/thread.h"
#include "temps_linux.h"
#include <string.h>
#include <pthread.h>
#include <dirent.h>
static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
@@ -38,13 +38,13 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
const FFTempsResult* ffDetectTemps(const FFinstance* instance)
{
static FFTempsResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -52,7 +52,7 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance)
if(!instance->config.allowSlowOperations)
{
ffListInitA(&result.values, sizeof(FFTempValue), 0);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
@@ -68,7 +68,7 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance)
if(dirp == NULL)
{
ffStrbufDestroy(&baseDir);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
@@ -97,6 +97,6 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance)
closedir(dirp);
ffStrbufDestroy(&baseDir);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
@@ -3,13 +3,13 @@
#include "common/io.h"
#include "common/parsing.h"
#include "common/processing.h"
#include "common/thread.h"
#include "terminalshell.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#ifdef __APPLE__
#include <libproc.h>
@@ -318,13 +318,13 @@ const FFTerminalShellResult*
{
FF_UNUSED(instance);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static FFTerminalShellResult result;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -361,6 +361,6 @@ const FFTerminalShellResult*
else
ffStrbufInitCopy(&result.terminalPrettyName, &result.terminalProcessName);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
+5 -5
View File
@@ -1,9 +1,9 @@
#include "fastfetch.h"
#include "detection/title.h"
#include "common/thread.h"
#include <limits.h>
#include <unistd.h>
#include <pthread.h>
#include <netdb.h>
#ifndef HOST_NAME_MAX
@@ -37,12 +37,12 @@ const FFTitleResult* ffDetectTitle(const FFinstance* instance)
{
static FFTitleResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -60,6 +60,6 @@ const FFTitleResult* ffDetectTitle(const FFinstance* instance)
if(result.fqdn.length == 0)
ffStrbufAppend(&result.fqdn, &result.hostname);
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
+5 -6
View File
@@ -1,9 +1,8 @@
#include "fastfetch.h"
#include "common/thread.h"
#include "detection/vulkan.h"
#include "detection/gpu/gpu.h"
#include <pthread.h>
#ifdef FF_HAVE_VULKAN
#include "common/library.h"
#include "common/io.h"
@@ -217,13 +216,13 @@ static const char* detectVulkan(const FFinstance* instance, FFVulkanResult* resu
const FFVulkanResult* ffDetectVulkan(const FFinstance* instance)
{
static FFVulkanResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
ffThreadMutexLock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}
init = true;
@@ -240,6 +239,6 @@ const FFVulkanResult* ffDetectVulkan(const FFinstance* instance)
result.error = "fastfetch was compiled without vulkan support";
#endif
pthread_mutex_unlock(&mutex);
ffThreadMutexUnlock(&mutex);
return &result;
}