File tree 2 files changed +14
-15
lines changed
2 files changed +14
-15
lines changed Original file line number Diff line number Diff line change @@ -183,18 +183,12 @@ register_worker(ringbuf_t *rbuf, unsigned registration_type)
183
183
if (!atomic_compare_exchange_weak (& w -> registered , not_registered , being_registered ))
184
184
continue ;
185
185
acquired = true;
186
+ w -> seen_off = RBUF_OFF_MAX ;
187
+ atomic_thread_fence (memory_order_release );
188
+ w -> registered = registration_type ;
186
189
187
- /* Swap the indexes to exclusively acquire the worker-record. */
188
- if (atomic_compare_exchange_weak (p_free_worker , prev_free_worker , new_free_worker )) {
189
- w -> seen_off = RBUF_OFF_MAX ;
190
- atomic_thread_fence (memory_order_release );
191
- w -> registered = registration_type ;
192
- break ;
193
- }
194
-
195
- /* The worker-record was not successfully acquired. */
196
- w -> registered = not_registered ;
197
- acquired = false;
190
+ /* Advance the index if no one else has. */
191
+ atomic_compare_exchange_weak (p_free_worker , prev_free_worker , new_free_worker );
198
192
}
199
193
}
200
194
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ ringbuf_stress(void *arg)
106
106
w = ringbuf_register (ringbuf );
107
107
assert (w != NULL );
108
108
}
109
- uint64_t total_recv = 0 ;
109
+ uint64_t total_xmit = 0 , total_not_xmit = 0 ;
110
110
111
111
/*
112
112
* There are NCPU threads concurrently generating and producing
@@ -125,7 +125,7 @@ ringbuf_stress(void *arg)
125
125
126
126
if (id == 0 ) {
127
127
if ((len = ringbuf_consume (ringbuf , & off )) != 0 ) {
128
- total_recv += len ;
128
+ total_xmit += len ;
129
129
size_t rem = len ;
130
130
assert (off < RBUF_SIZE );
131
131
while (rem ) {
@@ -140,15 +140,20 @@ ringbuf_stress(void *arg)
140
140
}
141
141
len = generate_message (buf , sizeof (buf ) - 1 );
142
142
if ((ret = ringbuf_acquire (ringbuf , & w , len )) != -1 ) {
143
+ total_xmit += len ;
143
144
off = (size_t )ret ;
144
145
assert (off < RBUF_SIZE );
145
146
memcpy (& rbuf [off ], buf , len );
146
147
ringbuf_produce (ringbuf , & w );
147
- }
148
+ } else
149
+ total_not_xmit += len ;
148
150
}
149
151
pthread_barrier_wait (& barrier );
150
152
if (id == 0 )
151
- printf ("Total received: %" PRIu64 "\n" , total_recv );
153
+ printf ("Thread 0: received %" PRIu64 "\n" , total_xmit );
154
+ else
155
+ printf ("Thread %d: sent %" PRIu64 ", unsent %" PRIu64 "\n" ,
156
+ id , total_xmit , total_not_xmit );
152
157
pthread_exit (NULL );
153
158
return NULL ;
154
159
}
You can’t perform that action at this time.
0 commit comments