8
8
/* A shared stream has a single producer and multiple consumers.
9
9
fd_stream_writer implements the producer APIs of the shared stream */
10
10
struct fd_stream_writer {
11
+ ulong magic ; /* magic */
11
12
fd_stream_frag_meta_t * out_mcache ; /* frag producer mcache */
12
13
13
- uchar * buf ; /* laddr of shared dcache buffer */
14
- ulong buf_base ; /* offset to the dcache buffer from wksp */
14
+ uchar * dcache ; /* laddr of shared dcache buffer */
15
+ ulong base ; /* offset to the dcache buffer from wksp */
15
16
16
17
/* dcache buffer state */
17
18
ulong buf_off ; /* local write offset into dcache buffer */
18
19
ulong buf_sz ; /* dcache buffer size */
19
20
ulong goff ; /* global offset into byte stream */
20
- ulong read_max ; /* max chunk size */
21
+ ulong frag_sz_max ; /* max frag size (controls the size of a single write into dcache) */
21
22
ulong stream_off ; /* start of published stream */
22
23
ulong goff_start ; /* start of goff in stream */
23
24
ulong out_seq ; /* current sequence number */
@@ -36,6 +37,7 @@ struct fd_stream_writer {
36
37
};
37
38
typedef struct fd_stream_writer fd_stream_writer_t ;
38
39
40
+ #define FD_STREAM_WRITER_MAGIC (0xFD57337717E736C0UL)
39
41
#define EXPECTED_FSEQ_CNT_PER_CONS 2
40
42
41
43
FD_PROTOTYPES_BEGIN
@@ -50,9 +52,19 @@ fd_stream_writer_footprint( void ) {
50
52
return sizeof (fd_stream_writer_t );
51
53
}
52
54
55
+ static inline fd_stream_writer_t *
56
+ fd_stream_writer_join ( void * _writer ) {
57
+ fd_stream_writer_t * writer = (fd_stream_writer_t * )_writer ;
58
+ if ( FD_UNLIKELY ( !writer ) ) return NULL ;
59
+ if ( FD_UNLIKELY ( !fd_ulong_is_aligned ( (ulong )writer , fd_stream_writer_align () ) ) ) return NULL ;
60
+ if ( FD_UNLIKELY ( writer -> magic != FD_STREAM_WRITER_MAGIC ) ) return NULL ;
61
+
62
+ return writer ;
63
+ }
64
+
53
65
static inline uchar *
54
66
fd_stream_writer_get_write_ptr ( fd_stream_writer_t * writer ) {
55
- return writer -> buf + writer -> buf_off ;
67
+ return writer -> dcache + writer -> buf_off ;
56
68
}
57
69
58
70
fd_stream_writer_t *
@@ -72,9 +84,9 @@ fd_stream_writer_init_flow_control_credits( fd_stream_writer_t * writer ) {
72
84
}
73
85
74
86
static inline void
75
- fd_stream_writer_set_read_max ( fd_stream_writer_t * writer ,
76
- ulong read_max ) {
77
- writer -> read_max = read_max ;
87
+ fd_stream_writer_set_frag_sz_max ( fd_stream_writer_t * writer ,
88
+ ulong frag_sz_max ) {
89
+ writer -> frag_sz_max = frag_sz_max ;
78
90
}
79
91
80
92
static inline void
@@ -113,14 +125,14 @@ fd_stream_writer_get_avail_bytes( fd_stream_writer_t * writer ) {
113
125
return 0 ;
114
126
}
115
127
116
- ulong const read_max = fd_ulong_min ( writer -> cr_byte_avail , writer -> read_max );
117
- return fd_ulong_min ( read_max , writer -> buf_sz - writer -> buf_off );
128
+ ulong const frag_sz_max = fd_ulong_min ( writer -> cr_byte_avail , writer -> frag_sz_max );
129
+ return fd_ulong_min ( frag_sz_max , writer -> buf_sz - writer -> buf_off );
118
130
}
119
131
120
132
static inline void
121
133
fd_stream_writer_publish ( fd_stream_writer_t * writer ,
122
134
ulong frag_sz ) {
123
- ulong loff = writer -> buf_base + writer -> stream_off ;
135
+ ulong loff = writer -> base + writer -> stream_off ;
124
136
fd_mcache_publish_stream ( writer -> out_mcache ,
125
137
fd_mcache_depth ( writer -> out_mcache -> f ),
126
138
writer -> out_seq ,
0 commit comments