Index: ossp-pkg/ex/ex.pod RCS File: /v/ossp/cvs/ossp-pkg/ex/ex.pod,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/ex/ex.pod,v' 2>/dev/null --- ex.pod 2002/03/07 21:30:10 1.21 +++ ex.pod 2002/03/30 18:15:49 1.22 @@ -410,98 +410,98 @@ =item F -#ifndef __PTHREAD_EX_H__ -#define __PTHREAD_EX_H__ + #ifndef __PTHREAD_EX_H__ + #define __PTHREAD_EX_H__ -#include + #include -int pthread_init_ex (void); -int pthread_create_ex (pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); + int pthread_init_ex (void); + int pthread_create_ex (pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); -#ifndef PTHREAD_EX_INTERNAL -#define pthread_init pthread_init_ex -#define pthread_create pthread_create_ex -#endif + #ifndef PTHREAD_EX_INTERNAL + #define pthread_init pthread_init_ex + #define pthread_create pthread_create_ex + #endif -#endif /* __PTHREAD_EX_H__ */ + #endif /* __PTHREAD_EX_H__ */ =item F -#include -#include + #include + #include + + #define PTHREAD_EX_INTERNAL + #include "pthread_ex.h" + #include "ex.h" + + /* context storage key */ + static pthread_key_t pthread_ex_ctx_key; -#define PTHREAD_EX_INTERNAL -#include "pthread_ex.h" -#include "ex.h" - -/* context storage key */ -static pthread_key_t pthread_ex_ctx_key; - -/* context destructor */ -static void pthread_ex_ctx_destroy(void *data) -{ - if (data != NULL) - free(data); - return; -} - -/* callback: context fetching */ -static ex_ctx_t *pthread_ex_ctx(void) -{ - return (ex_ctx_t *)pthread_getspecific(pthread_ex_ctx_key); -} - -/* callback: termination */ -static void pthread_ex_terminate(ex_t *e) -{ - pthread_exit(e->ex_value); -} - -/* pthread init */ -int pthread_init_ex(void) -{ - int rc; - - /* additionally create thread data key and override OSSP ex callbacks */ - pthread_key_create(&pthread_ex_ctx_key, pthread_ex_ctx_destroy); - __ex_ctx = pthread_ex_ctx; - __ex_terminate = pthread_ex_terminate; - - return rc; -} - -/* internal thread entry wrapper information */ -typedef struct { - void *(*entry)(void *); - void *arg; -} pthread_create_ex_t; - -/* internal thread entry wrapper */ -static void *pthread_create_wrapper(void *arg) -{ - pthread_create_ex_t *wrapper; - ex_ctx_t *ex_ctx; - - /* create per-thread exception context */ - wrapper = (pthread_create_ex_t *)arg; - ex_ctx = (ex_ctx_t *)malloc(sizeof(ex_ctx_t)); - EX_CTX_INITIALIZE(ex_ctx); - pthread_setspecific(pthread_ex_ctx_key, ex_ctx); - - /* perform original operation */ - return wrapper->entry(wrapper->arg); -} - -/* pthread_create() wrapper */ -int pthread_create_ex(pthread_t *thread, const pthread_attr_t *attr, void *(*entry)(void *), void *arg) -{ - pthread_create_ex_t wrapper; - - /* spawn thread but execute start function through wrapper */ - wrapper.entry = entry; - wrapper.arg = arg; - return pthread_create(thread, attr, pthread_create_wrapper, &wrapper); -} + /* context destructor */ + static void pthread_ex_ctx_destroy(void *data) + { + if (data != NULL) + free(data); + return; + } + + /* callback: context fetching */ + static ex_ctx_t *pthread_ex_ctx(void) + { + return (ex_ctx_t *)pthread_getspecific(pthread_ex_ctx_key); + } + + /* callback: termination */ + static void pthread_ex_terminate(ex_t *e) + { + pthread_exit(e->ex_value); + } + + /* pthread init */ + int pthread_init_ex(void) + { + int rc; + + /* additionally create thread data key and override OSSP ex callbacks */ + pthread_key_create(&pthread_ex_ctx_key, pthread_ex_ctx_destroy); + __ex_ctx = pthread_ex_ctx; + __ex_terminate = pthread_ex_terminate; + + return rc; + } + + /* internal thread entry wrapper information */ + typedef struct { + void *(*entry)(void *); + void *arg; + } pthread_create_ex_t; + + /* internal thread entry wrapper */ + static void *pthread_create_wrapper(void *arg) + { + pthread_create_ex_t *wrapper; + ex_ctx_t *ex_ctx; + + /* create per-thread exception context */ + wrapper = (pthread_create_ex_t *)arg; + ex_ctx = (ex_ctx_t *)malloc(sizeof(ex_ctx_t)); + EX_CTX_INITIALIZE(ex_ctx); + pthread_setspecific(pthread_ex_ctx_key, ex_ctx); + + /* perform original operation */ + return wrapper->entry(wrapper->arg); + } + + /* pthread_create() wrapper */ + int pthread_create_ex(pthread_t *thread, const pthread_attr_t *attr, void *(*entry)(void *), void *arg) + { + pthread_create_ex_t wrapper; + + /* spawn thread but execute start function through wrapper */ + wrapper.entry = entry; + wrapper.arg = arg; + return pthread_create(thread, attr, pthread_create_wrapper, &wrapper); + } =back @@ -665,27 +665,33 @@ =head1 SEE ALSO -B C/C/C; -B C/C/C/C; -B jmp_buf(3)/setjmp(3)/longjmp(3); -B sigjmp_buf(3)/sigsetjmp(3)/siglongjump(3); -B ucontext(3)/setcontext(3)/getcontext(3). +B C, C, C. + +B C, C, C, C. + +B jmp_buf(3), setjmp(3), longjmp(3). + +B sigjmp_buf(3), sigsetjmp(3), siglongjump(3). + +B ucontext(3), setcontext(3), getcontext(3). =head1 HISTORY B was invented in January 2002 by Ralf S. Engelschall -Erse@engelschall.comE for use inside the B project. -Its creation was prompted by the requirement to reduce the error -handling inside B. The core B/B clause -was inspired by B and the implementation was partly -derived from B 2.0.0, a similar library written 2000 by -Adam M. Costello Eamc@cs.berkeley.eduE and Cosmin Truta -Ecosmin@cs.toronto.eduE. The B clause was inspired by -the B C clause. The B feature was inspired by an -C shielding facility used in the B implementation. The -B feature was invented to simplify an application's cleanup -handling if multiple independent resources are allocated and have to be -freed on error. +Erse@engelschall.comE for use inside the B project. Its +creation was prompted by the requirement to reduce the error handling +inside B. + +The core B/B clause was inspired by B and the +implementation was partly derived from B 2.0.0, a similar +library written 2000 by Adam M. Costello Eamc@cs.berkeley.eduE +and Cosmin Truta Ecosmin@cs.toronto.eduE. + +The B clause was inspired by the B C clause. +The B feature was inspired by an C shielding facility +used in the B implementation. The B feature was invented +to simplify an application's cleanup handling if multiple independent +resources are allocated and have to be freed on error. =head1 AUTHORS