Changeset e503d3a9 in mainline
- Timestamp:
- 2010-10-25T21:33:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e7f6389
- Parents:
- b14b71e (diff), 84b7384 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/c
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/include/fibril.h
rb14b71e re503d3a9 44 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 (ctx)->fp = 0; \ 46 47 (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \ 47 48 } while (0) … … 53 54 typedef struct { 54 55 uintptr_t sp; 56 uintptr_t fp; 55 57 uintptr_t pc; 56 58 uintptr_t tls; 57 59 } 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 } 58 66 59 67 #endif -
uspace/lib/c/arch/amd64/include/fibril.h
rb14b71e re503d3a9 56 56 */ 57 57 typedef struct { 58 uint64_t sp; 59 uint64_t pc; 60 61 uint64_t rbx; 62 uint64_t rbp; 58 uint64_t sp; 59 uint64_t pc; 63 60 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 61 uint64_t rbx; 62 uint64_t rbp; 68 63 69 uint64_t tls; 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 68 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 } 71 76 72 77 #endif -
uspace/lib/c/arch/arm32/include/fibril.h
rb14b71e re503d3a9 86 86 } context_t; 87 87 88 static inline uintptr_t context_get_fp(context_t *ctx) 89 { 90 return ctx->fp; 91 } 92 88 93 89 94 #endif -
uspace/lib/c/arch/ia32/include/fibril.h
rb14b71e re503d3a9 67 67 } context_t; 68 68 69 static inline uintptr_t context_get_fp(context_t *ctx) 70 { 71 return ctx->ebp; 72 } 73 69 74 #endif 70 75 -
uspace/lib/c/arch/ia64/include/fibril.h
rb14b71e re503d3a9 130 130 } context_t; 131 131 132 static inline uintptr_t context_get_fp(context_t *ctx) 133 { 134 return 0; /* FIXME */ 135 } 136 132 137 #endif 133 138 -
uspace/lib/c/arch/mips32/include/fibril.h
rb14b71e re503d3a9 85 85 } context_t; 86 86 87 static inline uintptr_t context_get_fp(context_t *ctx) 88 { 89 return ctx->sp; 90 } 91 87 92 #endif 88 93 -
uspace/lib/c/arch/ppc32/include/fibril.h
rb14b71e re503d3a9 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 80 85 #endif 81 86 -
uspace/lib/c/arch/sparc64/include/fibril.h
rb14b71e re503d3a9 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 79 84 #endif 80 85 -
uspace/lib/c/generic/fibril.c
rb14b71e re503d3a9 275 275 fibril->func = func; 276 276 fibril->arg = arg; 277 278 fibril->waits_for = NULL; 277 279 278 280 context_save(&fibril->ctx); -
uspace/lib/c/generic/fibril_synch.c
rb14b71e re503d3a9 42 42 #include <errno.h> 43 43 #include <assert.h> 44 #include <stacktrace.h> 45 #include <stdlib.h> 44 46 45 47 static void optimize_execution_power(void) … … 56 58 } 57 59 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 58 95 void fibril_mutex_initialize(fibril_mutex_t *fm) 59 96 { 97 fm->oi.owned_by = NULL; 60 98 fm->counter = 1; 61 99 list_initialize(&fm->waiters); … … 64 102 void fibril_mutex_lock(fibril_mutex_t *fm) 65 103 { 104 fibril_t *f = (fibril_t *) fibril_get_id(); 105 66 106 futex_down(&async_futex); 67 107 if (fm->counter-- <= 0) { … … 73 113 link_initialize(&wdata.wu_event.link); 74 114 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 75 120 fibril_switch(FIBRIL_TO_MANAGER); 76 121 } else { 122 fm->oi.owned_by = f; 77 123 futex_up(&async_futex); 78 124 } … … 86 132 if (fm->counter > 0) { 87 133 fm->counter--; 134 fm->oi.owned_by = (fibril_t *) fibril_get_id(); 88 135 locked = true; 89 136 } … … 99 146 link_t *tmp; 100 147 awaiter_t *wdp; 148 fibril_t *f; 101 149 102 150 assert(!list_empty(&fm->waiters)); … … 105 153 wdp->active = true; 106 154 wdp->wu_event.inlist = false; 155 156 f = (fibril_t *) wdp->fid; 157 fm->oi.owned_by = f; 158 f->waits_for = NULL; 159 107 160 list_remove(&wdp->wu_event.link); 108 161 fibril_add_ready(wdp->fid); 109 162 optimize_execution_power(); 163 } else { 164 fm->oi.owned_by = NULL; 110 165 } 111 166 } … … 120 175 void fibril_rwlock_initialize(fibril_rwlock_t *frw) 121 176 { 177 frw->oi.owned_by = NULL; 122 178 frw->writers = 0; 123 179 frw->readers = 0; -
uspace/lib/c/include/fibril.h
rb14b71e re503d3a9 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 50 56 typedef enum { 51 57 FIBRIL_PREEMPT, … … 68 74 int retval; 69 75 int flags; 76 77 fibril_owner_info_t *waits_for; 70 78 } fibril_t; 71 79 -
uspace/lib/c/include/fibril_synch.h
rb14b71e re503d3a9 43 43 44 44 typedef struct { 45 fibril_owner_info_t oi; /* Keep this the first thing. */ 45 46 int counter; 46 47 link_t waiters; … … 49 50 #define FIBRIL_MUTEX_INITIALIZER(name) \ 50 51 { \ 52 .oi = { \ 53 .owned_by = NULL \ 54 }, \ 51 55 .counter = 1, \ 52 56 .waiters = { \ … … 60 64 61 65 typedef struct { 66 fibril_owner_info_t oi; /* Keep this the first thing. */ 62 67 unsigned writers; 63 68 unsigned readers; … … 67 72 #define FIBRIL_RWLOCK_INITIALIZER(name) \ 68 73 { \ 74 .oi = { \ 75 .owned_by = NULL \ 76 }, \ 69 77 .readers = 0, \ 70 78 .writers = 0, \
Note:
See TracChangeset
for help on using the changeset viewer.