Changeset efedee77 in mainline for uspace/lib/c/generic/fibril_synch.c
- Timestamp:
- 2010-11-02T22:38:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- af894a21
- Parents:
- aab02fb (diff), e06ef614 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/fibril_synch.c
raab02fb refedee77 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;
Note:
See TracChangeset
for help on using the changeset viewer.