Skip to content

Commit

Permalink
Refactor threading module: rename files & update refs 🌟
Browse files Browse the repository at this point in the history
- Renamed `athr_thr.c` to `athr_thread.c`; `athr_thr.h` to `athr_thread.h`.
- Updated includes: `athr_thr.h` to `athr_thread.h` in `athr.c` and `athr.h`.
- Adjusted Makefile to exclude `athr_terminal_ioctl` files on Windows.
- Added `.PHONY` targets to Makefile for `all`, `check`, `uninstall`, and `clean`.

These changes clarify the threading module's purpose by using full word names
and enhance Makefile's organization and cross-platform consistency.
  • Loading branch information
horta committed Nov 8, 2024
1 parent d3858e7 commit 90de4c6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ endif
ifeq ($(UNAME),Windows)
CFLAGS += -DATHR_OS_WIN32
CFLAGS += -DATHR_TERMINAL_WIN32
SRC := $(filter-out athr_terminal_ioctl.c,$(SRC))
HDR := $(filter-out athr_terminal_ioctl.h,$(SRC))
else
CFLAGS += -DATHR_OS_UNIX
ifeq ($(CURSES_FOUND),true)
Expand All @@ -58,9 +60,9 @@ $(info CC = $(CC))
$(info PKG_CONFIG_FOUND = $(PKG_CONFIG_FOUND))
$(info CURSES_FOUND = $(CURSES_FOUND))
$(info CURSES_LIBS = $(CURSES_LIBS))
$(info ATHR_TERMINAL = $(ATHR_TERMINAL))
$(info CFLAGS = $(CFLAGS))

.PHONY: all
all: $(LIB)

$(LIB): $(OBJ)
Expand All @@ -74,6 +76,7 @@ $(LIB): $(OBJ)
$(TEST_TARGET): %: %.o $(LIB)
$(CC) $(CFLAGS) $< -L. -lathr $(CURSES_LIBS) -lm -o $@

.PHONY: check
check: $(TEST_TARGET)
for test in $(TEST_TARGET); do ./$$test || exit 1; done

Expand All @@ -82,9 +85,10 @@ install: $(LIB) $(HDR)
install -m 0755 $(LIB) $(PREFIX)/lib/
install -m 0644 $(HDR) $(PREFIX)/include/

.PHONY: uninstall
uninstall:
rm -f $(PREFIX)/lib/$(LIB) $(HDR:%=$(PREFIX)/include/%)

.PHONY: all clean check uninstall
.PHONY: clean
clean:
rm -f $(OBJ) $(LIB) $(TEST_OBJ) $(TEST_TARGET) *.d
2 changes: 1 addition & 1 deletion athr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "athr_elapsed.h"
#include "athr_ema.h"
#include "athr_logger.h"
#include "athr_thr.h"
#include "athr_thread.h"
#include "athr_widget_bar.h"
#include "athr_widget_eta.h"
#include "athr_widget_main.h"
Expand Down
2 changes: 1 addition & 1 deletion athr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "athr_ema.h"
#include "athr_option.h"
#include "athr_thr.h"
#include "athr_thread.h"
#include "athr_widget_main.h"
#include <stdint.h>

Expand Down
16 changes: 8 additions & 8 deletions athr_thr.c β†’ athr_thread.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "athr_thr.h"
#include "athr_thread.h"

#if defined(ATHR_OS_WIN32)
#define WRAPPER_RETURN DWORD WINAPI
Expand All @@ -10,8 +10,8 @@

static WRAPPER_RETURN __thr_wrapper(WRAPPER_ARG_T arg)
{
struct athr_thread *thr = (struct athr_thread *)arg;
thr->func(thr->arg);
struct athr_thread *x = (struct athr_thread *)arg;
x->func(x->arg);

#if defined(ATHR_OS_WIN32)
ExitThread(0);
Expand All @@ -30,8 +30,8 @@ int athr_thread_create(struct athr_thread *x, athr_thread_start *func, void *arg
int rc = 0;

#if defined(ATHR_OS_WIN32)
thr->handle = CreateThread(NULL, 0, __thr_wrapper, (LPVOID)thr, 0, NULL);
rc = !thr->handle;
x->handle = CreateThread(NULL, 0, __thr_wrapper, (LPVOID)x, 0, NULL);
rc = !x->handle;
#elif defined(ATHR_OS_UNIX)
rc = pthread_create(&x->handle, 0, __thr_wrapper, (void *)x);
#endif
Expand All @@ -43,7 +43,7 @@ void athr_thread_detach(struct athr_thread *x)
{
if (!x->has_been_created) return;
#if defined(ATHR_OS_WIN32)
CloseHandle(thr->handle);
CloseHandle(x->handle);
#elif defined(ATHR_OS_UNIX)
pthread_detach(x->handle);
#endif
Expand All @@ -52,8 +52,8 @@ void athr_thread_detach(struct athr_thread *x)
int athr_thread_join(struct athr_thread *x)
{
#if defined(ATHR_OS_WIN32)
if (WaitForSingleObject(thr, INFINITE) == WAIT_FAILED) return 1;
CloseHandle(thr->handle);
if (WaitForSingleObject(x, INFINITE) == WAIT_FAILED) return 1;
CloseHandle(x->handle);
return 0;
#elif defined(ATHR_OS_UNIX)
void *pres = NULL;
Expand Down
File renamed without changes.

0 comments on commit 90de4c6

Please sign in to comment.