Changeset af2a76c in mainline for uspace/lib/c
- Timestamp:
- 2014-07-13T17:25:15Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7493e7b
- Parents:
- b8e75319 (diff), 78192cc7 (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:
-
- 16 edited
-
arch/amd64/src/stacktrace.c (modified) (1 diff)
-
arch/arm32/src/stacktrace.c (modified) (1 diff)
-
arch/ia32/src/stacktrace.c (modified) (1 diff)
-
arch/ppc32/src/stacktrace.c (modified) (1 diff)
-
arch/sparc32/src/stacktrace.c (modified) (2 diffs)
-
arch/sparc64/src/stacktrace.c (modified) (2 diffs)
-
generic/fibril.c (modified) (3 diffs)
-
generic/fibril_synch.c (modified) (8 diffs)
-
generic/inet.c (modified) (3 diffs)
-
generic/stacktrace.c (modified) (1 diff)
-
generic/str.c (modified) (1 diff)
-
include/fibril.h (modified) (1 diff)
-
include/fibril_synch.h (modified) (3 diffs)
-
include/ipc/dev_iface.h (modified) (1 diff)
-
include/stacktrace.h (modified) (1 diff)
-
include/str.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/amd64/src/stacktrace.c
rb8e75319 raf2a76c 51 51 int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev) 52 52 { 53 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);53 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev); 54 54 } 55 55 56 56 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 57 57 { 58 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);58 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 59 59 } 60 60 -
uspace/lib/c/arch/arm32/src/stacktrace.c
rb8e75319 raf2a76c 51 51 int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev) 52 52 { 53 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);53 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev); 54 54 } 55 55 56 56 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 57 57 { 58 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);58 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 59 59 } 60 60 -
uspace/lib/c/arch/ia32/src/stacktrace.c
rb8e75319 raf2a76c 51 51 int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev) 52 52 { 53 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);53 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev); 54 54 } 55 55 56 56 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 57 57 { 58 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);58 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 59 59 } 60 60 -
uspace/lib/c/arch/ppc32/src/stacktrace.c
rb8e75319 raf2a76c 51 51 int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev) 52 52 { 53 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);53 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev); 54 54 } 55 55 56 56 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 57 57 { 58 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);58 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 59 59 } 60 60 -
uspace/lib/c/arch/sparc32/src/stacktrace.c
rb8e75319 raf2a76c 53 53 { 54 54 uintptr_t bprev; 55 int rc = (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,55 int rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, 56 56 &bprev); 57 57 if (rc == EOK) … … 63 63 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 64 64 { 65 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);65 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 66 66 } 67 67 -
uspace/lib/c/arch/sparc64/src/stacktrace.c
rb8e75319 raf2a76c 55 55 int rc; 56 56 57 rc = (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);57 rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev); 58 58 if (rc == EOK) 59 59 *prev = bprev + STACK_BIAS; … … 63 63 int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra) 64 64 { 65 return (*st-> read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);65 return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra); 66 66 } 67 67 -
uspace/lib/c/generic/fibril.c
rb8e75319 raf2a76c 59 59 static LIST_INITIALIZE(serialized_list); 60 60 static LIST_INITIALIZE(manager_list); 61 static LIST_INITIALIZE(fibril_list); 61 62 62 63 /** Number of threads that are executing a manager fibril. */ … … 116 117 117 118 fibril->waits_for = NULL; 119 list_append(&fibril->all_link, &fibril_list); 118 120 119 121 return fibril; … … 122 124 void fibril_teardown(fibril_t *fibril) 123 125 { 126 list_remove(&fibril->all_link); 124 127 tls_free(fibril->tcb); 125 128 free(fibril); -
uspace/lib/c/generic/fibril_synch.c
rb8e75319 raf2a76c 448 448 int rc; 449 449 450 fibril_mutex_lock(&timer->lock); 451 452 while (true) { 453 while (timer->state != fts_active && 454 timer->state != fts_cleanup) { 455 456 if (timer->state == fts_cleanup) 457 break; 458 459 fibril_condvar_wait(&timer->cv, &timer->lock); 450 fibril_mutex_lock(timer->lockp); 451 452 while (timer->state != fts_cleanup) { 453 switch (timer->state) { 454 case fts_not_set: 455 case fts_fired: 456 fibril_condvar_wait(&timer->cv, timer->lockp); 457 break; 458 case fts_active: 459 rc = fibril_condvar_wait_timeout(&timer->cv, 460 timer->lockp, timer->delay); 461 if (rc == ETIMEOUT && timer->state == fts_active) { 462 timer->state = fts_fired; 463 timer->handler_running = true; 464 fibril_mutex_unlock(timer->lockp); 465 timer->fun(timer->arg); 466 fibril_mutex_lock(timer->lockp); 467 timer->handler_running = false; 468 } 469 break; 470 case fts_cleanup: 471 case fts_clean: 472 assert(false); 473 break; 460 474 } 461 462 if (timer->state == fts_cleanup) 463 break; 464 465 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock, 466 timer->delay); 467 if (rc == ETIMEOUT) { 468 timer->state = fts_fired; 469 fibril_mutex_unlock(&timer->lock); 470 timer->fun(timer->arg); 471 fibril_mutex_lock(&timer->lock); 472 } 473 } 474 475 fibril_mutex_unlock(&timer->lock); 475 } 476 477 /* Acknowledge timer fibril has finished cleanup. */ 478 timer->state = fts_clean; 479 fibril_mutex_unlock(timer->lockp); 480 free(timer); 481 476 482 return 0; 477 483 } … … 481 487 * @return New timer on success, @c NULL if out of memory. 482 488 */ 483 fibril_timer_t *fibril_timer_create( void)489 fibril_timer_t *fibril_timer_create(fibril_mutex_t *lock) 484 490 { 485 491 fid_t fid; … … 501 507 timer->fibril = fid; 502 508 timer->state = fts_not_set; 509 timer->lockp = (lock != NULL) ? lock : &timer->lock; 503 510 504 511 fibril_add_ready(fid); 505 506 512 return timer; 507 513 } … … 513 519 void fibril_timer_destroy(fibril_timer_t *timer) 514 520 { 515 fibril_mutex_lock(&timer->lock); 516 assert(timer->state != fts_active); 521 fibril_mutex_lock(timer->lockp); 522 assert(timer->state == fts_not_set || timer->state == fts_fired); 523 524 /* Request timer fibril to terminate. */ 517 525 timer->state = fts_cleanup; 518 526 fibril_condvar_broadcast(&timer->cv); 519 fibril_mutex_unlock( &timer->lock);527 fibril_mutex_unlock(timer->lockp); 520 528 } 521 529 … … 533 541 fibril_timer_fun_t fun, void *arg) 534 542 { 535 fibril_mutex_lock(&timer->lock); 543 fibril_mutex_lock(timer->lockp); 544 fibril_timer_set_locked(timer, delay, fun, arg); 545 fibril_mutex_unlock(timer->lockp); 546 } 547 548 /** Set locked timer. 549 * 550 * Set timer to execute a callback function after the specified 551 * interval. Must be called when the timer is locked. 552 * 553 * @param timer Timer 554 * @param delay Delay in microseconds 555 * @param fun Callback function 556 * @param arg Argument for @a fun 557 */ 558 void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay, 559 fibril_timer_fun_t fun, void *arg) 560 { 561 assert(fibril_mutex_is_locked(timer->lockp)); 562 assert(timer->state == fts_not_set || timer->state == fts_fired); 536 563 timer->state = fts_active; 537 564 timer->delay = delay; … … 539 566 timer->arg = arg; 540 567 fibril_condvar_broadcast(&timer->cv); 541 fibril_mutex_unlock(&timer->lock);542 568 } 543 569 … … 557 583 fibril_timer_state_t old_state; 558 584 559 fibril_mutex_lock(&timer->lock); 585 fibril_mutex_lock(timer->lockp); 586 old_state = fibril_timer_clear_locked(timer); 587 fibril_mutex_unlock(timer->lockp); 588 589 return old_state; 590 } 591 592 /** Clear locked timer. 593 * 594 * Clears (cancels) timer and returns last state of the timer. 595 * This can be one of: 596 * - fts_not_set If the timer has not been set or has been cleared 597 * - fts_active Timer was set but did not fire 598 * - fts_fired Timer fired 599 * Must be called when the timer is locked. 600 * 601 * @param timer Timer 602 * @return Last timer state 603 */ 604 fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *timer) 605 { 606 fibril_timer_state_t old_state; 607 608 assert(fibril_mutex_is_locked(timer->lockp)); 609 610 while (timer->handler_running) 611 fibril_condvar_wait(&timer->cv, timer->lockp); 612 560 613 old_state = timer->state; 561 614 timer->state = fts_not_set; … … 565 618 timer->arg = NULL; 566 619 fibril_condvar_broadcast(&timer->cv); 567 fibril_mutex_unlock(&timer->lock);568 620 569 621 return old_state; -
uspace/lib/c/generic/inet.c
rb8e75319 raf2a76c 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 #include <ipc/services.h> 35 35 #include <loc.h> 36 #include <stdlib.h> 36 37 37 38 static void inet_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 224 225 225 226 rc = inet_ev_ops->recv(&dgram); 227 free(dgram.data); 226 228 async_answer_0(iid, rc); 227 229 } -
uspace/lib/c/generic/stacktrace.c
rb8e75319 raf2a76c 42 42 static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data); 43 43 44 void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc) 44 static stacktrace_ops_t basic_ops = { 45 .read_uintptr = stacktrace_read_uintptr 46 }; 47 48 void stacktrace_print_generic(stacktrace_ops_t *ops, void *arg, uintptr_t fp, 49 uintptr_t pc) 45 50 { 46 51 stacktrace_t st; 47 52 uintptr_t nfp; 53 int rc; 48 54 49 st.op_arg = NULL;50 st. read_uintptr = stacktrace_read_uintptr;55 st.op_arg = arg; 56 st.ops = ops; 51 57 52 58 while (stacktrace_fp_valid(&st, fp)) { 53 59 printf("%p: %p()\n", (void *) fp, (void *) pc); 54 (void) stacktrace_ra_get(&st, fp, &pc); 55 (void) stacktrace_fp_prev(&st, fp, &nfp); 60 rc = stacktrace_ra_get(&st, fp, &pc); 61 if (rc != EOK) 62 break; 63 rc = stacktrace_fp_prev(&st, fp, &nfp); 64 if (rc != EOK) 65 break; 56 66 fp = nfp; 57 67 } 68 } 69 70 void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc) 71 { 72 stacktrace_print_generic(&basic_ops, NULL, fp, pc); 58 73 } 59 74 -
uspace/lib/c/generic/str.c
rb8e75319 raf2a76c 1360 1360 } 1361 1361 1362 char *strtok(char *s, const char *delim) 1363 { 1364 static char *next; 1365 1366 return strtok_r(s, delim, &next); 1367 } 1368 1369 char *strtok_r(char *s, const char *delim, char **next) 1362 /** Split string by delimiters. 1363 * 1364 * @param s String to be tokenized. May not be NULL. 1365 * @param delim String with the delimiters. 1366 * @param next Variable which will receive the pointer to the 1367 * continuation of the string following the first 1368 * occurrence of any of the delimiter characters. 1369 * May be NULL. 1370 * @return Pointer to the prefix of @a s before the first 1371 * delimiter character. NULL if no such prefix 1372 * exists. 1373 */ 1374 char *str_tok(char *s, const char *delim, char **next) 1370 1375 { 1371 1376 char *start, *end; 1372 1377 1373 if (s == NULL) 1374 s = *next; 1378 if (!s) 1379 return NULL; 1380 1381 size_t len = str_size(s); 1382 size_t cur; 1383 size_t tmp; 1384 wchar_t ch; 1375 1385 1376 1386 /* Skip over leading delimiters. */ 1377 while (*s && (str_chr(delim, *s) != NULL)) ++s; 1378 start = s; 1387 for (tmp = cur = 0; 1388 (ch = str_decode(s, &tmp, len)) && str_chr(delim, ch); /**/) 1389 cur = tmp; 1390 start = &s[cur]; 1379 1391 1380 1392 /* Skip over token characters. */ 1381 while (*s && (str_chr(delim, *s) == NULL)) ++s; 1382 end = s; 1383 *next = (*s ? s + 1 : s); 1384 1385 if (start == end) { 1393 for (tmp = cur; 1394 (ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch); /**/) 1395 cur = tmp; 1396 end = &s[cur]; 1397 if (next) 1398 *next = (ch ? &s[tmp] : &s[cur]); 1399 1400 if (start == end) 1386 1401 return NULL; /* No more tokens. */ 1387 }1388 1402 1389 1403 /* Overwrite delimiter with NULL terminator. */ -
uspace/lib/c/include/fibril.h
rb8e75319 raf2a76c 67 67 typedef struct fibril { 68 68 link_t link; 69 link_t all_link; 69 70 context_t ctx; 70 71 void *stack; -
uspace/lib/c/include/fibril_synch.h
rb8e75319 raf2a76c 116 116 /** Timer has fired and has not been cleared since */ 117 117 fts_fired, 118 /** Timer is being destroyed */ 119 fts_cleanup 118 /** Timer fibril is requested to terminate */ 119 fts_cleanup, 120 /** Timer fibril acknowledged termination */ 121 fts_clean 120 122 } fibril_timer_state_t; 121 123 … … 129 131 typedef struct { 130 132 fibril_mutex_t lock; 133 fibril_mutex_t *lockp; 131 134 fibril_condvar_t cv; 132 135 fid_t fibril; 133 136 fibril_timer_state_t state; 137 bool handler_running; 134 138 135 139 suseconds_t delay; … … 160 164 extern void fibril_condvar_broadcast(fibril_condvar_t *); 161 165 162 extern fibril_timer_t *fibril_timer_create( void);166 extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *); 163 167 extern void fibril_timer_destroy(fibril_timer_t *); 164 168 extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t, 165 169 void *); 170 extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t, 171 fibril_timer_fun_t, void *); 166 172 extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *); 173 extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *); 167 174 168 175 #endif -
uspace/lib/c/include/ipc/dev_iface.h
rb8e75319 raf2a76c 40 40 /** Character device interface */ 41 41 CHAR_DEV_IFACE, 42 43 /** Graphic device interface */44 GRAPH_DEV_IFACE,45 42 46 43 /** Audio device mixer interface */ -
uspace/lib/c/include/stacktrace.h
rb8e75319 raf2a76c 41 41 42 42 typedef struct { 43 int (*read_uintptr)(void *, uintptr_t, uintptr_t *); 44 } stacktrace_ops_t; 45 46 typedef struct { 43 47 void *op_arg; 44 int (*read_uintptr)(void *, uintptr_t, uintptr_t *);48 stacktrace_ops_t *ops; 45 49 } stacktrace_t; 46 50 47 51 extern void stacktrace_print(void); 48 52 extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t); 53 extern void stacktrace_print_generic(stacktrace_ops_t *, void *, uintptr_t, 54 uintptr_t); 49 55 50 56 /* -
uspace/lib/c/include/str.h
rb8e75319 raf2a76c 109 109 extern char *str_ndup(const char *, size_t max_size); 110 110 111 extern char *str_tok(char *, const char *, char **); 112 111 113 extern int str_uint8_t(const char *, const char **, unsigned int, bool, 112 114 uint8_t *); … … 132 134 extern unsigned long strtoul(const char *, char **, int); 133 135 134 extern char * strtok_r(char *, const char *, char **);135 extern char * strtok(char *, const char *);136 137 136 #endif 138 137
Note:
See TracChangeset
for help on using the changeset viewer.
