Skip to content

Commit

Permalink
Merge pull request #598 from just-now/thread-pool-clean
Browse files Browse the repository at this point in the history
Thread pool clean
  • Loading branch information
cole-miller authored Feb 22, 2024
2 parents 62ffea1 + 616e1a3 commit c9eda92
Show file tree
Hide file tree
Showing 6 changed files with 795 additions and 1 deletion.
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

0 comments on commit c9eda92

Please sign in to comment.