Skip to content

Commit 4628a55

Browse files
kbowers-jumpripatel-fd
authored andcommitted
vinyl request queue and ABI
This provides the vinly interprocess shared lockfree SPMC request queue and specifies the client-vinyl batch request ABI.
1 parent 7afc14b commit 4628a55

File tree

5 files changed

+863
-0
lines changed

5 files changed

+863
-0
lines changed

src/vinyl/fd_vinyl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
//#include "meta/fd_vinyl_meta.h" /* includes bstream/fd_vinyl_bstream.h */
88
//#include "data/fd_vinyl_data.h" /* includes io/fd_vinyl_io.h */
99
#include "line/fd_vinyl_line.h" /* includes meta/fd_vinyl_meta.h data/fd_vinyl_data.h */
10+
#include "rq/fd_vinyl_rq.h" /* includes fd_vinyl_base.h */
1011

1112
#endif /* HEADER_fd_src_vinyl_fd_vinyl_h */

src/vinyl/rq/Local.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(call add-hdrs,fd_vinyl_rq.h)
2+
$(call add-objs,fd_vinyl_rq,fd_vinyl)
3+
$(call make-unit-test,test_vinyl_rq,test_vinyl_rq,fd_vinyl fd_tango fd_util)
4+
$(call run-unit-test,test_vinyl_rq)

src/vinyl/rq/fd_vinyl_rq.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include "fd_vinyl_rq.h"
2+
3+
ulong
4+
fd_vinyl_rq_align( void ) {
5+
return alignof(fd_vinyl_rq_t);
6+
}
7+
8+
ulong
9+
fd_vinyl_rq_footprint( ulong req_cnt ) {
10+
if( FD_UNLIKELY( !((4UL<=req_cnt) & (req_cnt<(1UL<<63)/sizeof(fd_vinyl_req_t)) & fd_ulong_is_pow2( req_cnt )) ) ) return 0UL;
11+
return fd_ulong_align_up( sizeof(fd_vinyl_rq_t) + req_cnt*sizeof(fd_vinyl_req_t), alignof(fd_vinyl_rq_t) );
12+
}
13+
14+
void *
15+
fd_vinyl_rq_new( void * shmem,
16+
ulong req_cnt ) {
17+
fd_vinyl_rq_t * rq = (fd_vinyl_rq_t *)shmem;
18+
19+
if( FD_UNLIKELY( !rq ) ) {
20+
FD_LOG_WARNING(( "NULL shmem"));
21+
return NULL;
22+
}
23+
24+
if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)rq, fd_vinyl_rq_align() ) ) ) {
25+
FD_LOG_WARNING(( "bad align"));
26+
return NULL;
27+
}
28+
29+
ulong footprint = fd_vinyl_rq_footprint( req_cnt );
30+
if( FD_UNLIKELY( !footprint) ) {
31+
FD_LOG_WARNING(( "bad req_cnt"));
32+
return NULL;
33+
}
34+
35+
memset( rq, 0, footprint );
36+
37+
rq->req_cnt = req_cnt;
38+
rq->seq = 0UL;
39+
40+
fd_vinyl_req_t * req = fd_vinyl_rq_req( rq );
41+
42+
for( ulong seq=0UL; seq<req_cnt; seq++ ) req[ seq ].seq = seq - 1UL; /* Just before the next seq to be written to this entry */
43+
44+
FD_COMPILER_MFENCE();
45+
rq->magic = FD_VINYL_RQ_MAGIC;
46+
FD_COMPILER_MFENCE();
47+
48+
return rq;
49+
}
50+
51+
fd_vinyl_rq_t *
52+
fd_vinyl_rq_join( void * shrq ) {
53+
fd_vinyl_rq_t * rq = (fd_vinyl_rq_t *)shrq;
54+
55+
if( FD_UNLIKELY( !rq ) ) {
56+
FD_LOG_WARNING(( "NULL shrq"));
57+
return NULL;
58+
}
59+
60+
if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)rq, fd_vinyl_rq_align() ) ) ) {
61+
FD_LOG_WARNING(( "bad align"));
62+
return NULL;
63+
}
64+
65+
if( FD_UNLIKELY( rq->magic!=FD_VINYL_RQ_MAGIC ) ) {
66+
FD_LOG_WARNING(( "bad magic"));
67+
return NULL;
68+
}
69+
70+
return (fd_vinyl_rq_t *)shrq;
71+
}
72+
73+
void *
74+
fd_vinyl_rq_leave( fd_vinyl_rq_t * rq ) {
75+
76+
if( FD_UNLIKELY( !rq ) ) {
77+
FD_LOG_WARNING(( "NULL rq"));
78+
return NULL;
79+
}
80+
81+
return rq;
82+
}
83+
84+
void *
85+
fd_vinyl_rq_delete( void * shrq ) {
86+
fd_vinyl_rq_t * rq = (fd_vinyl_rq_t *)shrq;
87+
88+
if( FD_UNLIKELY( !rq ) ) {
89+
FD_LOG_WARNING(( "NULL shrq"));
90+
return NULL;
91+
}
92+
93+
if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)rq, fd_vinyl_rq_align() ) ) ) {
94+
FD_LOG_WARNING(( "bad align"));
95+
return NULL;
96+
}
97+
98+
if( FD_UNLIKELY( rq->magic!=FD_VINYL_RQ_MAGIC ) ) {
99+
FD_LOG_WARNING(( "bad magic"));
100+
return NULL;
101+
}
102+
103+
FD_COMPILER_MFENCE();
104+
rq->magic = 0UL;
105+
FD_COMPILER_MFENCE();
106+
107+
return rq;
108+
}

0 commit comments

Comments
 (0)