Skip to content

Commit 9177a66

Browse files
fix
1 parent 1b75d0e commit 9177a66

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/funkier/fd_funkier_rec.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,20 @@ fd_funkier_rec_publish( fd_funkier_rec_prepare_t * prepare ) {
247247
FD_COMPILER_MFENCE(); /* TODO: maybe not necessary */
248248
}
249249

250+
/* We need to hold the pool lock whilst inserting and removing from the map, to make the updates
251+
to the prev_idx/next_idx pointers atomic. */
250252
fd_funkier_rec_pool_lock( &rec_pool, 1 );
251253
rec->prev_idx = rec_prev_idx;
252254
if( fd_funkier_rec_idx_is_null( rec_prev_idx ) ) {
253255
*rec_head_idx = rec_idx;
254256
} else {
255257
rec_pool.ele[ rec_prev_idx ].next_idx = rec_idx;
256258
}
257-
fd_funkier_rec_pool_unlock( &rec_pool );
258259

259260
if( fd_funkier_rec_map_insert( &rec_map, rec, FD_MAP_FLAG_BLOCKING ) ) {
260261
FD_LOG_CRIT(( "fd_funkier_rec_map_insert failed" ));
261262
}
263+
fd_funkier_rec_pool_unlock( &rec_pool );
262264
}
263265

264266
void
@@ -328,18 +330,22 @@ fd_funkier_rec_hard_remove( fd_funkier_t * funk,
328330
}
329331
fd_funkier_rec_key_copy( pair->key, key );
330332

333+
fd_funkier_rec_pool_lock( &rec_pool, 1 );
334+
331335
fd_funkier_rec_t * rec = NULL;
332336
for(;;) {
333337
fd_funkier_rec_map_query_t rec_query[1];
334338
int err = fd_funkier_rec_map_remove( &rec_map, pair, NULL, rec_query, FD_MAP_FLAG_BLOCKING );
335339
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
336-
if( err == FD_MAP_ERR_KEY ) return;
340+
if( err == FD_MAP_ERR_KEY ) {
341+
fd_funkier_rec_pool_unlock( &rec_pool );
342+
return;
343+
}
337344
if( FD_UNLIKELY( err != FD_MAP_SUCCESS ) ) FD_LOG_CRIT(( "map corruption" ));
338345
rec = fd_funkier_rec_map_query_ele( rec_query );
339346
break;
340347
}
341348

342-
fd_funkier_rec_pool_lock( &rec_pool, 1 );
343349
ulong prev_idx = rec->prev_idx;
344350
ulong next_idx = rec->next_idx;
345351
if( txn == NULL ) {

0 commit comments

Comments
 (0)