Skip to content

Commit 5b2006c

Browse files
committed
Global: get rid of locks
Psychological burden NO MORE
1 parent d3f673d commit 5b2006c

File tree

10 files changed

+2
-69
lines changed

10 files changed

+2
-69
lines changed

src/common/dbus.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ static const FFDBusLibrary* loadLib(void)
3333
static FFDBusLibrary lib;
3434
static bool loaded = false;
3535
static bool loadSuccess = false;
36-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
37-
38-
ffThreadMutexLock(&mutex);
3936

4037
if(!loaded)
4138
{
4239
loaded = true;
4340
loadSuccess = loadLibSymbols(&lib);
4441
}
4542

46-
ffThreadMutexUnlock(&mutex);
4743
return loadSuccess ? &lib : NULL;
4844
}
4945

src/common/settings.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ typedef enum FFInitState
1515

1616
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
1717
static dataObject data; \
18-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
1918
static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \
20-
ffThreadMutexLock(&mutex); \
2119
if(initState != FF_INITSTATE_UNINITIALIZED) {\
22-
ffThreadMutexUnlock(&mutex); \
2320
return initState == FF_INITSTATE_SUCCESSFUL ? &data : NULL; \
2421
} \
2522
initState = FF_INITSTATE_SUCCESSFUL; \
2623
void* libraryHandle = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL); \
2724
if(libraryHandle == NULL) { \
2825
initState = FF_INITSTATE_FAILED; \
29-
ffThreadMutexUnlock(&mutex); \
3026
return NULL; \
3127
} \
3228

@@ -35,20 +31,17 @@ typedef enum FFInitState
3531
if(data.ff ## symbolName == NULL) { \
3632
dlclose(libraryHandle); \
3733
initState = FF_INITSTATE_FAILED; \
38-
ffThreadMutexUnlock(&mutex); \
3934
return NULL; \
4035
}
4136

4237
#define FF_LIBRARY_DATA_LOAD_RETURN \
4338
initState = FF_INITSTATE_SUCCESSFUL; \
44-
ffThreadMutexUnlock(&mutex); \
4539
return &data;
4640

4741
#define FF_LIBRARY_DATA_LOAD_ERROR \
4842
{ \
4943
dlclose(libraryHandle); \
5044
initState = FF_INITSTATE_FAILED; \
51-
ffThreadMutexUnlock(&mutex); \
5245
return NULL; \
5346
}
5447

src/detection/displayserver/linux/wayland.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
202202
if(display.width <= 0 || display.height <= 0)
203203
return;
204204

205-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
206-
ffThreadMutexLock(&mutex);
207-
208205
switch(display.transform)
209206
{
210207
case WL_OUTPUT_TRANSFORM_90:
@@ -262,8 +259,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist
262259
ffStrbufDestroy(&display.vendorAndModelId);
263260
ffStrbufDestroy(&display.name);
264261
ffStrbufDestroy(&display.edidName);
265-
266-
ffThreadMutexUnlock(&mutex);
267262
}
268263

269264
static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)

src/detection/gtk_qt/gtk.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName,
3636

3737
static void detectGTKFromSettings(FFGTKResult* result)
3838
{
39-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
40-
4139
static const char* themeName = NULL;
4240
static const char* iconsName = NULL;
4341
static const char* fontName = NULL;
@@ -47,11 +45,8 @@ static void detectGTKFromSettings(FFGTKResult* result)
4745

4846
static bool init = false;
4947

50-
ffThreadMutexLock(&mutex);
51-
5248
if(init)
5349
{
54-
ffThreadMutexUnlock(&mutex);
5550
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper);
5651
return;
5752
}
@@ -103,7 +98,6 @@ static void detectGTKFromSettings(FFGTKResult* result)
10398
wallpaper = ffSettingsGet("/org/gnome/desktop/background/picture-uri", "org.gnome.desktop.background", NULL, "picture-uri", FF_VARIANT_TYPE_STRING).strValue;
10499
}
105100

106-
ffThreadMutexUnlock(&mutex);
107101
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper);
108102
}
109103

@@ -178,14 +172,10 @@ static void detectGTK(const char* version, FFGTKResult* result)
178172
}
179173

180174
#define FF_DETECT_GTK_IMPL(version) \
181-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
182175
static FFGTKResult result; \
183176
static bool init = false; \
184-
ffThreadMutexLock(&mutex); \
185-
if(init){ \
186-
ffThreadMutexUnlock(&mutex);\
177+
if(init) \
187178
return &result; \
188-
} \
189179
init = true; \
190180
ffStrbufInit(&result.theme); \
191181
ffStrbufInit(&result.icons); \
@@ -194,7 +184,6 @@ static void detectGTK(const char* version, FFGTKResult* result)
194184
ffStrbufInit(&result.cursorSize); \
195185
ffStrbufInit(&result.wallpaper); \
196186
detectGTK(#version, &result); \
197-
ffThreadMutexUnlock(&mutex); \
198187
return &result;
199188

200189
const FFGTKResult* ffDetectGTK2(void)

src/detection/gtk_qt/qt.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,9 @@ const FFQtResult* ffDetectQt(void)
138138
{
139139
static FFQtResult result;
140140

141-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
142141
static bool init = false;
143-
ffThreadMutexLock(&mutex);
144142
if(init)
145-
{
146-
ffThreadMutexUnlock(&mutex);
147143
return &result;
148-
}
149144
init = true;
150145

151146
ffStrbufInit(&result.widgetStyle);
@@ -161,6 +156,5 @@ const FFQtResult* ffDetectQt(void)
161156
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT) == 0)
162157
detectLXQt(&result);
163158

164-
ffThreadMutexUnlock(&mutex);
165159
return &result;
166160
}

src/detection/internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66
#include "common/thread.h"
77

88
#define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \
9-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \
109
static ResultType result; \
1110
static bool init = false; \
12-
ffThreadMutexLock(&mutex); \
1311
if(init) \
14-
{ \
15-
ffThreadMutexUnlock(&mutex); \
1612
return &result; \
17-
} \
1813
init = true; \
1914
__VA_ARGS__; \
20-
ffThreadMutexUnlock(&mutex); \
2115
return &result; \
2216

2317
#endif

src/detection/temps/temps_linux.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
4444
const FFTempsResult* ffDetectTemps(void)
4545
{
4646
static FFTempsResult result;
47-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
4847
static bool init = false;
4948

50-
ffThreadMutexLock(&mutex);
5149
if(init)
52-
{
53-
ffThreadMutexUnlock(&mutex);
5450
return &result;
55-
}
5651
init = true;
5752

5853
ffListInitA(&result.values, sizeof(FFTempValue), 16);
@@ -64,10 +59,7 @@ const FFTempsResult* ffDetectTemps(void)
6459

6560
DIR* dirp = opendir(baseDir.chars);
6661
if(dirp == NULL)
67-
{
68-
ffThreadMutexUnlock(&mutex);
6962
return &result;
70-
}
7163

7264
struct dirent* entry;
7365
while((entry = readdir(dirp)) != NULL)
@@ -92,6 +84,5 @@ const FFTempsResult* ffDetectTemps(void)
9284

9385
closedir(dirp);
9486

95-
ffThreadMutexUnlock(&mutex);
9687
return &result;
9788
}

src/detection/terminalshell/terminalshell_linux.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers
310310

311311
const FFTerminalShellResult* ffDetectTerminalShell()
312312
{
313-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
314313
static FFTerminalShellResult result;
315314
static bool init = false;
316-
ffThreadMutexLock(&mutex);
317315
if(init)
318-
{
319-
ffThreadMutexUnlock(&mutex);
320316
return &result;
321-
}
322317
init = true;
323318

324319
#ifdef __APPLE__
@@ -413,6 +408,5 @@ const FFTerminalShellResult* ffDetectTerminalShell()
413408
ffStrbufInit(&result.terminalVersion);
414409
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
415410

416-
ffThreadMutexUnlock(&mutex);
417411
return &result;
418412
}

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers
355355

356356
const FFTerminalShellResult* ffDetectTerminalShell(void)
357357
{
358-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
359358
static FFTerminalShellResult result;
360359
static bool init = false;
361-
ffThreadMutexLock(&mutex);
362360
if(init)
363-
{
364-
ffThreadMutexUnlock(&mutex);
365361
return &result;
366-
}
367362
init = true;
368363

369364
ffStrbufInit(&result.shellProcessName);
@@ -381,7 +376,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(void)
381376

382377
uint32_t ppid;
383378
if(!getProcessInfo(0, &ppid, NULL, NULL, NULL))
384-
goto exit;
379+
return &result;
385380

386381
ppid = getShellInfo(&result, ppid);
387382
if(ppid)
@@ -393,7 +388,5 @@ const FFTerminalShellResult* ffDetectTerminalShell(void)
393388
ffStrbufInit(&result.terminalVersion);
394389
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
395390

396-
exit:
397-
ffThreadMutexUnlock(&mutex);
398391
return &result;
399392
}

src/detection/vulkan/vulkan.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,10 @@ static const char* detectVulkan(FFVulkanResult* result)
228228
FFVulkanResult* ffDetectVulkan(void)
229229
{
230230
static FFVulkanResult result;
231-
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
232231
static bool init = false;
233232

234-
ffThreadMutexLock(&mutex);
235233
if(init)
236-
{
237-
ffThreadMutexUnlock(&mutex);
238234
return &result;
239-
}
240235
init = true;
241236

242237
ffStrbufInit(&result.driver);
@@ -250,6 +245,5 @@ FFVulkanResult* ffDetectVulkan(void)
250245
result.error = "fastfetch was compiled without vulkan support";
251246
#endif
252247

253-
ffThreadMutexUnlock(&mutex);
254248
return &result;
255249
}

0 commit comments

Comments
 (0)