Changeset 2965d18 in mainline
- Timestamp:
- 2018-07-30T20:15:38Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d4b7b29
- Parents:
- 8080262
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 19:53:13)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 20:15:38)
- Location:
- uspace/lib/c
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril.c
r8080262 r2965d18 476 476 static void _fibril_switch_to(_switch_type_t type, fibril_t *dstf, bool locked) 477 477 { 478 assert(fibril_self()->rmutex_locks == 0); 479 478 480 if (!locked) 479 481 futex_lock(&fibril_futex); … … 633 635 errno_t fibril_wait_timeout(fibril_event_t *event, const struct timeval *expires) 634 636 { 637 assert(fibril_self()->rmutex_locks == 0); 638 635 639 DPRINTF("### Fibril %p sleeping on event %p.\n", fibril_self(), event); 636 640 … … 713 717 void fibril_wait_for(fibril_event_t *event) 714 718 { 719 assert(fibril_self()->rmutex_locks == 0); 720 715 721 (void) fibril_wait_timeout(event, NULL); 716 722 } … … 769 775 void fibril_yield(void) 770 776 { 777 if (fibril_self()->rmutex_locks > 0) 778 return; 779 771 780 fibril_t *f = _ready_list_pop_nonblocking(false); 772 781 if (f) … … 789 798 int fibril_test_spawn_runners(int n) 790 799 { 800 assert(fibril_self()->rmutex_locks == 0); 801 791 802 if (!multithreaded) { 792 803 _ready_debug_check(); -
uspace/lib/c/generic/fibril_synch.c
r8080262 r2965d18 50 50 #include "private/async.h" 51 51 #include "private/fibril.h" 52 53 void fibril_rmutex_initialize(fibril_rmutex_t *m) 54 { 55 futex_initialize(&m->futex, 1); 56 } 57 58 /** 59 * Lock restricted mutex. 60 * When a restricted mutex is locked, the fibril may not sleep or create new 61 * threads. Any attempt to do so will abort the program. 62 */ 63 void fibril_rmutex_lock(fibril_rmutex_t *m) 64 { 65 futex_lock(&m->futex); 66 fibril_self()->rmutex_locks++; 67 } 68 69 bool fibril_rmutex_trylock(fibril_rmutex_t *m) 70 { 71 if (futex_trylock(&m->futex)) { 72 fibril_self()->rmutex_locks++; 73 return true; 74 } else { 75 return false; 76 } 77 } 78 79 void fibril_rmutex_unlock(fibril_rmutex_t *m) 80 { 81 fibril_self()->rmutex_locks--; 82 futex_unlock(&m->futex); 83 } 52 84 53 85 static fibril_local bool deadlocked = false; -
uspace/lib/c/generic/futex.c
r8080262 r2965d18 43 43 44 44 //#define DPRINTF(...) kio_printf(__VA_ARGS__) 45 #define DPRINTF(...) ((void)0)45 #define DPRINTF(...) dummy_printf(__VA_ARGS__) 46 46 47 47 /** Initialize futex counter. … … 84 84 * They should compile to regular load/stores, but simple assignments 85 85 * would be UB by definition. 86 * The proper ordering is ensured by the surrounding futex operation. 86 87 */ 87 88 … … 94 95 assert(prev_owner == NULL); 95 96 __atomic_store_n(&futex->owner, self, __ATOMIC_RELAXED); 96 97 atomic_inc(&self->futex_locks);98 97 } 99 98 … … 104 103 __futex_assert_is_locked(futex, name); 105 104 __atomic_store_n(&futex->owner, NULL, __ATOMIC_RELAXED); 106 atomic_dec(&self->futex_locks);107 105 futex_up(futex); 108 106 } … … 117 115 118 116 __atomic_store_n(&futex->owner, self, __ATOMIC_RELAXED); 119 120 atomic_inc(&self->futex_locks);121 117 122 118 DPRINTF("Trylock on futex %s (%p) by fibril %p succeeded.\n", name, futex, self); … … 135 131 136 132 __futex_assert_is_locked(futex, name); 137 atomic_dec(&self->futex_locks);138 atomic_inc(&no->futex_locks);139 133 __atomic_store_n(&futex->owner, new_owner, __ATOMIC_RELAXED); 140 134 } -
uspace/lib/c/generic/private/fibril.h
r8080262 r2965d18 61 61 62 62 /* Debugging stuff. */ 63 atomic_t futex_locks;63 int rmutex_locks; 64 64 fibril_owner_info_t *waits_for; 65 65 fibril_event_t *sleep_event; -
uspace/lib/c/include/fibril_synch.h
r8080262 r2965d18 80 80 #define FIBRIL_RMUTEX_INITIALIZE(name) \ 81 81 fibril_rmutex_t name = FIBRIL_RMUTEX_INITIALIZER(name) 82 83 static inline void fibril_rmutex_initialize(fibril_rmutex_t *m)84 {85 futex_initialize(&m->futex, 1);86 }87 88 static inline void fibril_rmutex_lock(fibril_rmutex_t *m)89 {90 futex_lock(&m->futex);91 }92 93 static inline bool fibril_rmutex_trylock(fibril_rmutex_t *m)94 {95 return futex_trylock(&m->futex);96 }97 98 static inline void fibril_rmutex_unlock(fibril_rmutex_t *m)99 {100 futex_unlock(&m->futex);101 }102 82 103 83 typedef struct { … … 222 202 fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt) 223 203 204 extern void fibril_rmutex_initialize(fibril_rmutex_t *); 205 extern void fibril_rmutex_lock(fibril_rmutex_t *); 206 extern bool fibril_rmutex_trylock(fibril_rmutex_t *); 207 extern void fibril_rmutex_unlock(fibril_rmutex_t *); 208 224 209 extern void fibril_mutex_initialize(fibril_mutex_t *); 225 210 extern void fibril_mutex_lock(fibril_mutex_t *); -
uspace/lib/c/include/io/kio.h
r8080262 r2965d18 49 49 extern int kio_vprintf(const char *, va_list); 50 50 51 /* 52 * In some files, we have conditional DPRINTF(...) macro that is defined empty 53 * in most cases. Provide a dummy printf so we get argument checking and 54 * avoid unused variable errors. 55 */ 56 57 static inline int dummy_printf(const char *fmt, ...) _HELENOS_PRINTF_ATTRIBUTE(1, 2); 58 static inline int dummy_printf(const char *fmt, ...) 59 { 60 /* Empty. */ 61 (void) fmt; 62 return 0; 63 } 64 51 65 #endif 52 66
Note:
See TracChangeset
for help on using the changeset viewer.