Changes in uspace/lib/libc/generic/fibril.c [ec8b0dac:f41aa81] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/fibril.c
rec8b0dac rf41aa81 41 41 #include <unistd.h> 42 42 #include <stdio.h> 43 #include <arch/barrier.h> 43 44 #include <libarch/faddr.h> 44 45 #include <futex.h> … … 133 134 int fibril_switch(fibril_switch_type_t stype) 134 135 { 135 fibril_t *srcf, *dstf;136 136 int retval = 0; 137 137 138 138 futex_down(&fibril_futex); 139 139 140 140 if (stype == FIBRIL_PREEMPT && list_empty(&ready_list)) 141 141 goto ret_0; 142 142 143 143 if (stype == FIBRIL_FROM_MANAGER) { 144 if ( list_empty(&ready_list) && list_empty(&serialized_list))144 if ((list_empty(&ready_list)) && (list_empty(&serialized_list))) 145 145 goto ret_0; 146 146 147 /* 147 148 * Do not preempt if there is not enough threads to run the 148 149 * ready fibrils which are not serialized. 149 150 */ 150 if ( list_empty(&serialized_list) &&151 threads_in_manager <= serialized_threads) {151 if ((list_empty(&serialized_list)) && 152 (threads_in_manager <= serialized_threads)) { 152 153 goto ret_0; 153 154 } 154 155 } 156 155 157 /* If we are going to manager and none exists, create it */ 156 if ( stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {158 if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) { 157 159 while (list_empty(&manager_list)) { 158 160 futex_up(&fibril_futex); … … 162 164 } 163 165 164 srcf = __tcb_get()->fibril_data;166 fibril_t *srcf = __tcb_get()->fibril_data; 165 167 if (stype != FIBRIL_FROM_DEAD) { 168 166 169 /* Save current state */ 167 170 if (!context_save(&srcf->ctx)) { 168 171 if (serialization_count) 169 172 srcf->flags &= ~FIBRIL_SERIALIZED; 173 170 174 if (srcf->clean_after_me) { 171 175 /* … … 173 177 * restored context here. 174 178 */ 175 void *stack = srcf->clean_after_me->stack; 179 void *stack = srcf->clean_after_me->stack; 176 180 if (stack) { 177 181 /* … … 188 192 srcf->clean_after_me = NULL; 189 193 } 194 190 195 return 1; /* futex_up already done here */ 191 196 } 192 197 193 198 /* Save myself to the correct run list */ 194 199 if (stype == FIBRIL_PREEMPT) … … 197 202 list_append(&srcf->link, &manager_list); 198 203 threads_in_manager--; 199 } else { 204 } else { 200 205 /* 201 206 * If stype == FIBRIL_TO_MANAGER, don't put ourselves to … … 207 212 208 213 /* Choose a new fibril to run */ 209 if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) { 214 fibril_t *dstf; 215 if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) { 210 216 dstf = list_get_instance(manager_list.next, fibril_t, link); 211 217 if (serialization_count && stype == FIBRIL_TO_MANAGER) { … … 214 220 } 215 221 threads_in_manager++; 216 222 217 223 if (stype == FIBRIL_FROM_DEAD) 218 224 dstf->clean_after_me = srcf; … … 228 234 } 229 235 list_remove(&dstf->link); 230 236 231 237 futex_up(&fibril_futex); 232 238 context_restore(&dstf->ctx); 233 239 /* not reached */ 234 240 235 241 ret_0: 236 242 futex_up(&fibril_futex);
Note:
See TracChangeset
for help on using the changeset viewer.