Skip to content

Commit 3a740e9

Browse files
Copilotdarkautism
andcommitted
Fix lock-free queue bugs and add GitHub Actions CI
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
1 parent 878e624 commit 3a740e9

14 files changed

Lines changed: 35 additions & 5 deletions

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-and-test:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Build
15+
run: make
16+
- name: Test
17+
run: make test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@
88
/Visual Stdio/.vs/lfqueue/v14
99
/Visual Stdio/Release
1010
/Visual Stdio/Debug
11+
12+
# Build artifacts
13+
bin/
14+
*.o
15+
*.a
16+
*.so
17+
*.so.*

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

bin/example

-26 KB
Binary file not shown.

bin/test_p100c10

-30.6 KB
Binary file not shown.

bin/test_p10c100

-30.6 KB
Binary file not shown.

bin/test_p1c1

-30.4 KB
Binary file not shown.

bin/test_p4c4

-30.6 KB
Binary file not shown.

cross-platform.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
#define lmb() asm volatile("":::"memory") // compiler barrier only. runtime reordering already impossible on x86
5353
#define smb() asm volatile("":::"memory")
5454
// "mfence" for lmb and smb makes assertion failures rarer, but doesn't eliminate, so it's just papering over the symptoms
55-
#endif // else no definition
55+
#else
56+
#define lmb() mb()
57+
#define smb() mb()
58+
#endif
5659

5760
// thread
5861
#include <pthread.h>

lfq.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ int lfq_init(struct lfq_ctx *ctx, int max_consume_thread) {
9191
return -errno;
9292

9393
struct lfq_node * free_pool_node = calloc(1,sizeof(struct lfq_node));
94-
if (!free_pool_node)
94+
if (!free_pool_node) {
95+
free(tmpnode);
9596
return -errno;
97+
}
9698

9799
tmpnode->can_free = free_pool_node->can_free = true;
98100
memset(ctx, 0, sizeof(struct lfq_ctx));
99101
ctx->MAXHPSIZE = max_consume_thread;
100-
ctx->HP = calloc(max_consume_thread,sizeof(struct lfq_node));
101-
ctx->tid_map = calloc(max_consume_thread,sizeof(struct lfq_node));
102+
ctx->HP = calloc(max_consume_thread,sizeof(struct lfq_node *));
103+
ctx->tid_map = calloc(max_consume_thread,sizeof(int));
102104
ctx->head = ctx->tail=tmpnode;
103105
ctx->fph = ctx->fpt=free_pool_node;
104106

0 commit comments

Comments
 (0)