Changeset 508b0df1 in mainline for uspace/lib/c/generic/thread
- Timestamp:
- 2018-09-06T20:21:52Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 78de83de, fc10e1b
- Parents:
- 4621d23
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-13 03:53:39)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-06 20:21:52)
- Location:
- uspace/lib/c/generic/thread
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/thread/fibril.c
r4621d23 r508b0df1 88 88 /* This futex serializes access to global data. */ 89 89 static futex_t fibril_futex = FUTEX_INITIALIZER; 90 static futex_t ready_semaphore = FUTEX_INITIALIZE(0);90 static futex_t ready_semaphore; 91 91 static long ready_st_count; 92 92 … … 117 117 } 118 118 119 static inline long _ready_count(void)120 {121 /*122 * The number of available tokens is always equal to the number123 * of fibrils in the ready list + the number of free IPC buffer124 * buckets.125 */126 127 if (multithreaded)128 return atomic_get(&ready_semaphore.val);129 130 _ready_debug_check();131 return ready_st_count;132 }133 134 119 static inline void _ready_up(void) 135 120 { … … 152 137 } 153 138 154 static atomic_ t threads_in_ipc_wait = { 0 };139 static atomic_int threads_in_ipc_wait; 155 140 156 141 /** Function that spans the whole life-cycle of a fibril. … … 303 288 fibril_t *f = list_pop(&ready_list, fibril_t, link); 304 289 if (!f) 305 atomic_inc(&threads_in_ipc_wait); 290 atomic_fetch_add_explicit(&threads_in_ipc_wait, 1, 291 memory_order_relaxed); 306 292 if (!locked) 307 293 futex_unlock(&fibril_futex); … … 317 303 rc = _ipc_wait(&call, expires); 318 304 319 atomic_dec(&threads_in_ipc_wait); 305 atomic_fetch_sub_explicit(&threads_in_ipc_wait, 1, 306 memory_order_relaxed); 320 307 321 308 if (rc != EOK && rc != ENOENT) { … … 386 373 _ready_up(); 387 374 388 if (atomic_ get(&threads_in_ipc_wait)) {375 if (atomic_load_explicit(&threads_in_ipc_wait, memory_order_relaxed)) { 389 376 DPRINTF("Poking.\n"); 390 377 /* Wakeup one thread sleeping in SYS_IPC_WAIT. */ … … 811 798 if (!multithreaded) { 812 799 _ready_debug_check(); 813 atomic_set(&ready_semaphore.val, ready_st_count);800 futex_initialize(&ready_semaphore, ready_st_count); 814 801 multithreaded = true; 815 802 } -
uspace/lib/c/generic/thread/futex.c
r4621d23 r508b0df1 34 34 35 35 #include <assert.h> 36 #include < atomic.h>36 #include <stdatomic.h> 37 37 #include <fibril.h> 38 38 #include <io/kio.h> … … 52 52 void futex_initialize(futex_t *futex, int val) 53 53 { 54 atomic_s et(&futex->val, val);54 atomic_store_explicit(&futex->val, val, memory_order_relaxed); 55 55 } 56 56 … … 59 59 void __futex_assert_is_locked(futex_t *futex, const char *name) 60 60 { 61 void *owner = __atomic_load_n(&futex->owner, __ATOMIC_RELAXED);61 void *owner = atomic_load_explicit(&futex->owner, memory_order_relaxed); 62 62 fibril_t *self = (fibril_t *) fibril_get_id(); 63 63 if (owner != self) { … … 69 69 void __futex_assert_is_not_locked(futex_t *futex, const char *name) 70 70 { 71 void *owner = __atomic_load_n(&futex->owner, __ATOMIC_RELAXED);71 void *owner = atomic_load_explicit(&futex->owner, memory_order_relaxed); 72 72 fibril_t *self = (fibril_t *) fibril_get_id(); 73 73 if (owner == self) { … … 91 91 futex_down(futex); 92 92 93 void *prev_owner = __atomic_load_n(&futex->owner, __ATOMIC_RELAXED); 93 void *prev_owner = atomic_load_explicit(&futex->owner, 94 memory_order_relaxed); 94 95 assert(prev_owner == NULL); 95 __atomic_store_n(&futex->owner, self, __ATOMIC_RELAXED);96 atomic_store_explicit(&futex->owner, self, memory_order_relaxed); 96 97 } 97 98 … … 101 102 DPRINTF("Unlocking futex %s (%p) by fibril %p.\n", name, futex, self); 102 103 __futex_assert_is_locked(futex, name); 103 __atomic_store_n(&futex->owner, NULL, __ATOMIC_RELAXED);104 atomic_store_explicit(&futex->owner, NULL, memory_order_relaxed); 104 105 futex_up(futex); 105 106 } … … 110 111 bool success = futex_trydown(futex); 111 112 if (success) { 112 void *owner = __atomic_load_n(&futex->owner, __ATOMIC_RELAXED); 113 void *owner = atomic_load_explicit(&futex->owner, 114 memory_order_relaxed); 113 115 assert(owner == NULL); 114 116 115 __atomic_store_n(&futex->owner, self, __ATOMIC_RELAXED);117 atomic_store_explicit(&futex->owner, self, memory_order_relaxed); 116 118 117 119 DPRINTF("Trylock on futex %s (%p) by fibril %p succeeded.\n", name, futex, self); … … 130 132 131 133 __futex_assert_is_locked(futex, name); 132 __atomic_store_n(&futex->owner, new_owner, __ATOMIC_RELAXED);134 atomic_store_explicit(&futex->owner, new_owner, memory_order_relaxed); 133 135 } 134 136
Note:
See TracChangeset
for help on using the changeset viewer.