Changeset 9bde0d5 in mainline
- Timestamp:
- 2018-07-18T19:56:43Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 42f5860
- Parents:
- 40abf56
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:47:28)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:56:43)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/rcubench/rcubench.c
r40abf56 r9bde0d5 59 59 size_t iters; 60 60 size_t nthreads; 61 futex_t done_threads; 62 63 futex_t bench_fut; 61 fibril_semaphore_t done_threads; 64 62 } bench_t; 65 63 … … 111 109 112 110 /* Signal another thread completed. */ 113 f utex_up(&bench->done_threads);111 fibril_semaphore_up(&bench->done_threads); 114 112 return EOK; 115 113 } … … 147 145 /* Wait for threads to complete. */ 148 146 for (size_t k = 0; k < bench->nthreads; ++k) { 149 f utex_down(&bench->done_threads);147 fibril_semaphore_down(&bench->done_threads); 150 148 } 151 149 } … … 202 200 } 203 201 204 futex_initialize(&bench->bench_fut, 1);205 206 202 if (0 == str_cmp(argv[1], "sys-futex")) { 207 203 bench->func = kernel_futex_bench; … … 247 243 bench_t bench; 248 244 249 f utex_initialize(&bench.done_threads, 0);245 fibril_semaphore_initialize(&bench.done_threads, 0); 250 246 251 247 if (!parse_cmd_line(argc, argv, &bench, &err)) { -
uspace/lib/c/generic/async/ports.c
r40abf56 r9bde0d5 99 99 100 100 /** Futex guarding the interface hash table. */ 101 static futex_t interface_futex = FUTEX_INITIALIZER;101 static FIBRIL_RMUTEX_INITIALIZE(interface_mutex); 102 102 static hash_table_t interface_hash_table; 103 103 … … 205 205 interface_t *interface; 206 206 207 f utex_lock(&interface_futex);207 fibril_rmutex_lock(&interface_mutex); 208 208 209 209 ht_link_t *link = hash_table_find(&interface_hash_table, &iface); … … 214 214 215 215 if (!interface) { 216 f utex_unlock(&interface_futex);216 fibril_rmutex_unlock(&interface_mutex); 217 217 return ENOMEM; 218 218 } … … 220 220 port_t *port = async_new_port(interface, handler, data); 221 221 if (!port) { 222 f utex_unlock(&interface_futex);222 fibril_rmutex_unlock(&interface_mutex); 223 223 return ENOMEM; 224 224 } … … 226 226 *port_id = port->id; 227 227 228 f utex_unlock(&interface_futex);228 fibril_rmutex_unlock(&interface_mutex); 229 229 230 230 return EOK; … … 252 252 port_t *port = NULL; 253 253 254 f utex_lock(&interface_futex);254 fibril_rmutex_lock(&interface_mutex); 255 255 256 256 ht_link_t *link = hash_table_find(&interface_hash_table, &iface); … … 264 264 } 265 265 266 f utex_unlock(&interface_futex);266 fibril_rmutex_unlock(&interface_mutex); 267 267 268 268 return port; -
uspace/lib/c/generic/async/server.c
r40abf56 r9bde0d5 234 234 } 235 235 236 static futex_t client_futex = FUTEX_INITIALIZER;236 static FIBRIL_RMUTEX_INITIALIZE(client_mutex); 237 237 static hash_table_t client_hash_table; 238 238 239 239 // TODO: lockfree notification_queue? 240 static futex_t notification_futex = FUTEX_INITIALIZER;240 static FIBRIL_RMUTEX_INITIALIZE(notification_mutex); 241 241 static hash_table_t notification_hash_table; 242 242 static LIST_INITIALIZE(notification_queue); … … 339 339 client_t *client = NULL; 340 340 341 f utex_lock(&client_futex);341 fibril_rmutex_lock(&client_mutex); 342 342 ht_link_t *link = hash_table_find(&client_hash_table, &client_id); 343 343 if (link) { … … 346 346 } else if (create) { 347 347 // TODO: move the malloc out of critical section 348 /* malloc() is rmutex safe. */ 348 349 client = malloc(sizeof(client_t)); 349 350 if (client) { … … 356 357 } 357 358 358 f utex_unlock(&client_futex);359 fibril_rmutex_unlock(&client_mutex); 359 360 return client; 360 361 } … … 364 365 bool destroy; 365 366 366 f utex_lock(&client_futex);367 fibril_rmutex_lock(&client_mutex); 367 368 368 369 if (atomic_predec(&client->refcnt) == 0) { … … 372 373 destroy = false; 373 374 374 f utex_unlock(&client_futex);375 fibril_rmutex_unlock(&client_mutex); 375 376 376 377 if (destroy) { … … 693 694 fibril_semaphore_down(¬ification_semaphore); 694 695 695 f utex_lock(¬ification_futex);696 fibril_rmutex_lock(¬ification_mutex); 696 697 697 698 /* … … 727 728 list_remove(¬ification->qlink); 728 729 729 f utex_unlock(¬ification_futex);730 fibril_rmutex_unlock(¬ification_mutex); 730 731 731 732 if (handler) … … 766 767 assert(call); 767 768 768 f utex_lock(¬ification_futex);769 fibril_rmutex_lock(¬ification_mutex); 769 770 770 771 notification_msg_t *m = list_pop(¬ification_freelist, … … 772 773 773 774 if (!m) { 774 f utex_unlock(¬ification_futex);775 fibril_rmutex_unlock(¬ification_mutex); 775 776 m = malloc(sizeof(notification_msg_t)); 776 777 if (!m) { … … 779 780 } 780 781 781 f utex_lock(¬ification_futex);782 fibril_rmutex_lock(¬ification_mutex); 782 783 notification_freelist_total++; 783 784 } … … 789 790 // TODO: Make sure this can't happen and turn it into assert. 790 791 notification_freelist_total--; 791 f utex_unlock(¬ification_futex);792 fibril_rmutex_unlock(¬ification_mutex); 792 793 free(m); 793 794 return; … … 804 805 list_append(¬ification->qlink, ¬ification_queue); 805 806 806 f utex_unlock(¬ification_futex);807 fibril_rmutex_unlock(¬ification_mutex); 807 808 808 809 fibril_semaphore_up(¬ification_semaphore); … … 829 830 fid_t fib = 0; 830 831 831 f utex_lock(¬ification_futex);832 fibril_rmutex_lock(¬ification_mutex); 832 833 833 834 if (notification_avail == 0) { … … 835 836 fib = fibril_create(notification_fibril_func, NULL); 836 837 if (fib == 0) { 837 f utex_unlock(¬ification_futex);838 fibril_rmutex_unlock(¬ification_mutex); 838 839 free(notification); 839 840 return NULL; … … 847 848 hash_table_insert(¬ification_hash_table, ¬ification->htlink); 848 849 849 f utex_unlock(¬ification_futex);850 fibril_rmutex_unlock(¬ification_mutex); 850 851 851 852 if (imethod == 0) { -
uspace/lib/c/generic/malloc.c
r40abf56 r9bde0d5 44 44 #include <bitops.h> 45 45 #include <mem.h> 46 #include <f utex.h>46 #include <fibril_synch.h> 47 47 #include <stdlib.h> 48 48 #include <adt/gcdlcm.h> … … 194 194 195 195 /** Futex for thread-safe heap manipulation */ 196 static futex_t malloc_futex = FUTEX_INITIALIZER;196 static FIBRIL_RMUTEX_INITIALIZE(malloc_mutex); 197 197 198 198 #define malloc_assert(expr) safe_assert(expr) 199 200 #ifdef FUTEX_UPGRADABLE201 /** True if the heap may be accessed from multiple threads. */202 static bool multithreaded = false;203 204 /** Makes accesses to the heap thread safe. */205 void malloc_enable_multithreaded(void)206 {207 multithreaded = true;208 }209 199 210 200 /** Serializes access to the heap from multiple threads. */ 211 201 static inline void heap_lock(void) 212 202 { 213 if (multithreaded) { 214 futex_down(&malloc_futex); 215 } else { 216 /* 217 * Malloc never switches fibrils while the heap is locked. 218 * Similarly, it never creates new threads from within the 219 * locked region. Therefore, if there are no other threads 220 * except this one, the whole operation will complete without 221 * any interruptions. 222 */ 223 } 203 fibril_rmutex_lock(&malloc_mutex); 224 204 } 225 205 … … 227 207 static inline void heap_unlock(void) 228 208 { 229 if (multithreaded) { 230 futex_up(&malloc_futex); 231 } else { 232 /* 233 * Malloc never switches fibrils while the heap is locked. 234 * Similarly, it never creates new threads from within the 235 * locked region. Therefore, if there are no other threads 236 * except this one, the whole operation will complete without 237 * any interruptions. 238 */ 239 } 240 } 241 242 #else 243 244 /** Makes accesses to the heap thread safe. */ 245 void malloc_enable_multithreaded(void) 246 { 247 /* No-op. Already using thread-safe heap locking operations. */ 248 } 249 250 /** Serializes access to the heap from multiple threads. */ 251 static inline void heap_lock(void) 252 { 253 futex_down(&malloc_futex); 254 } 255 256 /** Serializes access to the heap from multiple threads. */ 257 static inline void heap_unlock(void) 258 { 259 futex_up(&malloc_futex); 260 } 261 #endif 262 209 fibril_rmutex_unlock(&malloc_mutex); 210 } 263 211 264 212 /** Initialize a heap block -
uspace/lib/c/generic/thread.c
r40abf56 r9bde0d5 116 116 } 117 117 118 /* Make heap thread safe. */119 malloc_enable_multithreaded();120 121 118 fibril->arg = arg; 122 119 uarg->uspace_entry = (void *) FADDR(__thread_entry); -
uspace/lib/c/include/malloc.h
r40abf56 r9bde0d5 49 49 extern void *heap_check(void); 50 50 51 extern void malloc_enable_multithreaded(void);52 51 #endif 53 52
Note:
See TracChangeset
for help on using the changeset viewer.