Changes in / [e503d3a9:b14b71e] in mainline
- Location:
- uspace/lib/c
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/include/fibril.h
re503d3a9 rb14b71e 44 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 (ctx)->fp = 0; \47 46 (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \ 48 47 } while (0) … … 54 53 typedef struct { 55 54 uintptr_t sp; 56 uintptr_t fp;57 55 uintptr_t pc; 58 56 uintptr_t tls; 59 57 } context_t; 60 61 static inline uintptr_t context_get_fp(context_t *ctx)62 {63 /* On real hardware, this function returns the frame pointer. */64 return ctx->fp;65 }66 58 67 59 #endif -
uspace/lib/c/arch/amd64/include/fibril.h
re503d3a9 rb14b71e 56 56 */ 57 57 typedef struct { 58 uint64_t sp; 59 uint64_t pc; 58 uint64_t sp; 59 uint64_t pc; 60 61 uint64_t rbx; 62 uint64_t rbp; 60 63 61 uint64_t rbx; 62 uint64_t rbp; 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 63 68 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 68 69 uint64_t tls; 69 uint64_t tls; 70 70 } context_t; 71 72 static inline uintptr_t context_get_fp(context_t *ctx)73 {74 return ctx->rbp;75 }76 71 77 72 #endif -
uspace/lib/c/arch/arm32/include/fibril.h
re503d3a9 rb14b71e 86 86 } context_t; 87 87 88 static inline uintptr_t context_get_fp(context_t *ctx)89 {90 return ctx->fp;91 }92 93 88 94 89 #endif -
uspace/lib/c/arch/ia32/include/fibril.h
re503d3a9 rb14b71e 67 67 } context_t; 68 68 69 static inline uintptr_t context_get_fp(context_t *ctx)70 {71 return ctx->ebp;72 }73 74 69 #endif 75 70 -
uspace/lib/c/arch/ia64/include/fibril.h
re503d3a9 rb14b71e 130 130 } context_t; 131 131 132 static inline uintptr_t context_get_fp(context_t *ctx)133 {134 return 0; /* FIXME */135 }136 137 132 #endif 138 133 -
uspace/lib/c/arch/mips32/include/fibril.h
re503d3a9 rb14b71e 85 85 } context_t; 86 86 87 static inline uintptr_t context_get_fp(context_t *ctx)88 {89 return ctx->sp;90 }91 92 87 #endif 93 88 -
uspace/lib/c/arch/ppc32/include/fibril.h
re503d3a9 rb14b71e 78 78 } __attribute__ ((packed)) context_t; 79 79 80 static inline uintptr_t context_get_fp(context_t *ctx)81 {82 return ctx->sp;83 }84 85 80 #endif 86 81 -
uspace/lib/c/arch/sparc64/include/fibril.h
re503d3a9 rb14b71e 77 77 } context_t; 78 78 79 static inline uintptr_t context_get_fp(context_t *ctx)80 {81 return ctx->sp + STACK_BIAS;82 }83 84 79 #endif 85 80 -
uspace/lib/c/generic/fibril.c
re503d3a9 rb14b71e 275 275 fibril->func = func; 276 276 fibril->arg = arg; 277 278 fibril->waits_for = NULL;279 277 280 278 context_save(&fibril->ctx); -
uspace/lib/c/generic/fibril_synch.c
re503d3a9 rb14b71e 42 42 #include <errno.h> 43 43 #include <assert.h> 44 #include <stacktrace.h>45 #include <stdlib.h>46 44 47 45 static void optimize_execution_power(void) … … 58 56 } 59 57 60 static bool check_for_deadlock(fibril_owner_info_t *oi)61 {62 while (oi && oi->owned_by) {63 if (oi->owned_by == (fibril_t *) fibril_get_id())64 return true;65 oi = oi->owned_by->waits_for;66 }67 68 return false;69 }70 71 static void print_deadlock(fibril_owner_info_t *oi)72 {73 fibril_t *f = (fibril_t *) fibril_get_id();74 75 printf("Deadlock detected.\n");76 stacktrace_print();77 78 printf("Fibril %p waits for primitive %p.\n", f, oi);79 80 while (oi && oi->owned_by) {81 printf("Primitive %p is owned by fibril %p.\n",82 oi, oi->owned_by);83 if (oi->owned_by == f)84 break;85 stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),86 oi->owned_by->ctx.pc);87 printf("Fibril %p waits for primitive %p.\n",88 oi->owned_by, oi->owned_by->waits_for);89 oi = oi->owned_by->waits_for;90 }91 92 abort();93 }94 95 58 void fibril_mutex_initialize(fibril_mutex_t *fm) 96 59 { 97 fm->oi.owned_by = NULL;98 60 fm->counter = 1; 99 61 list_initialize(&fm->waiters); … … 102 64 void fibril_mutex_lock(fibril_mutex_t *fm) 103 65 { 104 fibril_t *f = (fibril_t *) fibril_get_id();105 106 66 futex_down(&async_futex); 107 67 if (fm->counter-- <= 0) { … … 113 73 link_initialize(&wdata.wu_event.link); 114 74 list_append(&wdata.wu_event.link, &fm->waiters); 115 116 if (check_for_deadlock(&fm->oi))117 print_deadlock(&fm->oi);118 f->waits_for = &fm->oi;119 120 75 fibril_switch(FIBRIL_TO_MANAGER); 121 76 } else { 122 fm->oi.owned_by = f;123 77 futex_up(&async_futex); 124 78 } … … 132 86 if (fm->counter > 0) { 133 87 fm->counter--; 134 fm->oi.owned_by = (fibril_t *) fibril_get_id();135 88 locked = true; 136 89 } … … 146 99 link_t *tmp; 147 100 awaiter_t *wdp; 148 fibril_t *f;149 101 150 102 assert(!list_empty(&fm->waiters)); … … 153 105 wdp->active = true; 154 106 wdp->wu_event.inlist = false; 155 156 f = (fibril_t *) wdp->fid;157 fm->oi.owned_by = f;158 f->waits_for = NULL;159 160 107 list_remove(&wdp->wu_event.link); 161 108 fibril_add_ready(wdp->fid); 162 109 optimize_execution_power(); 163 } else {164 fm->oi.owned_by = NULL;165 110 } 166 111 } … … 175 120 void fibril_rwlock_initialize(fibril_rwlock_t *frw) 176 121 { 177 frw->oi.owned_by = NULL;178 122 frw->writers = 0; 179 123 frw->readers = 0; -
uspace/lib/c/include/fibril.h
re503d3a9 rb14b71e 48 48 #define FIBRIL_WRITER 2 49 49 50 struct fibril;51 52 typedef struct {53 struct fibril *owned_by;54 } fibril_owner_info_t;55 56 50 typedef enum { 57 51 FIBRIL_PREEMPT, … … 74 68 int retval; 75 69 int flags; 76 77 fibril_owner_info_t *waits_for;78 70 } fibril_t; 79 71 -
uspace/lib/c/include/fibril_synch.h
re503d3a9 rb14b71e 43 43 44 44 typedef struct { 45 fibril_owner_info_t oi; /* Keep this the first thing. */46 45 int counter; 47 46 link_t waiters; … … 50 49 #define FIBRIL_MUTEX_INITIALIZER(name) \ 51 50 { \ 52 .oi = { \53 .owned_by = NULL \54 }, \55 51 .counter = 1, \ 56 52 .waiters = { \ … … 64 60 65 61 typedef struct { 66 fibril_owner_info_t oi; /* Keep this the first thing. */67 62 unsigned writers; 68 63 unsigned readers; … … 72 67 #define FIBRIL_RWLOCK_INITIALIZER(name) \ 73 68 { \ 74 .oi = { \75 .owned_by = NULL \76 }, \77 69 .readers = 0, \ 78 70 .writers = 0, \
Note:
See TracChangeset
for help on using the changeset viewer.