File tree 6 files changed +24
-24
lines changed
6 files changed +24
-24
lines changed Original file line number Diff line number Diff line change @@ -350,19 +350,19 @@ namespace sf {
350
350
351
351
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
352
352
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
353
- // get thread index - in any cases
354
- auto it = thread_local_index_hashmap.find (this );
353
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
354
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
355
355
if (it != thread_local_index_hashmap.cend ())
356
356
set_index = it->second .thread_index ;
357
357
358
358
if (index_op == unregister_thread_op) { // unregister thread
359
359
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
360
- thread_local_index_hashmap.erase (this );
360
+ thread_local_index_hashmap.erase (&shared_locks_array );
361
361
else
362
362
return -1 ;
363
363
}
364
364
else if (index_op == register_thread_op) { // register thread
365
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
365
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
366
366
367
367
// remove info about deleted contfree-mutexes
368
368
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
Original file line number Diff line number Diff line change @@ -350,19 +350,19 @@ namespace sf {
350
350
351
351
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
352
352
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
353
- // get thread index - in any cases
354
- auto it = thread_local_index_hashmap.find (this );
353
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
354
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
355
355
if (it != thread_local_index_hashmap.cend ())
356
356
set_index = it->second .thread_index ;
357
357
358
358
if (index_op == unregister_thread_op) { // unregister thread
359
359
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
360
- thread_local_index_hashmap.erase (this );
360
+ thread_local_index_hashmap.erase (&shared_locks_array );
361
361
else
362
362
return -1 ;
363
363
}
364
364
else if (index_op == register_thread_op) { // register thread
365
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
365
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
366
366
367
367
// remove info about deleted contfree-mutexes
368
368
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
Original file line number Diff line number Diff line change @@ -235,19 +235,19 @@ class contention_free_shared_mutex {
235
235
236
236
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
237
237
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
238
- // get thread index - in any cases
239
- auto it = thread_local_index_hashmap.find (this );
238
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
239
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
240
240
if (it != thread_local_index_hashmap.cend ())
241
241
set_index = it->second .thread_index ;
242
242
243
243
if (index_op == unregister_thread_op) { // unregister thread
244
244
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
245
- thread_local_index_hashmap.erase (this );
245
+ thread_local_index_hashmap.erase (&shared_locks_array );
246
246
else
247
247
return -1 ;
248
248
}
249
249
else if (index_op == register_thread_op) { // register thread
250
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
250
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
251
251
252
252
// remove info about deleted contfree-mutexes
253
253
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
Original file line number Diff line number Diff line change @@ -331,19 +331,19 @@ class contention_free_shared_mutex {
331
331
332
332
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
333
333
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
334
- // get thread index - in any cases
335
- auto it = thread_local_index_hashmap.find (this );
334
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
335
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
336
336
if (it != thread_local_index_hashmap.cend ())
337
337
set_index = it->second .thread_index ;
338
338
339
339
if (index_op == unregister_thread_op) { // unregister thread
340
340
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
341
- thread_local_index_hashmap.erase (this );
341
+ thread_local_index_hashmap.erase (&shared_locks_array );
342
342
else
343
343
return -1 ;
344
344
}
345
345
else if (index_op == register_thread_op) { // register thread
346
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
346
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
347
347
348
348
// remove info about deleted contfree-mutexes
349
349
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
Original file line number Diff line number Diff line change @@ -93,19 +93,19 @@ namespace sf {
93
93
94
94
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
95
95
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
96
- // get thread index - in any cases
97
- auto it = thread_local_index_hashmap.find (this );
96
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
97
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
98
98
if (it != thread_local_index_hashmap.cend ())
99
99
set_index = it->second .thread_index ;
100
100
101
101
if (index_op == unregister_thread_op) { // unregister thread
102
102
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
103
- thread_local_index_hashmap.erase (this );
103
+ thread_local_index_hashmap.erase (&shared_locks_array );
104
104
else
105
105
return -1 ;
106
106
}
107
107
else if (index_op == register_thread_op) { // register thread
108
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
108
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
109
109
110
110
// remove info about deleted contfree-mutexes
111
111
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
Original file line number Diff line number Diff line change @@ -350,19 +350,19 @@ namespace sf {
350
350
351
351
int get_or_set_index (index_op_t index_op = get_index_op, int set_index = -1 ) {
352
352
thread_local static std::unordered_map<void *, unregister_t > thread_local_index_hashmap;
353
- // get thread index - in any cases
354
- auto it = thread_local_index_hashmap.find (this );
353
+ // get thread index - in any cases. Use &shared_locks_array as key ("this" may get recycled if contfree-mtx under "it" was deleted)
354
+ auto it = thread_local_index_hashmap.find (&shared_locks_array );
355
355
if (it != thread_local_index_hashmap.cend ())
356
356
set_index = it->second .thread_index ;
357
357
358
358
if (index_op == unregister_thread_op) { // unregister thread
359
359
if (shared_locks_array[set_index].value == 1 ) // if isn't shared_lock now
360
- thread_local_index_hashmap.erase (this );
360
+ thread_local_index_hashmap.erase (&shared_locks_array );
361
361
else
362
362
return -1 ;
363
363
}
364
364
else if (index_op == register_thread_op) { // register thread
365
- thread_local_index_hashmap.emplace (this , unregister_t (set_index, shared_locks_array_ptr));
365
+ thread_local_index_hashmap.emplace (&shared_locks_array , unregister_t (set_index, shared_locks_array_ptr));
366
366
367
367
// remove info about deleted contfree-mutexes
368
368
for (auto it = thread_local_index_hashmap.begin (), ite = thread_local_index_hashmap.end (); it != ite;) {
You can’t perform that action at this time.
0 commit comments