Changeset 8080262 in mainline
- Timestamp:
- 2018-07-30T18:55:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2965d18
- Parents:
- b4c8a7b
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:07:46)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:55:22)
- Location:
- uspace/lib/c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async/client.c
rb4c8a7b r8080262 122 122 #include "../private/fibril.h" 123 123 124 static FIBRIL_RMUTEX_INITIALIZE(message_mutex); 125 124 126 /** Naming service session */ 125 127 async_sess_t session_ns; … … 204 206 return; 205 207 206 f utex_lock(&async_futex);208 fibril_rmutex_lock(&message_mutex); 207 209 208 210 msg->retval = IPC_GET_RETVAL(*data); … … 220 222 } 221 223 222 f utex_unlock(&async_futex);224 fibril_rmutex_unlock(&message_mutex); 223 225 } 224 226 … … 390 392 assert(!msg->forget); 391 393 392 f utex_lock(&async_futex);394 fibril_rmutex_lock(&message_mutex); 393 395 394 396 if (msg->done) { … … 399 401 } 400 402 401 f utex_unlock(&async_futex);403 fibril_rmutex_unlock(&message_mutex); 402 404 } 403 405 -
uspace/lib/c/generic/async/server.c
rb4c8a7b r8080262 111 111 #include <errno.h> 112 112 #include <sys/time.h> 113 #include <libarch/barrier.h>114 113 #include <stdbool.h> 115 114 #include <stdlib.h> … … 125 124 #define DPRINTF(...) ((void) 0) 126 125 127 /** Async framework global futex */128 futex_t async_futex = FUTEX_INITIALIZER;129 130 126 /** Call data */ 131 127 typedef struct { … … 250 246 static sysarg_t notification_avail = 0; 251 247 252 /* The remaining structures are guarded by async_futex. */ 248 static FIBRIL_RMUTEX_INITIALIZE(conn_mutex); 253 249 static hash_table_t conn_hash_table; 254 250 … … 430 426 * Remove myself from the connection hash table. 431 427 */ 432 f utex_lock(&async_futex);428 fibril_rmutex_lock(&conn_mutex); 433 429 hash_table_remove(&conn_hash_table, &(conn_key_t){ 434 430 .task_id = fibril_connection->in_task_id, 435 431 .phone_hash = fibril_connection->in_phone_hash 436 432 }); 437 f utex_unlock(&async_futex);433 fibril_rmutex_unlock(&conn_mutex); 438 434 439 435 /* … … 517 513 /* Add connection to the connection hash table */ 518 514 519 f utex_lock(&async_futex);515 fibril_rmutex_lock(&conn_mutex); 520 516 hash_table_insert(&conn_hash_table, &conn->link); 521 f utex_unlock(&async_futex);522 523 fibril_ add_ready(conn->fid);517 fibril_rmutex_unlock(&conn_mutex); 518 519 fibril_start(conn->fid); 524 520 525 521 return conn->fid; … … 618 614 assert(call); 619 615 620 f utex_lock(&async_futex);616 fibril_rmutex_lock(&conn_mutex); 621 617 622 618 ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){ … … 625 621 }); 626 622 if (!link) { 627 f utex_unlock(&async_futex);623 fibril_rmutex_unlock(&conn_mutex); 628 624 return false; 629 625 } … … 634 630 msg_t *msg = malloc(sizeof(*msg)); 635 631 if (!msg) { 636 f utex_unlock(&async_futex);632 fibril_rmutex_unlock(&conn_mutex); 637 633 return false; 638 634 } … … 644 640 conn->close_chandle = call->cap_handle; 645 641 642 fibril_rmutex_unlock(&conn_mutex); 643 646 644 /* If the connection fibril is waiting for an event, activate it */ 647 645 fibril_notify(&conn->msg_arrived); 648 649 futex_unlock(&async_futex);650 646 return true; 651 647 } … … 960 956 } 961 957 962 f utex_lock(&async_futex);958 fibril_rmutex_lock(&conn_mutex); 963 959 964 960 /* If nothing in queue, wait until something arrives */ … … 974 970 memset(call, 0, sizeof(ipc_call_t)); 975 971 IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP); 976 f utex_unlock(&async_futex);972 fibril_rmutex_unlock(&conn_mutex); 977 973 return true; 978 974 } 979 975 980 976 // TODO: replace with cvar 981 f utex_unlock(&async_futex);977 fibril_rmutex_unlock(&conn_mutex); 982 978 983 979 errno_t rc = fibril_wait_timeout(&conn->msg_arrived, expires); … … 985 981 return false; 986 982 987 f utex_lock(&async_futex);983 fibril_rmutex_lock(&conn_mutex); 988 984 } 989 985 … … 995 991 free(msg); 996 992 997 f utex_unlock(&async_futex);993 fibril_rmutex_unlock(&conn_mutex); 998 994 return true; 999 995 } -
uspace/lib/c/generic/fibril_synch.c
rb4c8a7b r8080262 53 53 static fibril_local bool deadlocked = false; 54 54 55 static futex_t fibril_synch_futex = FUTEX_INITIALIZER; 56 55 57 typedef struct { 56 58 link_t link; … … 96 98 static void check_fibril_for_deadlock(fibril_owner_info_t *oi, fibril_t *fib) 97 99 { 98 futex_assert_is_locked(& async_futex);100 futex_assert_is_locked(&fibril_synch_futex); 99 101 100 102 while (oi && oi->owned_by) { 101 103 if (oi->owned_by == fib) { 102 futex_unlock(& async_futex);104 futex_unlock(&fibril_synch_futex); 103 105 print_deadlock(oi); 104 106 abort(); … … 124 126 fibril_t *f = (fibril_t *) fibril_get_id(); 125 127 126 futex_lock(& async_futex);128 futex_lock(&fibril_synch_futex); 127 129 128 130 if (fm->counter-- > 0) { 129 131 fm->oi.owned_by = f; 130 futex_unlock(& async_futex);132 futex_unlock(&fibril_synch_futex); 131 133 return; 132 134 } … … 137 139 f->waits_for = &fm->oi; 138 140 139 futex_unlock(& async_futex);141 futex_unlock(&fibril_synch_futex); 140 142 141 143 fibril_wait_for(&wdata.event); … … 146 148 bool locked = false; 147 149 148 futex_lock(& async_futex);150 futex_lock(&fibril_synch_futex); 149 151 if (fm->counter > 0) { 150 152 fm->counter--; … … 152 154 locked = true; 153 155 } 154 futex_unlock(& async_futex);156 futex_unlock(&fibril_synch_futex); 155 157 156 158 return locked; … … 177 179 void fibril_mutex_unlock(fibril_mutex_t *fm) 178 180 { 179 futex_lock(& async_futex);181 futex_lock(&fibril_synch_futex); 180 182 _fibril_mutex_unlock_unsafe(fm); 181 futex_unlock(& async_futex);183 futex_unlock(&fibril_synch_futex); 182 184 } 183 185 184 186 bool fibril_mutex_is_locked(fibril_mutex_t *fm) 185 187 { 186 futex_lock(& async_futex);188 futex_lock(&fibril_synch_futex); 187 189 bool locked = (fm->oi.owned_by == (fibril_t *) fibril_get_id()); 188 futex_unlock(& async_futex);190 futex_unlock(&fibril_synch_futex); 189 191 return locked; 190 192 } … … 202 204 fibril_t *f = (fibril_t *) fibril_get_id(); 203 205 204 futex_lock(& async_futex);206 futex_lock(&fibril_synch_futex); 205 207 206 208 if (!frw->writers) { … … 208 210 if (frw->readers++ == 0) 209 211 frw->oi.owned_by = f; 210 futex_unlock(& async_futex);212 futex_unlock(&fibril_synch_futex); 211 213 return; 212 214 } … … 219 221 f->waits_for = &frw->oi; 220 222 221 futex_unlock(& async_futex);223 futex_unlock(&fibril_synch_futex); 222 224 223 225 fibril_wait_for(&wdata.event); … … 228 230 fibril_t *f = (fibril_t *) fibril_get_id(); 229 231 230 futex_lock(& async_futex);232 futex_lock(&fibril_synch_futex); 231 233 232 234 if (!frw->writers && !frw->readers) { 233 235 frw->oi.owned_by = f; 234 236 frw->writers++; 235 futex_unlock(& async_futex);237 futex_unlock(&fibril_synch_futex); 236 238 return; 237 239 } … … 244 246 f->waits_for = &frw->oi; 245 247 246 futex_unlock(& async_futex);248 futex_unlock(&fibril_synch_futex); 247 249 248 250 fibril_wait_for(&wdata.event); … … 306 308 void fibril_rwlock_read_unlock(fibril_rwlock_t *frw) 307 309 { 308 futex_lock(& async_futex);310 futex_lock(&fibril_synch_futex); 309 311 assert(frw->readers > 0); 310 312 _fibril_rwlock_common_unlock(frw); 311 futex_unlock(& async_futex);313 futex_unlock(&fibril_synch_futex); 312 314 } 313 315 314 316 void fibril_rwlock_write_unlock(fibril_rwlock_t *frw) 315 317 { 316 futex_lock(& async_futex);318 futex_lock(&fibril_synch_futex); 317 319 assert(frw->writers == 1); 318 320 assert(frw->oi.owned_by == fibril_self()); 319 321 _fibril_rwlock_common_unlock(frw); 320 futex_unlock(& async_futex);322 futex_unlock(&fibril_synch_futex); 321 323 } 322 324 323 325 bool fibril_rwlock_is_read_locked(fibril_rwlock_t *frw) 324 326 { 325 futex_lock(& async_futex);327 futex_lock(&fibril_synch_futex); 326 328 bool locked = (frw->readers > 0); 327 futex_unlock(& async_futex);329 futex_unlock(&fibril_synch_futex); 328 330 return locked; 329 331 } … … 331 333 bool fibril_rwlock_is_write_locked(fibril_rwlock_t *frw) 332 334 { 333 futex_lock(& async_futex);335 futex_lock(&fibril_synch_futex); 334 336 assert(frw->writers <= 1); 335 337 bool locked = (frw->writers > 0) && (frw->oi.owned_by == fibril_self()); 336 futex_unlock(& async_futex);338 futex_unlock(&fibril_synch_futex); 337 339 return locked; 338 340 } … … 374 376 } 375 377 376 futex_lock(& async_futex);378 futex_lock(&fibril_synch_futex); 377 379 _fibril_mutex_unlock_unsafe(fm); 378 380 list_append(&wdata.link, &fcv->waiters); 379 futex_unlock(& async_futex);381 futex_unlock(&fibril_synch_futex); 380 382 381 383 (void) fibril_wait_timeout(&wdata.event, expires); 382 384 383 futex_lock(& async_futex);385 futex_lock(&fibril_synch_futex); 384 386 bool timed_out = link_in_use(&wdata.link); 385 387 list_remove(&wdata.link); 386 futex_unlock(& async_futex);388 futex_unlock(&fibril_synch_futex); 387 389 388 390 fibril_mutex_lock(fm); … … 398 400 void fibril_condvar_signal(fibril_condvar_t *fcv) 399 401 { 400 futex_lock(& async_futex);402 futex_lock(&fibril_synch_futex); 401 403 402 404 awaiter_t *w = list_pop(&fcv->waiters, awaiter_t, link); … … 404 406 fibril_notify(&w->event); 405 407 406 futex_unlock(& async_futex);408 futex_unlock(&fibril_synch_futex); 407 409 } 408 410 409 411 void fibril_condvar_broadcast(fibril_condvar_t *fcv) 410 412 { 411 futex_lock(& async_futex);413 futex_lock(&fibril_synch_futex); 412 414 413 415 awaiter_t *w; … … 415 417 fibril_notify(&w->event); 416 418 417 futex_unlock(& async_futex);419 futex_unlock(&fibril_synch_futex); 418 420 } 419 421 … … 644 646 void fibril_semaphore_up(fibril_semaphore_t *sem) 645 647 { 646 futex_lock(& async_futex);648 futex_lock(&fibril_synch_futex); 647 649 sem->count++; 648 650 … … 653 655 } 654 656 655 futex_unlock(& async_futex);657 futex_unlock(&fibril_synch_futex); 656 658 } 657 659 … … 665 667 void fibril_semaphore_down(fibril_semaphore_t *sem) 666 668 { 667 futex_lock(& async_futex);669 futex_lock(&fibril_synch_futex); 668 670 sem->count--; 669 671 670 672 if (sem->count >= 0) { 671 futex_unlock(& async_futex);673 futex_unlock(&fibril_synch_futex); 672 674 return; 673 675 } … … 676 678 list_append(&wdata.link, &sem->waiters); 677 679 678 futex_unlock(& async_futex);680 futex_unlock(&fibril_synch_futex); 679 681 680 682 fibril_wait_for(&wdata.event); -
uspace/lib/c/include/ipc/common.h
rb4c8a7b r8080262 53 53 } ipc_call_t; 54 54 55 extern futex_t async_futex;56 57 55 #endif 58 56
Note:
See TracChangeset
for help on using the changeset viewer.