mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Global: get rid of locks
Psychological burden NO MORE
This commit is contained in:
@@ -33,9 +33,6 @@ static const FFDBusLibrary* loadLib(void)
|
||||
static FFDBusLibrary lib;
|
||||
static bool loaded = false;
|
||||
static bool loadSuccess = false;
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
|
||||
ffThreadMutexLock(&mutex);
|
||||
|
||||
if(!loaded)
|
||||
{
|
||||
@@ -43,7 +40,6 @@ static const FFDBusLibrary* loadLib(void)
|
||||
loadSuccess = loadLibSymbols(&lib);
|
||||
}
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return loadSuccess ? &lib : NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,14 @@ typedef enum FFInitState
|
||||
|
||||
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
|
||||
static dataObject data; \
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
|
||||
static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \
|
||||
ffThreadMutexLock(&mutex); \
|
||||
if(initState != FF_INITSTATE_UNINITIALIZED) {\
|
||||
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; \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return NULL; \
|
||||
} \
|
||||
|
||||
@@ -35,20 +31,17 @@ typedef enum FFInitState
|
||||
if(data.ff ## symbolName == NULL) { \
|
||||
dlclose(libraryHandle); \
|
||||
initState = FF_INITSTATE_FAILED; \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define FF_LIBRARY_DATA_LOAD_RETURN \
|
||||
initState = FF_INITSTATE_SUCCESSFUL; \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return &data;
|
||||
|
||||
#define FF_LIBRARY_DATA_LOAD_ERROR \
|
||||
{ \
|
||||
dlclose(libraryHandle); \
|
||||
initState = FF_INITSTATE_FAILED; \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
|
||||
@@ -202,9 +202,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
|
||||
if(display.width <= 0 || display.height <= 0)
|
||||
return;
|
||||
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
ffThreadMutexLock(&mutex);
|
||||
|
||||
switch(display.transform)
|
||||
{
|
||||
case WL_OUTPUT_TRANSFORM_90:
|
||||
@@ -262,8 +259,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
|
||||
ffStrbufDestroy(&display.vendorAndModelId);
|
||||
ffStrbufDestroy(&display.name);
|
||||
ffStrbufDestroy(&display.edidName);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
}
|
||||
|
||||
static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
|
||||
|
||||
@@ -36,8 +36,6 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName,
|
||||
|
||||
static void detectGTKFromSettings(FFGTKResult* result)
|
||||
{
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static const char* themeName = NULL;
|
||||
static const char* iconsName = NULL;
|
||||
static const char* fontName = NULL;
|
||||
@@ -47,11 +45,8 @@ static void detectGTKFromSettings(FFGTKResult* result)
|
||||
|
||||
static bool init = false;
|
||||
|
||||
ffThreadMutexLock(&mutex);
|
||||
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper);
|
||||
return;
|
||||
}
|
||||
@@ -103,7 +98,6 @@ static void detectGTKFromSettings(FFGTKResult* result)
|
||||
wallpaper = ffSettingsGet("/org/gnome/desktop/background/picture-uri", "org.gnome.desktop.background", NULL, "picture-uri", FF_VARIANT_TYPE_STRING).strValue;
|
||||
}
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper);
|
||||
}
|
||||
|
||||
@@ -178,14 +172,10 @@ static void detectGTK(const char* version, FFGTKResult* result)
|
||||
}
|
||||
|
||||
#define FF_DETECT_GTK_IMPL(version) \
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
|
||||
static FFGTKResult result; \
|
||||
static bool init = false; \
|
||||
ffThreadMutexLock(&mutex); \
|
||||
if(init){ \
|
||||
ffThreadMutexUnlock(&mutex);\
|
||||
if(init) \
|
||||
return &result; \
|
||||
} \
|
||||
init = true; \
|
||||
ffStrbufInit(&result.theme); \
|
||||
ffStrbufInit(&result.icons); \
|
||||
@@ -194,7 +184,6 @@ static void detectGTK(const char* version, FFGTKResult* result)
|
||||
ffStrbufInit(&result.cursorSize); \
|
||||
ffStrbufInit(&result.wallpaper); \
|
||||
detectGTK(#version, &result); \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return &result;
|
||||
|
||||
const FFGTKResult* ffDetectGTK2(void)
|
||||
|
||||
@@ -138,14 +138,9 @@ const FFQtResult* ffDetectQt(void)
|
||||
{
|
||||
static FFQtResult result;
|
||||
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
static bool init = false;
|
||||
ffThreadMutexLock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.widgetStyle);
|
||||
@@ -161,6 +156,5 @@ const FFQtResult* ffDetectQt(void)
|
||||
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT) == 0)
|
||||
detectLXQt(&result);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -6,18 +6,12 @@
|
||||
#include "common/thread.h"
|
||||
|
||||
#define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
|
||||
static ResultType result; \
|
||||
static bool init = false; \
|
||||
ffThreadMutexLock(&mutex); \
|
||||
if(init) \
|
||||
{ \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return &result; \
|
||||
} \
|
||||
init = true; \
|
||||
__VA_ARGS__; \
|
||||
ffThreadMutexUnlock(&mutex); \
|
||||
return &result; \
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,15 +44,10 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
|
||||
const FFTempsResult* ffDetectTemps(void)
|
||||
{
|
||||
static FFTempsResult result;
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
static bool init = false;
|
||||
|
||||
ffThreadMutexLock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffListInitA(&result.values, sizeof(FFTempValue), 16);
|
||||
@@ -64,10 +59,7 @@ const FFTempsResult* ffDetectTemps(void)
|
||||
|
||||
DIR* dirp = opendir(baseDir.chars);
|
||||
if(dirp == NULL)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
@@ -92,6 +84,5 @@ const FFTempsResult* ffDetectTemps(void)
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -310,15 +310,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers
|
||||
|
||||
const FFTerminalShellResult* ffDetectTerminalShell()
|
||||
{
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
static FFTerminalShellResult result;
|
||||
static bool init = false;
|
||||
ffThreadMutexLock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
#ifdef __APPLE__
|
||||
@@ -413,6 +408,5 @@ const FFTerminalShellResult* ffDetectTerminalShell()
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -355,15 +355,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers
|
||||
|
||||
const FFTerminalShellResult* ffDetectTerminalShell(void)
|
||||
{
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
static FFTerminalShellResult result;
|
||||
static bool init = false;
|
||||
ffThreadMutexLock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.shellProcessName);
|
||||
@@ -381,7 +376,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(void)
|
||||
|
||||
uint32_t ppid;
|
||||
if(!getProcessInfo(0, &ppid, NULL, NULL, NULL))
|
||||
goto exit;
|
||||
return &result;
|
||||
|
||||
ppid = getShellInfo(&result, ppid);
|
||||
if(ppid)
|
||||
@@ -393,7 +388,5 @@ const FFTerminalShellResult* ffDetectTerminalShell(void)
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
exit:
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -228,15 +228,10 @@ static const char* detectVulkan(FFVulkanResult* result)
|
||||
FFVulkanResult* ffDetectVulkan(void)
|
||||
{
|
||||
static FFVulkanResult result;
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
static bool init = false;
|
||||
|
||||
ffThreadMutexLock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.driver);
|
||||
@@ -250,6 +245,5 @@ FFVulkanResult* ffDetectVulkan(void)
|
||||
result.error = "fastfetch was compiled without vulkan support";
|
||||
#endif
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user