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