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.5 PTH_1_0b7:1.5 PTH_1_0b6:1.5 PTH_1_0b5:1.4 PTH_1_0b4:1.4 PTH_1_0b3:1.2 PTH_1_0b2:1.2 PTH_1_0b1:1.1; locks; strict; comment @ * @; 1.24 date 2007.01.01.18.23.52; author rse; state Exp; branches; next 1.23; commitid 9DhdiirNzQPBIP0s; 1.23 date 2006.06.08.17.54.52; author rse; state Exp; branches; next 1.22; commitid x8N3mLVdQgkbdeAr; 1.22 date 2005.11.22.07.26.43; author rse; state Exp; branches; next 1.21; commitid lQyXsY7GlFXe6Jar; 1.21 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.20; 1.20 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.19; 1.19 date 2003.01.01.15.49.11; author rse; state Exp; branches; next 1.18; 1.18 date 2002.11.03.11.15.04; author rse; state Exp; branches; next 1.17; 1.17 date 2002.10.24.15.21.13; author rse; state Exp; branches; next 1.16; 1.16 date 2002.01.27.11.03.40; author rse; state Exp; branches; next 1.15; 1.15 date 2001.03.24.14.51.04; author rse; state Exp; branches; next 1.14; 1.14 date 2000.03.03.15.42.10; author rse; state Exp; branches; next 1.13; 1.13 date 99.12.30.21.58.59; author rse; state Exp; branches; next 1.12; 1.12 date 99.11.09.08.11.31; author rse; state Exp; branches; next 1.11; 1.11 date 99.11.01.10.27.19; author rse; state Exp; branches; next 1.10; 1.10 date 99.10.31.11.46.12; author rse; state Exp; branches 1.10.2.1; next 1.9; 1.9 date 99.09.17.08.01.54; author rse; state Exp; branches; next 1.8; 1.8 date 99.08.19.15.08.52; author rse; state Exp; branches; next 1.7; 1.7 date 99.08.17.08.08.35; author rse; state Exp; branches; next 1.6; 1.6 date 99.08.04.14.00.53; author rse; state Exp; branches; next 1.5; 1.5 date 99.07.14.06.25.34; author rse; state Exp; branches; next 1.4; 1.4 date 99.07.08.10.34.00; author rse; state Exp; branches; next 1.3; 1.3 date 99.07.08.10.19.10; author rse; state Exp; branches; next 1.2; 1.2 date 99.07.04.12.05.35; author rse; state Exp; branches; next 1.1; 1.1 date 99.06.27.15.38.04; author rse; state Exp; branches; next ; 1.10.2.1 date 99.11.01.10.24.59; author rse; state Exp; branches; next ; desc @@ 1.24 log @Adjusted all copyright messages for new year 2007. @ text @/* ** GNU Pth - The GNU Portable Threads ** Copyright (c) 1999-2007 Ralf S. Engelschall ** ** This file is part of GNU Pth, a non-preemptive thread scheduling ** library which can be found at http://www.gnu.org/software/pth/. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License as published by the Free Software Foundation; either ** version 2.1 of the License, or (at your option) any later version. ** ** This library is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public ** License along with this library; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** USA, or contact Ralf S. Engelschall . ** ** pth_attr.c: Pth thread attributes */ /* ``Unix -- where you can do anything in two keystrokes, or less...'' -- Unknown */ #include "pth_p.h" #if cpp enum { PTH_ATTR_GET, PTH_ATTR_SET }; 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; unsigned int a_stacksize; char *a_stackaddr; }; #endif /* cpp */ pth_attr_t pth_attr_of(pth_t t) { pth_attr_t a; if (t == NULL) return pth_error((pth_attr_t)NULL, EINVAL); if ((a = (pth_attr_t)malloc(sizeof(struct pth_attr_st))) == NULL) return pth_error((pth_attr_t)NULL, ENOMEM); a->a_tid = t; return a; } pth_attr_t pth_attr_new(void) { pth_attr_t a; if ((a = (pth_attr_t)malloc(sizeof(struct pth_attr_st))) == NULL) return pth_error((pth_attr_t)NULL, ENOMEM); a->a_tid = NULL; pth_attr_init(a); return a; } int pth_attr_destroy(pth_attr_t a) { if (a == NULL) return pth_error(FALSE, EINVAL); free(a); return TRUE; } int pth_attr_init(pth_attr_t a) { if (a == NULL) return pth_error(FALSE, EINVAL); if (a->a_tid != NULL) 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; a->a_stackaddr = NULL; return TRUE; } int pth_attr_get(pth_attr_t a, int op, ...) { va_list ap; int rc; va_start(ap, op); rc = pth_attr_ctrl(PTH_ATTR_GET, a, op, ap); va_end(ap); return rc; } int pth_attr_set(pth_attr_t a, int op, ...) { va_list ap; int rc; va_start(ap, op); rc = pth_attr_ctrl(PTH_ATTR_SET, a, op, ap); va_end(ap); return rc; } intern int pth_attr_ctrl(int cmd, pth_attr_t a, int op, va_list ap) { if (a == NULL) return pth_error(FALSE, EINVAL); switch (op) { case PTH_ATTR_PRIO: { /* priority */ int val, *src, *dst; if (cmd == PTH_ATTR_SET) { src = &val; val = va_arg(ap, int); dst = (a->a_tid != NULL ? &a->a_tid->prio : &a->a_prio); } else { src = (a->a_tid != NULL ? &a->a_tid->prio : &a->a_prio); dst = va_arg(ap, int *); } *dst = *src; break; } case PTH_ATTR_NAME: { /* name */ if (cmd == PTH_ATTR_SET) { char *src, *dst; src = va_arg(ap, char *); dst = (a->a_tid != NULL ? a->a_tid->name : a->a_name); pth_util_cpystrn(dst, src, PTH_TCB_NAMELEN); } else { char *src, **dst; src = (a->a_tid != NULL ? a->a_tid->name : a->a_name); dst = va_arg(ap, char **); *dst = src; } 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; break; } case PTH_ATTR_JOINABLE: { /* detachment type */ int val, *src, *dst; if (cmd == PTH_ATTR_SET) { src = &val; val = va_arg(ap, int); dst = (a->a_tid != NULL ? &a->a_tid->joinable : &a->a_joinable); } else { src = (a->a_tid != NULL ? &a->a_tid->joinable : &a->a_joinable); dst = va_arg(ap, int *); } *dst = *src; break; } case PTH_ATTR_CANCEL_STATE: { /* cancellation state */ unsigned int val, *src, *dst; if (cmd == PTH_ATTR_SET) { src = &val; val = va_arg(ap, unsigned int); dst = (a->a_tid != NULL ? &a->a_tid->cancelstate : &a->a_cancelstate); } else { src = (a->a_tid != NULL ? &a->a_tid->cancelstate : &a->a_cancelstate); dst = va_arg(ap, unsigned int *); } *dst = *src; break; } case PTH_ATTR_STACK_SIZE: { /* stack size */ unsigned int val, *src, *dst; if (cmd == PTH_ATTR_SET) { if (a->a_tid != NULL) return pth_error(FALSE, EPERM); src = &val; val = va_arg(ap, unsigned int); dst = &a->a_stacksize; } else { src = (a->a_tid != NULL ? &a->a_tid->stacksize : &a->a_stacksize); dst = va_arg(ap, unsigned int *); } *dst = *src; break; } case PTH_ATTR_STACK_ADDR: { /* stack address */ char *val, **src, **dst; if (cmd == PTH_ATTR_SET) { if (a->a_tid != NULL) return pth_error(FALSE, EPERM); src = &val; val = va_arg(ap, char *); dst = &a->a_stackaddr; } else { src = (a->a_tid != NULL ? &a->a_tid->stack : &a->a_stackaddr); dst = va_arg(ap, char **); } *dst = *src; break; } case PTH_ATTR_TIME_SPAWN: { pth_time_t *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); dst = va_arg(ap, pth_time_t *); if (a->a_tid != NULL) pth_time_set(dst, &a->a_tid->spawned); else pth_time_set(dst, PTH_TIME_ZERO); break; } case PTH_ATTR_TIME_LAST: { pth_time_t *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); dst = va_arg(ap, pth_time_t *); if (a->a_tid != NULL) pth_time_set(dst, &a->a_tid->lastran); else pth_time_set(dst, PTH_TIME_ZERO); break; } case PTH_ATTR_TIME_RAN: { pth_time_t *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); dst = va_arg(ap, pth_time_t *); if (a->a_tid != NULL) pth_time_set(dst, &a->a_tid->running); else pth_time_set(dst, PTH_TIME_ZERO); break; } case PTH_ATTR_START_FUNC: { void *(**dst)(void *); if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); if (a->a_tid == NULL) return pth_error(FALSE, EACCES); dst = (void *(**)(void *))va_arg(ap, void *); *dst = a->a_tid->start_func; break; } case PTH_ATTR_START_ARG: { void **dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); if (a->a_tid == NULL) return pth_error(FALSE, EACCES); dst = va_arg(ap, void **); *dst = a->a_tid->start_arg; break; } case PTH_ATTR_STATE: { pth_state_t *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); if (a->a_tid == NULL) return pth_error(FALSE, EACCES); dst = va_arg(ap, pth_state_t *); *dst = a->a_tid->state; break; } case PTH_ATTR_EVENTS: { pth_event_t *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); if (a->a_tid == NULL) return pth_error(FALSE, EACCES); dst = va_arg(ap, pth_event_t *); *dst = a->a_tid->events; break; } case PTH_ATTR_BOUND: { int *dst; if (cmd == PTH_ATTR_SET) return pth_error(FALSE, EPERM); dst = va_arg(ap, int *); *dst = (a->a_tid != NULL ? TRUE : FALSE); break; } default: return pth_error(FALSE, EINVAL); } return TRUE; } @ 1.23 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.22 log @Add a missing "break" in pth_attr.c:pth_attr_ctrl(). Submitted by: Stefan Schippers @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.21 log @Adjusted all copyright messages for new year 2005. @ text @d166 1 @ 1.20 log @Adjusted all copyright messages for new year 2004. @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.19 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.18 log @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. @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.17 log @Internally switch from "errno_shield {...}" to "pth_shield {...}" and from "return_errno(..)" to "return pth_error(...)" in order to make the internal error handling a little bit more consistent. @ text @d40 1 d89 1 d153 13 @ 1.16 log @bump copyright year @ text @d54 1 a54 1 return_errno(FALSE, EINVAL); d56 1 a56 1 return_errno(NULL, ENOMEM); d66 1 a66 1 return_errno(NULL, ENOMEM); d75 1 a75 1 return_errno(FALSE, EINVAL); d83 1 a83 1 return_errno(FALSE, EINVAL); d85 1 a85 1 return_errno(FALSE, EPERM); d120 1 a120 1 return_errno(FALSE, EINVAL); d185 1 a185 1 return_errno(FALSE, EPERM); d201 1 a201 1 return_errno(FALSE, EPERM); d215 1 a215 1 return_errno(FALSE, EPERM); d226 1 a226 1 return_errno(FALSE, EPERM); d237 1 a237 1 return_errno(FALSE, EPERM); d248 1 a248 1 return_errno(FALSE, EPERM); d250 1 a250 1 return_errno(FALSE, EACCES); d258 1 a258 1 return_errno(FALSE, EPERM); d260 1 a260 1 return_errno(FALSE, EACCES); d268 1 a268 1 return_errno(FALSE, EPERM); d270 1 a270 1 return_errno(FALSE, EACCES); d278 1 a278 1 return_errno(FALSE, EPERM); d280 1 a280 1 return_errno(FALSE, EACCES); d288 1 a288 1 return_errno(FALSE, EPERM); d294 1 a294 1 return_errno(FALSE, EINVAL); @ 1.15 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.14 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.13 log @*** empty log message *** @ text @d90 1 a90 1 a->a_stacksize = 32*1024; @ 1.12 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.11 log @*** empty log message *** @ text @d25 1 a25 1 /* ``Unix -- where you can do anything d126 1 a126 1 src = &val; val = va_arg(ap, int); d156 1 a156 1 src = &val; val = va_arg(ap, int); d170 1 a170 1 src = &val; val = va_arg(ap, unsigned int); d186 1 a186 1 src = &val; val = va_arg(ap, unsigned int); d202 1 a202 1 src = &val; val = va_arg(ap, char *); @ 1.10 log @*** empty log message *** @ text @d2 1 a2 2 ** pth_attr.c -- Pth thread attributes ** d22 2 @ 1.10.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** pth_attr.c: Pth thread attributes @ 1.9 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.8 log @*** empty log message *** @ text @d10 1 a10 1 ** modify it under the terms of the GNU Library General Public d17 1 a17 1 ** Library General Public License for more details. d19 1 a19 1 ** You should have received a copy of the GNU Library General Public @ 1.7 log @*** empty log message *** @ text @d24 3 a26 1 @ 1.6 log @*** empty log message *** @ text @d52 1 a52 1 if ((a = malloc(sizeof(struct pth_attr_st))) == NULL) d62 1 a62 1 if ((a = malloc(sizeof(struct pth_attr_st))) == NULL) @ 1.5 log @*** empty log message *** @ text @d181 2 d184 1 a184 1 dst = (a->a_tid != NULL ? &a->a_tid->stacksize : &a->a_stacksize); d194 1 a194 1 /* stack size */ d197 2 d200 1 a200 1 dst = (a->a_tid != NULL ? &a->a_tid->stack : &a->a_stackaddr); @ 1.4 log @*** empty log message *** @ text @d210 1 a210 1 if (a->a_tid != NULL) { d212 1 a212 2 } else { a213 1 } d221 1 a221 1 if (a->a_tid != NULL) { d223 1 a223 2 } else { a224 1 } d232 1 a232 1 if (a->a_tid != NULL) { d234 1 a234 2 } else { a235 1 } d242 1 a242 1 if (a->a_tid != NULL) d252 1 a252 1 if (a->a_tid != NULL) d262 1 a262 1 if (a->a_tid != NULL) d272 1 a272 1 if (a->a_tid != NULL) @ 1.3 log @*** empty log message *** @ text @d2 1 a2 1 ** pth_attr.c -- PTH thread attributes @ 1.2 log @*** empty log message *** @ text @d6 2 a7 2 ** This file is part of PTH, a non-preemptive thread scheduling library ** which can be found at http://www.gnu.org/software/pth/. @ 1.1 log @*** empty log message *** @ text @d7 1 a7 1 ** which can be found at http://www.engelschall.com/sw/pth/. @