Changeset 116d3f6f in mainline for uspace/lib/libc/generic/fibril.c
- Timestamp:
- 2007-10-03T06:55:56Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 18525c5
- Parents:
- 5b5d25f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/fibril.c
r5b5d25f r116d3f6f 76 76 return NULL; 77 77 78 f = malloc(sizeof( *f));78 f = malloc(sizeof(fibril_t)); 79 79 if (!f) { 80 80 __free_tls(tcb); … … 85 85 f->tcb = tcb; 86 86 87 f->func = NULL; 88 f->arg = NULL; 89 f->stack = NULL; 90 f->clean_after_me = NULL; 91 f->retval = 0; 92 f->flags = 0; 93 87 94 return f; 88 95 } … … 107 114 f->retval = f->func(f->arg); 108 115 109 fibril_s chedule_next_adv(FIBRIL_FROM_DEAD);116 fibril_switch(FIBRIL_FROM_DEAD); 110 117 /* not reached */ 111 118 } 112 119 113 /** S chedule next fibril.120 /** Switch from the current fibril. 114 121 * 115 122 * If calling with FIBRIL_TO_MANAGER parameter, the async_futex should be … … 122 129 * return 1 otherwise. 123 130 */ 124 int fibril_s chedule_next_adv(fibril_switch_type_t stype)131 int fibril_switch(fibril_switch_type_t stype) 125 132 { 126 133 fibril_t *srcf, *dstf; … … 139 146 * managers. 140 147 */ 141 if (list_empty(&serialized_list) && fibrils_in_manager <=142 serialized_fibrils) {148 if (list_empty(&serialized_list) && 149 fibrils_in_manager <= serialized_fibrils) { 143 150 goto ret_0; 144 151 } … … 164 171 * restored context here. 165 172 */ 166 free(srcf->clean_after_me->stack); 173 void *stack = srcf->clean_after_me->stack; 174 if (stack) { 175 /* 176 * This check is necessary because a 177 * thread could have exited like a 178 * normal fibril using the 179 * FIBRIL_FROM_DEAD switch type. In that 180 * case, its fibril will not have the 181 * stack member filled. 182 */ 183 free(stack); 184 } 167 185 fibril_teardown(srcf->clean_after_me); 168 186 srcf->clean_after_me = NULL; … … 185 203 } 186 204 } 187 205 188 206 /* Choose a new fibril to run */ 189 207 if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) { … … 195 213 fibrils_in_manager++; 196 214 197 if (stype == FIBRIL_FROM_DEAD) 215 if (stype == FIBRIL_FROM_DEAD) 198 216 dstf->clean_after_me = srcf; 199 217 } else { … … 234 252 f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO * 235 253 getpagesize()); 236 237 254 if (!f->stack) { 238 255 fibril_teardown(f); 239 256 return 0; 240 257 } 241 258 259 f->func = func; 242 260 f->arg = arg; 243 f->func = func;244 f->clean_after_me = NULL;245 f->retval = 0;246 f->flags = 0;247 261 248 262 context_save(&f->ctx);
Note:
See TracChangeset
for help on using the changeset viewer.