Changeset 42f5860 in mainline
- Timestamp:
- 2018-07-18T19:56:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9d8307a
- Parents:
- 9bde0d5
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-13 23:13:27)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:56:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/rcu.c
r9bde0d5 r42f5860 105 105 size_t cur_gp; 106 106 size_t reader_group; 107 f utex_t list_futex;107 fibril_rmutex_t list_mutex; 108 108 list_t fibrils_list; 109 109 struct { 110 f utex_t futex;110 fibril_rmutex_t mutex; 111 111 bool locked; 112 112 list_t blocked_fibrils; 113 size_t blocked_thread_cnt;114 futex_t futex_blocking_threads;115 113 } sync_lock; 116 114 } rcu_data_t; … … 137 135 .cur_gp = 0, 138 136 .reader_group = RCU_GROUP_A, 139 .list_ futex = FUTEX_INITIALIZER,137 .list_mutex = FIBRIL_RMUTEX_INITIALIZER(rcu.list_mutex), 140 138 .fibrils_list = LIST_INITIALIZER(rcu.fibrils_list), 141 139 .sync_lock = { 142 . futex = FUTEX_INITIALIZER,140 .mutex = FIBRIL_RMUTEX_INITIALIZER(rcu.sync_lock.mutex), 143 141 .locked = false, 144 142 .blocked_fibrils = LIST_INITIALIZER(rcu.sync_lock.blocked_fibrils), 145 .blocked_thread_cnt = 0,146 .futex_blocking_threads = FUTEX_INITIALIZE(0),147 143 }, 148 144 }; … … 171 167 assert(!fibril_rcu.registered); 172 168 173 f utex_lock(&rcu.list_futex);169 fibril_rmutex_lock(&rcu.list_mutex); 174 170 list_append(&fibril_rcu.link, &rcu.fibrils_list); 175 f utex_unlock(&rcu.list_futex);171 fibril_rmutex_unlock(&rcu.list_mutex); 176 172 177 173 fibril_rcu.registered = true; … … 196 192 fibril_rcu.nesting_cnt = 0; 197 193 198 f utex_lock(&rcu.list_futex);194 fibril_rmutex_lock(&rcu.list_mutex); 199 195 list_remove(&fibril_rcu.link); 200 f utex_unlock(&rcu.list_futex);196 fibril_rmutex_unlock(&rcu.list_mutex); 201 197 202 198 fibril_rcu.registered = false; … … 333 329 static void wait_for_readers(size_t reader_group) 334 330 { 335 f utex_lock(&rcu.list_futex);331 fibril_rmutex_lock(&rcu.list_mutex); 336 332 337 333 list_t quiescent_fibrils; … … 344 340 345 341 if (is_preexisting_reader(fib, reader_group)) { 346 f utex_unlock(&rcu.list_futex);342 fibril_rmutex_unlock(&rcu.list_mutex); 347 343 sync_sleep(); 348 f utex_lock(&rcu.list_futex);344 fibril_rmutex_lock(&rcu.list_mutex); 349 345 /* Break to while loop. */ 350 346 break; … … 357 353 358 354 list_concat(&rcu.fibrils_list, &quiescent_fibrils); 359 f utex_unlock(&rcu.list_futex);355 fibril_rmutex_unlock(&rcu.list_mutex); 360 356 } 361 357 362 358 static void lock_sync(void) 363 359 { 364 f utex_lock(&rcu.sync_lock.futex);360 fibril_rmutex_lock(&rcu.sync_lock.mutex); 365 361 if (rcu.sync_lock.locked) { 366 362 blocked_fibril_t blocked_fib; … … 371 367 do { 372 368 blocked_fib.is_ready = false; 373 f utex_unlock(&rcu.sync_lock.futex);369 fibril_rmutex_unlock(&rcu.sync_lock.mutex); 374 370 futex_lock(&async_futex); 375 371 fibril_switch(FIBRIL_FROM_BLOCKED); 376 372 futex_unlock(&async_futex); 377 f utex_lock(&rcu.sync_lock.futex);373 fibril_rmutex_lock(&rcu.sync_lock.mutex); 378 374 } while (rcu.sync_lock.locked); 379 375 … … 389 385 assert(rcu.sync_lock.locked); 390 386 391 /* 392 * Blocked threads have a priority over fibrils when accessing sync(). 393 * Pass the lock onto a waiting thread. 394 */ 395 if (0 < rcu.sync_lock.blocked_thread_cnt) { 396 --rcu.sync_lock.blocked_thread_cnt; 397 futex_unlock(&rcu.sync_lock.futex_blocking_threads); 398 } else { 399 /* Unlock but wake up any fibrils waiting for the lock. */ 400 401 if (!list_empty(&rcu.sync_lock.blocked_fibrils)) { 402 blocked_fibril_t *blocked_fib = member_to_inst( 403 list_first(&rcu.sync_lock.blocked_fibrils), blocked_fibril_t, link); 404 405 if (!blocked_fib->is_ready) { 406 blocked_fib->is_ready = true; 407 fibril_add_ready(blocked_fib->id); 408 } 387 /* Unlock but wake up any fibrils waiting for the lock. */ 388 389 if (!list_empty(&rcu.sync_lock.blocked_fibrils)) { 390 blocked_fibril_t *blocked_fib = member_to_inst( 391 list_first(&rcu.sync_lock.blocked_fibrils), blocked_fibril_t, link); 392 393 if (!blocked_fib->is_ready) { 394 blocked_fib->is_ready = true; 395 fibril_add_ready(blocked_fib->id); 409 396 } 410 411 rcu.sync_lock.locked = false;412 futex_unlock(&rcu.sync_lock.futex);413 397 } 398 399 rcu.sync_lock.locked = false; 400 fibril_rmutex_unlock(&rcu.sync_lock.mutex); 414 401 } 415 402 … … 421 408 * but keep sync locked. 422 409 */ 423 f utex_unlock(&rcu.sync_lock.futex);410 fibril_rmutex_unlock(&rcu.sync_lock.mutex); 424 411 fibril_usleep(RCU_SLEEP_MS * 1000); 425 f utex_lock(&rcu.sync_lock.futex);412 fibril_rmutex_lock(&rcu.sync_lock.mutex); 426 413 } 427 414
Note:
See TracChangeset
for help on using the changeset viewer.