Index: ossp-pkg/pth/ChangeLog RCS File: /v/ossp/cvs/ossp-pkg/pth/ChangeLog,v rcsdiff -q -kk '-r1.583' '-r1.584' -u '/v/ossp/cvs/ossp-pkg/pth/ChangeLog,v' 2>/dev/null --- ChangeLog 2002/11/03 09:59:32 1.583 +++ ChangeLog 2002/11/03 11:15:04 1.584 @@ -21,6 +21,12 @@ Changes between 1.4.1 and 1.5.0 (27-Jan-2002 to xx-Oct-2002) + *) Added thread attribute PTH_ATTR_DISPATCHES which (in bounded + attribute objects) is incremented every time the context + is switched to the associated thread. This can be used for + statistical information. + [Ralf S. Engelschall] + *) Added a stand-alone sub-API for manual user-space context switching. It is somewhat modeled after the POSIX ucontext(3) facility and consists of an opaque data type pth_uctx_t and Index: ossp-pkg/pth/pth.h.in RCS File: /v/ossp/cvs/ossp-pkg/pth/pth.h.in,v rcsdiff -q -kk '-r1.135' '-r1.136' -u '/v/ossp/cvs/ossp-pkg/pth/pth.h.in,v' 2>/dev/null --- pth.h.in 2002/11/03 09:59:32 1.135 +++ pth.h.in 2002/11/03 11:15:04 1.136 @@ -151,6 +151,7 @@ PTH_ATTR_CANCEL_STATE, /* RW [unsigned int] thread cancellation state */ PTH_ATTR_STACK_SIZE, /* RW [unsigned int] stack size */ PTH_ATTR_STACK_ADDR, /* RW [char *] stack lower address */ + PTH_ATTR_DISPATCHES, /* RO [int] total number of thread dispatches */ PTH_ATTR_TIME_SPAWN, /* RO [pth_time_t] time thread was spawned */ PTH_ATTR_TIME_LAST, /* RO [pth_time_t] time thread was last dispatched */ PTH_ATTR_TIME_RAN, /* RO [pth_time_t] time thread was running */ Index: ossp-pkg/pth/pth.pod RCS File: /v/ossp/cvs/ossp-pkg/pth/pth.pod,v rcsdiff -q -kk '-r1.158' '-r1.159' -u '/v/ossp/cvs/ossp-pkg/pth/pth.pod,v' 2>/dev/null --- pth.pod 2002/11/03 09:59:33 1.158 +++ pth.pod 2002/11/03 11:15:04 1.159 @@ -714,6 +714,11 @@ Name of thread (up to 40 characters are stored only), mainly for debugging purposes. +=item C (read-write) [C] + +In bounded attribute objects, this field is incremented every time the +context is switched to the associated thread. + =item C (read-write> [C] The thread detachment type, C indicates a joinable thread, @@ -799,8 +804,9 @@ This initializes an attribute object I to the default values: C := C, C := `C', -C := C, C := -C, C := 64*1024 and +C := C<0>, C := C, +C := C, +C := 64*1024 and C := C. All other C attributes are read-only attributes and don't receive default values in I, because they exists only for bounded attribute objects. @@ -814,6 +820,7 @@ PTH_ATTR_PRIO int PTH_ATTR_NAME char * + PTH_ATTR_DISPATCHES int PTH_ATTR_JOINABLE int PTH_ATTR_CANCEL_STATE unsigned int PTH_ATTR_STACK_SIZE unsigned int @@ -828,6 +835,7 @@ PTH_ATTR_PRIO int * PTH_ATTR_NAME char ** + PTH_ATTR_DISPATCHES int * PTH_ATTR_JOINABLE int * PTH_ATTR_CANCEL_STATE unsigned int * PTH_ATTR_STACK_SIZE unsigned int * @@ -860,12 +868,14 @@ This spawns a new thread with the attributes given in I (or C for default attributes - which means that thread priority, joinability and cancel state are inherited from the current thread) with the -starting point at routine I. This entry routine is called as -`pth_exit(I(I))' inside the new thread unit, i.e., I's -return value is fed to an implicit pth_exit(3). So the thread usually can exit -by just returning. Nevertheless the thread can also exit explicitly at any -time by calling pth_exit(3). But keep in mind that calling the POSIX function -exit(3) still terminates the complete process and not just the current thread. +starting point at routine I; the dispatch count is not inherited from +the current thread if I is not specified - rather, it is initialized +to zero. This entry routine is called as `pth_exit(I(I))' inside +the new thread unit, i.e., I's return value is fed to an implicit +pth_exit(3). So the thread can also exit by just returning. Nevertheless +the thread can also exit explicitly at any time by calling pth_exit(3). But +keep in mind that calling the POSIX function exit(3) still terminates the +complete process and not just the current thread. There is no B-internal limit on the number of threads one can spawn, except the limit implied by the available virtual memory. B internally Index: ossp-pkg/pth/pth_attr.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_attr.c,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/pth/pth_attr.c,v' 2>/dev/null --- pth_attr.c 2002/10/24 15:21:13 1.17 +++ pth_attr.c 2002/11/03 11:15:04 1.18 @@ -37,6 +37,7 @@ struct pth_attr_st { pth_t a_tid; int a_prio; + int a_dispatches; char a_name[PTH_TCB_NAMELEN]; int a_joinable; unsigned int a_cancelstate; @@ -85,6 +86,7 @@ return pth_error(FALSE, EPERM); a->a_prio = PTH_PRIO_STD; pth_util_cpystrn(a->a_name, "unknown", PTH_TCB_NAMELEN); + a->a_dispatches = 0; a->a_joinable = TRUE; a->a_cancelstate = PTH_CANCEL_DEFAULT; a->a_stacksize = 64*1024; @@ -149,6 +151,19 @@ } break; } + case PTH_ATTR_DISPATCHES: { + /* incremented on every context switch */ + int val, *src, *dst; + if (cmd == PTH_ATTR_SET) { + src = &val; val = va_arg(ap, int); + dst = (a->a_tid != NULL ? &a->a_tid->dispatches : &a->a_dispatches); + } + else { + src = (a->a_tid != NULL ? &a->a_tid->dispatches : &a->a_dispatches); + dst = va_arg(ap, int *); + } + *dst = *src; + } case PTH_ATTR_JOINABLE: { /* detachment type */ int val, *src, *dst; Index: ossp-pkg/pth/pth_lib.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_lib.c,v rcsdiff -q -kk '-r1.53' '-r1.54' -u '/v/ossp/cvs/ossp-pkg/pth/pth_lib.c,v' 2>/dev/null --- pth_lib.c 2002/10/24 15:21:13 1.53 +++ pth_lib.c 2002/11/03 11:15:04 1.54 @@ -239,6 +239,7 @@ t->prio = attr->a_prio; t->joinable = attr->a_joinable; t->cancelstate = attr->a_cancelstate; + t->dispatches = attr->a_dispatches; pth_util_cpystrn(t->name, attr->a_name, PTH_TCB_NAMELEN); } else if (pth_current != NULL) { @@ -246,6 +247,7 @@ t->prio = pth_current->prio; t->joinable = pth_current->joinable; t->cancelstate = pth_current->cancelstate; + t->dispatches = 0; pth_snprintf(t->name, PTH_TCB_NAMELEN, "%s.child@%d=0x%lx", pth_current->name, (unsigned int)time(NULL), (unsigned long)pth_current); @@ -255,6 +257,7 @@ t->prio = PTH_PRIO_STD; t->joinable = TRUE; t->cancelstate = PTH_CANCEL_DEFAULT; + t->dispatches = 0; pth_snprintf(t->name, PTH_TCB_NAMELEN, "user/%x", (unsigned int)time(NULL)); } Index: ossp-pkg/pth/pth_sched.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_sched.c,v rcsdiff -q -kk '-r1.81' '-r1.82' -u '/v/ossp/cvs/ossp-pkg/pth/pth_sched.c,v' 2>/dev/null --- pth_sched.c 2002/01/27 11:03:41 1.81 +++ pth_sched.c 2002/11/03 11:15:05 1.82 @@ -240,6 +240,7 @@ pth_time_add(&pth_sched->running, &running); /* ** ENTERING THREAD ** - by switching the machine context */ + pth_current->dispatches++; pth_mctx_switch(&pth_sched->mctx, &pth_current->mctx); /* update scheduler times */ Index: ossp-pkg/pth/pth_tcb.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_tcb.c,v rcsdiff -q -kk '-r1.39' '-r1.40' -u '/v/ossp/cvs/ossp-pkg/pth/pth_tcb.c,v' 2>/dev/null --- pth_tcb.c 2002/10/24 15:21:14 1.39 +++ pth_tcb.c 2002/11/03 11:15:05 1.40 @@ -40,6 +40,7 @@ /* standard thread control block ingredients */ int prio; /* base priority of thread */ char name[PTH_TCB_NAMELEN];/* name of thread (mainly for debugging) */ + int dispatches; /* total number of thread dispatches */ pth_state_t state; /* current state indicator for thread */ /* timing */