Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread pool clean #598

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ BasedOnStyle: Chromium
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AfterStruct: true
AfterStruct: false
Cpp11BracedListStyle: false
IndentWidth: 8
UseTab: ForContinuationAndIndentation
PointerAlignment: Right
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ basic_dqlite_sources = \
src/lib/buffer.c \
src/lib/fs.c \
src/lib/sm.c \
src/lib/threadpool.c \
src/lib/transport.c \
src/logger.c \
src/message.c \
Expand Down Expand Up @@ -149,6 +150,7 @@ unit_test_SOURCES += \
test/test_error.c \
test/test_integration.c \
test/unit/ext/test_uv.c \
test/unit/ext/test_uv_pool.c \
test/unit/lib/test_addr.c \
test/unit/lib/test_buffer.c \
test/unit/lib/test_byte.c \
Expand Down
32 changes: 32 additions & 0 deletions src/lib/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ typedef void *queue[2];
QUEUE__PREV(q) = (e); \
}

#define QUEUE__INSERT_TAIL(q, e) QUEUE__PUSH(q, e)

/**
* Insert an element at the front of a queue.
*/
#define QUEUE__INSERT_HEAD(h, q) \
{ \
QUEUE__NEXT(q) = QUEUE__NEXT(h); \
QUEUE__PREV(q) = (h); \
QUEUE__NEXT_PREV(q) = (q); \
QUEUE__NEXT(h) = (q); \
}

/**
* Remove the given element from the queue. Any element can be removed at any
* time.
Expand All @@ -47,6 +60,25 @@ typedef void *queue[2];
QUEUE__NEXT_PREV(e) = QUEUE__PREV(e); \
}

/**
* Moves elements from queue @h to queue @n
* Note: Removed QUEUE__SPLIT() and merged it into QUEUE__MOVE().
*/
#define QUEUE__MOVE(h, n) \
{ \
if (QUEUE__IS_EMPTY(h)) { \
QUEUE__INIT(n); \
} else { \
queue *__q = QUEUE__HEAD(h); \
QUEUE__PREV(n) = QUEUE__PREV(h); \
QUEUE__PREV_NEXT(n) = (n); \
QUEUE__NEXT(n) = (__q); \
QUEUE__PREV(h) = QUEUE__PREV(__q); \
QUEUE__PREV_NEXT(h) = (h); \
QUEUE__PREV(__q) = (n); \
} \
}

/**
* Return the element at the front of the queue.
*/
Expand Down
Loading
Loading