head 1.69; access; symbols PTH_2_0_7:1.68 PTH_2_0_6:1.67 PTH_2_0_5:1.67 PTH_2_0_4:1.67 PTH_2_0_3:1.66 PTH_2_0_2:1.66 PTH_2_0_1:1.65 PTH_2_0_0:1.64 PTH_2_0b2:1.63 PTH_2_0b1:1.62 PTH_2_0b0:1.62 PTH_1_4:1.57.0.2 PTH_1_4_1:1.57 PTH_1_4_0:1.56 PTH_1_3_7:1.50 PTH_1_4a3:1.51 PTH_1_3_6:1.50 PTH_1_4a2:1.51 PTH_1_3_5:1.50 PTH_1_4a1:1.51 PTH_1_3_4:1.50 PTH_1_3:1.50.0.2 PTH_1_3_3:1.50 PTH_1_3_2:1.50 PTH_1_3_1:1.50 PTH_1_3_0:1.50 PTH_1_3b3:1.50 PTH_1_2_3:1.46.2.2 PTH_1_3b2:1.49 PTH_1_3b1:1.49 PTH_1_3a5:1.49 PTH_1_3a4:1.49 PTH_1_3a3:1.49 PTH_1_2_2:1.46.2.1 PTH_1_3a2:1.49 PTH_1_2_1:1.46.2.1 PTH_1_3a1:1.47 PTH_1_2:1.46.0.2 PTH_1_2_0:1.46 PTH_1_2b8:1.45 PTH_1_2b7:1.41 PTH_1_1_6:1.37 PTH_1_2b6:1.40 PTH_1_2b5:1.40 PTH_1_2b4:1.39 PTH_1_2b3:1.39 PTH_1_2b2:1.38 PTH_1_2b1:1.38 PTH_1_1_5:1.37 PTH_1_0_6:1.26.2.1 PTH_1_0_5:1.26 PTH_1_0:1.26.0.2 PTH_1_1:1.37.0.2 PTH_1_1_4:1.37 PTH_1_1_3:1.34 PTH_1_1_2:1.34 PTH_1_1_1:1.34 PTH_1_1_0:1.31 PTH_1_1b7:1.30 PTH_1_1b6:1.30 PTH_1_1b5:1.29 PTH_1_1b4:1.27 PTH_1_1b3:1.27 PTH_1_1b2:1.26 PTH_1_1b1:1.26 PTH_1_0_4:1.26 PTH_1_0_3:1.25 PTH_1_0_2:1.23 PTH_1_0_1:1.22 PTH_1_0_0:1.21 PTH_1_0b8:1.20 PTH_1_0b7:1.14 PTH_1_0b6:1.13 PTH_1_0b5:1.12 PTH_1_0b4:1.7 PTH_1_0b3:1.2 PTH_1_0b2:1.2; locks; strict; comment @ * @; 1.69 date 2007.01.01.18.23.53; author rse; state Exp; branches; next 1.68; commitid 9DhdiirNzQPBIP0s; 1.68 date 2006.06.08.17.54.54; author rse; state Exp; branches; next 1.67; commitid x8N3mLVdQgkbdeAr; 1.67 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.66; 1.66 date 2004.09.12.09.28.04; author rse; state Exp; branches; next 1.65; 1.65 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.64; 1.64 date 2003.01.01.15.49.12; author rse; state Exp; branches; next 1.63; 1.63 date 2002.11.09.11.30.15; author rse; state Exp; branches; next 1.62; 1.62 date 2002.11.05.19.39.09; author rse; state Exp; branches; next 1.61; 1.61 date 2002.10.24.15.21.14; author rse; state Exp; branches; next 1.60; 1.60 date 2002.10.23.14.04.00; author rse; state Exp; branches; next 1.59; 1.59 date 2002.10.15.20.34.23; author rse; state Exp; branches; next 1.58; 1.58 date 2002.10.15.17.23.19; author rse; state Exp; branches; next 1.57; 1.57 date 2002.01.27.11.03.41; author rse; state Exp; branches; next 1.56; 1.56 date 2001.03.24.15.55.33; author rse; state Exp; branches; next 1.55; 1.55 date 2001.03.24.15.46.32; author rse; state Exp; branches; next 1.54; 1.54 date 2001.03.24.14.51.05; author rse; state Exp; branches; next 1.53; 1.53 date 2001.03.24.14.37.06; author rse; state Exp; branches; next 1.52; 1.52 date 2001.03.24.14.27.29; author rse; state Exp; branches; next 1.51; 1.51 date 2000.04.05.16.05.45; author rse; state Exp; branches; next 1.50; 1.50 date 2000.02.04.21.43.02; author rse; state Exp; branches; next 1.49; 1.49 date 99.12.30.21.59.01; author rse; state Exp; branches; next 1.48; 1.48 date 99.11.09.08.11.32; author rse; state Exp; branches; next 1.47; 1.47 date 99.11.01.10.27.21; author rse; state Exp; branches; next 1.46; 1.46 date 99.10.31.11.46.13; author rse; state Exp; branches 1.46.2.1; next 1.45; 1.45 date 99.10.26.14.56.39; author rse; state Exp; branches; next 1.44; 1.44 date 99.10.26.14.54.06; author rse; state Exp; branches; next 1.43; 1.43 date 99.10.26.14.53.42; author rse; state Exp; branches; next 1.42; 1.42 date 99.10.26.14.53.13; author rse; state Exp; branches; next 1.41; 1.41 date 99.10.19.14.40.25; author rse; state Exp; branches; next 1.40; 1.40 date 99.09.19.10.13.25; author rse; state Exp; branches; next 1.39; 1.39 date 99.09.17.08.01.56; author rse; state Exp; branches; next 1.38; 1.38 date 99.08.31.11.24.58; author rse; state Exp; branches; next 1.37; 1.37 date 99.08.29.16.49.30; author rse; state Exp; branches; next 1.36; 1.36 date 99.08.29.16.43.32; author rse; state Exp; branches; next 1.35; 1.35 date 99.08.29.11.35.54; author rse; state Exp; branches; next 1.34; 1.34 date 99.08.21.12.16.14; author rse; state Exp; branches; next 1.33; 1.33 date 99.08.21.12.06.07; author rse; state Exp; branches; next 1.32; 1.32 date 99.08.20.07.02.37; author rse; state Exp; branches; next 1.31; 1.31 date 99.08.19.15.08.53; author rse; state Exp; branches; next 1.30; 1.30 date 99.08.17.09.35.21; author rse; state Exp; branches; next 1.29; 1.29 date 99.08.17.08.08.36; author rse; state Exp; branches; next 1.28; 1.28 date 99.08.15.13.25.00; author rse; state Exp; branches; next 1.27; 1.27 date 99.08.11.09.05.38; author rse; state Exp; branches; next 1.26; 1.26 date 99.08.02.12.26.10; author rse; state Exp; branches 1.26.2.1; next 1.25; 1.25 date 99.07.30.07.13.59; author rse; state Exp; branches; next 1.24; 1.24 date 99.07.30.06.19.42; author rse; state Exp; branches; next 1.23; 1.23 date 99.07.23.16.27.37; author rse; state Exp; branches; next 1.22; 1.22 date 99.07.22.14.55.10; author rse; state Exp; branches; next 1.21; 1.21 date 99.07.16.11.40.11; author rse; state Exp; branches; next 1.20; 1.20 date 99.07.16.08.17.19; author rse; state Exp; branches; next 1.19; 1.19 date 99.07.15.16.36.41; author rse; state Exp; branches; next 1.18; 1.18 date 99.07.15.15.27.58; author rse; state Exp; branches; next 1.17; 1.17 date 99.07.15.15.04.57; author rse; state Exp; branches; next 1.16; 1.16 date 99.07.15.13.59.35; author rse; state Exp; branches; next 1.15; 1.15 date 99.07.15.09.47.23; author rse; state Exp; branches; next 1.14; 1.14 date 99.07.14.18.53.14; author rse; state Exp; branches; next 1.13; 1.13 date 99.07.14.06.13.24; author rse; state Exp; branches; next 1.12; 1.12 date 99.07.10.15.14.47; author rse; state Exp; branches; next 1.11; 1.11 date 99.07.10.14.21.18; author rse; state Exp; branches; next 1.10; 1.10 date 99.07.09.08.06.41; author rse; state Exp; branches; next 1.9; 1.9 date 99.07.08.15.01.18; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.08.12.27.26; author rse; state Exp; branches; next 1.7; 1.7 date 99.07.08.10.34.02; author rse; state Exp; branches; next 1.6; 1.6 date 99.07.08.10.22.34; author rse; state Exp; branches; next 1.5; 1.5 date 99.07.08.10.19.11; author rse; state Exp; branches; next 1.4; 1.4 date 99.07.08.10.07.31; author rse; state Exp; branches; next 1.3; 1.3 date 99.07.08.09.41.00; author rse; state Exp; branches; next 1.2; 1.2 date 99.07.04.13.36.38; author rse; state Exp; branches; next 1.1; 1.1 date 99.07.04.12.17.32; author rse; state Exp; branches; next ; 1.46.2.1 date 99.11.01.10.25.02; author rse; state Exp; branches; next 1.46.2.2; 1.46.2.2 date 2000.02.04.22.07.18; author rse; state Exp; branches; next ; 1.26.2.1 date 99.08.31.08.32.18; author rse; state Exp; branches; next ; desc @@ 1.69 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 . ** ** pthread.c: POSIX Thread ("Pthread") API for Pth */ /* ``The nice thing about standards is that there are so many to choose from. And if you really don't like all the standards you just have to wait another year until the one arises you are looking for'' -- Tannenbaum, 'Introduction to Computer Networks' */ /* ** HEADER STUFF */ /* * Include our own Pthread and then the private Pth header. * The order here is very important to get correct namespace hiding! */ #define _PTHREAD_PRIVATE #include "pthread.h" #include "pth_p.h" #undef _PTHREAD_PRIVATE /* general success return value */ #ifdef OK #undef OK #endif #define OK 0 /* ** GLOBAL STUFF */ static void pthread_shutdown(void) { pth_kill(); return; } static int pthread_initialized = FALSE; #define pthread_initialize() \ do { \ if (pthread_initialized == FALSE) { \ pthread_initialized = TRUE; \ pth_init(); \ atexit(pthread_shutdown); \ } \ } while (0) /* ** THREAD ATTRIBUTE ROUTINES */ int pthread_attr_init(pthread_attr_t *attr) { pth_attr_t na; pthread_initialize(); if (attr == NULL) return pth_error(EINVAL, EINVAL); if ((na = pth_attr_new()) == NULL) return errno; (*attr) = (pthread_attr_t)na; return OK; } int pthread_attr_destroy(pthread_attr_t *attr) { pth_attr_t na; if (attr == NULL || *attr == NULL) return pth_error(EINVAL, EINVAL); na = (pth_attr_t)(*attr); pth_attr_destroy(na); *attr = NULL; return OK; } int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched) { if (attr == NULL || inheritsched == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *schedparam) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *schedparam) { if (attr == NULL || schedparam == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_setschedpolicy(pthread_attr_t *attr, int schedpolicy) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *schedpolicy) { if (attr == NULL || schedpolicy == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_setscope(pthread_attr_t *attr, int scope) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_getscope(const pthread_attr_t *attr, int *scope) { if (attr == NULL || scope == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) { if (attr == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_set((pth_attr_t)(*attr), PTH_ATTR_STACK_SIZE, (unsigned int)stacksize)) return errno; return OK; } int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) { if (attr == NULL || stacksize == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_get((pth_attr_t)(*attr), PTH_ATTR_STACK_SIZE, (unsigned int *)stacksize)) return errno; return OK; } int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr) { if (attr == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_set((pth_attr_t)(*attr), PTH_ATTR_STACK_ADDR, (char *)stackaddr)) return errno; return OK; } int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) { if (attr == NULL || stackaddr == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_get((pth_attr_t)(*attr), PTH_ATTR_STACK_ADDR, (char **)stackaddr)) return errno; return OK; } int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { int s; if (attr == NULL) return pth_error(EINVAL, EINVAL); if (detachstate == PTHREAD_CREATE_DETACHED) s = FALSE; else if (detachstate == PTHREAD_CREATE_JOINABLE) s = TRUE; else return pth_error(EINVAL, EINVAL); if (!pth_attr_set((pth_attr_t)(*attr), PTH_ATTR_JOINABLE, s)) return errno; return OK; } int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) { int s; if (attr == NULL || detachstate == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_get((pth_attr_t)(*attr), PTH_ATTR_JOINABLE, &s)) return errno; if (s == TRUE) *detachstate = PTHREAD_CREATE_JOINABLE; else *detachstate = PTHREAD_CREATE_DETACHED; return OK; } int pthread_attr_setguardsize(pthread_attr_t *attr, int stacksize) { if (attr == NULL || stacksize < 0) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_getguardsize(const pthread_attr_t *attr, int *stacksize) { if (attr == NULL || stacksize == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_attr_setname_np(pthread_attr_t *attr, char *name) { if (attr == NULL || name == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_set((pth_attr_t)(*attr), PTH_ATTR_NAME, name)) return errno; return OK; } int pthread_attr_getname_np(const pthread_attr_t *attr, char **name) { if (attr == NULL || name == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_get((pth_attr_t)(*attr), PTH_ATTR_NAME, name)) return errno; return OK; } int pthread_attr_setprio_np(pthread_attr_t *attr, int prio) { if (attr == NULL || (prio < PTH_PRIO_MIN || prio > PTH_PRIO_MAX)) return pth_error(EINVAL, EINVAL); if (!pth_attr_set((pth_attr_t)(*attr), PTH_ATTR_PRIO, prio)) return errno; return OK; } int pthread_attr_getprio_np(const pthread_attr_t *attr, int *prio) { if (attr == NULL || prio == NULL) return pth_error(EINVAL, EINVAL); if (!pth_attr_get((pth_attr_t)(*attr), PTH_ATTR_PRIO, prio)) return errno; return OK; } /* ** THREAD ROUTINES */ int pthread_create( pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { pth_attr_t na; pthread_initialize(); if (thread == NULL || start_routine == NULL) return pth_error(EINVAL, EINVAL); if (pth_ctrl(PTH_CTRL_GETTHREADS) >= PTHREAD_THREADS_MAX) return pth_error(EAGAIN, EAGAIN); if (attr != NULL) na = (pth_attr_t)(*attr); else na = PTH_ATTR_DEFAULT; *thread = (pthread_t)pth_spawn(na, start_routine, arg); if (*thread == NULL) return pth_error(EAGAIN, EAGAIN); return OK; } int __pthread_detach(pthread_t thread) { pth_attr_t na; if (thread == NULL) return pth_error(EINVAL, EINVAL); if ((na = pth_attr_of((pth_t)thread)) == NULL) return errno; if (!pth_attr_set(na, PTH_ATTR_JOINABLE, FALSE)) return errno; pth_attr_destroy(na); return OK; } pthread_t pthread_self(void) { pthread_initialize(); return (pthread_t)pth_self(); } int pthread_equal(pthread_t t1, pthread_t t2) { return (t1 == t2); } int pthread_yield_np(void) { pthread_initialize(); pth_yield(NULL); return OK; } void pthread_exit(void *value_ptr) { pthread_initialize(); pth_exit(value_ptr); return; } int pthread_join(pthread_t thread, void **value_ptr) { pthread_initialize(); if (!pth_join((pth_t)thread, value_ptr)) return errno; if (value_ptr != NULL) if (*value_ptr == PTH_CANCELED) *value_ptr = PTHREAD_CANCELED; return OK; } int pthread_once( pthread_once_t *once_control, void (*init_routine)(void)) { pthread_initialize(); if (once_control == NULL || init_routine == NULL) return pth_error(EINVAL, EINVAL); if (*once_control != 1) init_routine(); *once_control = 1; return OK; } int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) { pthread_initialize(); return pth_sigmask(how, set, oset); } int pthread_kill(pthread_t thread, int sig) { if (!pth_raise((pth_t)thread, sig)) return errno; return OK; } /* ** CONCURRENCY ROUTINES ** ** We just have to provide the interface, because SUSv2 says: ** "The pthread_setconcurrency() function allows an application to ** inform the threads implementation of its desired concurrency ** level, new_level. The actual level of concurrency provided by the ** implementation as a result of this function call is unspecified." */ static int pthread_concurrency = 0; int pthread_getconcurrency(void) { return pthread_concurrency; } int pthread_setconcurrency(int new_level) { if (new_level < 0) return pth_error(EINVAL, EINVAL); pthread_concurrency = new_level; return OK; } /* ** CONTEXT ROUTINES */ int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) { pthread_initialize(); if (!pth_key_create((pth_key_t *)key, destructor)) return errno; return OK; } int pthread_key_delete(pthread_key_t key) { if (!pth_key_delete((pth_key_t)key)) return errno; return OK; } int pthread_setspecific(pthread_key_t key, const void *value) { if (!pth_key_setdata((pth_key_t)key, value)) return errno; return OK; } void *pthread_getspecific(pthread_key_t key) { return pth_key_getdata((pth_key_t)key); } /* ** CANCEL ROUTINES */ int pthread_cancel(pthread_t thread) { if (!pth_cancel((pth_t)thread)) return errno; return OK; } void pthread_testcancel(void) { pth_cancel_point(); return; } int pthread_setcancelstate(int state, int *oldstate) { int s, os; if (oldstate != NULL) { pth_cancel_state(0, &os); if (os & PTH_CANCEL_ENABLE) *oldstate = PTHREAD_CANCEL_ENABLE; else *oldstate = PTHREAD_CANCEL_DISABLE; } if (state != 0) { pth_cancel_state(0, &s); if (state == PTHREAD_CANCEL_ENABLE) { s |= PTH_CANCEL_ENABLE; s &= ~(PTH_CANCEL_DISABLE); } else { s |= PTH_CANCEL_DISABLE; s &= ~(PTH_CANCEL_ENABLE); } pth_cancel_state(s, NULL); } return OK; } int pthread_setcanceltype(int type, int *oldtype) { int t, ot; if (oldtype != NULL) { pth_cancel_state(0, &ot); if (ot & PTH_CANCEL_DEFERRED) *oldtype = PTHREAD_CANCEL_DEFERRED; else *oldtype = PTHREAD_CANCEL_ASYNCHRONOUS; } if (type != 0) { pth_cancel_state(0, &t); if (type == PTHREAD_CANCEL_DEFERRED) { t |= PTH_CANCEL_DEFERRED; t &= ~(PTH_CANCEL_ASYNCHRONOUS); } else { t |= PTH_CANCEL_ASYNCHRONOUS; t &= ~(PTH_CANCEL_DEFERRED); } pth_cancel_state(t, NULL); } return OK; } /* ** SCHEDULER ROUTINES */ int pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param) { /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param) { /* not supported */ return pth_error(ENOSYS, ENOSYS); } /* ** CLEANUP ROUTINES */ void pthread_cleanup_push(void (*routine)(void *), void *arg) { pthread_initialize(); pth_cleanup_push(routine, arg); return; } void pthread_cleanup_pop(int execute) { pth_cleanup_pop(execute); return; } /* ** AT-FORK SUPPORT */ struct pthread_atfork_st { void (*prepare)(void); void (*parent)(void); void (*child)(void); }; static struct pthread_atfork_st pthread_atfork_info[PTH_ATFORK_MAX]; static int pthread_atfork_idx = 0; static void pthread_atfork_cb_prepare(void *_info) { struct pthread_atfork_st *info = (struct pthread_atfork_st *)_info; info->prepare(); return; } static void pthread_atfork_cb_parent(void *_info) { struct pthread_atfork_st *info = (struct pthread_atfork_st *)_info; info->parent(); return; } static void pthread_atfork_cb_child(void *_info) { struct pthread_atfork_st *info = (struct pthread_atfork_st *)_info; info->child(); return; } int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) { struct pthread_atfork_st *info; if (pthread_atfork_idx > PTH_ATFORK_MAX-1) return pth_error(ENOMEM, ENOMEM); info = &pthread_atfork_info[pthread_atfork_idx++]; info->prepare = prepare; info->parent = parent; info->child = child; if (!pth_atfork_push(pthread_atfork_cb_prepare, pthread_atfork_cb_parent, pthread_atfork_cb_child, info)) return errno; return OK; } /* ** MUTEX ATTRIBUTE ROUTINES */ int pthread_mutexattr_init(pthread_mutexattr_t *attr) { pthread_initialize(); if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *attr, int *prioceiling) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_getprotocol(pthread_mutexattr_t *attr, int *protocol) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } /* ** MUTEX ROUTINES */ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { pth_mutex_t *m; pthread_initialize(); if (mutex == NULL) return pth_error(EINVAL, EINVAL); if ((m = (pth_mutex_t *)malloc(sizeof(pth_mutex_t))) == NULL) return errno; if (!pth_mutex_init(m)) return errno; (*mutex) = (pthread_mutex_t)m; return OK; } int pthread_mutex_destroy(pthread_mutex_t *mutex) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); free(*mutex); *mutex = NULL; return OK; } int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutex_getprioceiling(pthread_mutex_t *mutex, int *prioceiling) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_mutex_lock(pthread_mutex_t *mutex) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; if (!pth_mutex_acquire((pth_mutex_t *)(*mutex), FALSE, NULL)) return errno; return OK; } int pthread_mutex_trylock(pthread_mutex_t *mutex) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; if (!pth_mutex_acquire((pth_mutex_t *)(*mutex), TRUE, NULL)) return errno; return OK; } int pthread_mutex_unlock(pthread_mutex_t *mutex) { if (mutex == NULL) return pth_error(EINVAL, EINVAL); if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; if (!pth_mutex_release((pth_mutex_t *)(*mutex))) return errno; return OK; } /* ** LOCK ATTRIBUTE ROUTINES */ int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { pthread_initialize(); if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } /* ** LOCK ROUTINES */ int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { pth_rwlock_t *rw; pthread_initialize(); if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if ((rw = (pth_rwlock_t *)malloc(sizeof(pth_rwlock_t))) == NULL) return errno; if (!pth_rwlock_init(rw)) return errno; (*rwlock) = (pthread_rwlock_t)rw; return OK; } int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); free(*rwlock); *rwlock = NULL; return OK; } int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) if (pthread_rwlock_init(rwlock, NULL) != OK) return errno; if (!pth_rwlock_acquire((pth_rwlock_t *)(*rwlock), PTH_RWLOCK_RD, FALSE, NULL)) return errno; return OK; } int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) if (pthread_rwlock_init(rwlock, NULL) != OK) return errno; if (!pth_rwlock_acquire((pth_rwlock_t *)(*rwlock), PTH_RWLOCK_RD, TRUE, NULL)) return errno; return OK; } int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) if (pthread_rwlock_init(rwlock, NULL) != OK) return errno; if (!pth_rwlock_acquire((pth_rwlock_t *)(*rwlock), PTH_RWLOCK_RW, FALSE, NULL)) return errno; return OK; } int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) if (pthread_rwlock_init(rwlock, NULL) != OK) return errno; if (!pth_rwlock_acquire((pth_rwlock_t *)(*rwlock), PTH_RWLOCK_RW, TRUE, NULL)) return errno; return OK; } int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { if (rwlock == NULL) return pth_error(EINVAL, EINVAL); if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) if (pthread_rwlock_init(rwlock, NULL) != OK) return errno; if (!pth_rwlock_release((pth_rwlock_t *)(*rwlock))) return errno; return OK; } /* ** CONDITION ATTRIBUTE ROUTINES */ int pthread_condattr_init(pthread_condattr_t *attr) { pthread_initialize(); if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_condattr_destroy(pthread_condattr_t *attr) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } int pthread_condattr_getpshared(pthread_condattr_t *attr, int *pshared) { if (attr == NULL) return pth_error(EINVAL, EINVAL); /* not supported */ return pth_error(ENOSYS, ENOSYS); } /* ** CONDITION ROUTINES */ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { pth_cond_t *cn; pthread_initialize(); if (cond == NULL) return pth_error(EINVAL, EINVAL); if ((cn = (pth_cond_t *)malloc(sizeof(pth_cond_t))) == NULL) return errno; if (!pth_cond_init(cn)) return errno; (*cond) = (pthread_cond_t)cn; return OK; } int pthread_cond_destroy(pthread_cond_t *cond) { if (cond == NULL) return pth_error(EINVAL, EINVAL); free(*cond); *cond = NULL; return OK; } int pthread_cond_broadcast(pthread_cond_t *cond) { if (cond == NULL) return pth_error(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) if (pthread_cond_init(cond, NULL) != OK) return errno; if (!pth_cond_notify((pth_cond_t *)(*cond), TRUE)) return errno; return OK; } int pthread_cond_signal(pthread_cond_t *cond) { if (cond == NULL) return pth_error(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) if (pthread_cond_init(cond, NULL) != OK) return errno; if (!pth_cond_notify((pth_cond_t *)(*cond), FALSE)) return errno; return OK; } int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { if (cond == NULL || mutex == NULL) return pth_error(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) if (pthread_cond_init(cond, NULL) != OK) return errno; if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; if (!pth_cond_await((pth_cond_t *)(*cond), (pth_mutex_t *)(*mutex), NULL)) return errno; return OK; } int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; if (cond == NULL || mutex == NULL || abstime == NULL) return pth_error(EINVAL, EINVAL); #ifdef __amigaos__ if (abstime->ts_sec < 0 || abstime->ts_nsec < 0 || abstime->ts_nsec >= 1000000000) #else if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) #endif return pth_error(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) if (pthread_cond_init(cond, NULL) != OK) return errno; if (*mutex == PTHREAD_MUTEX_INITIALIZER) if (pthread_mutex_init(mutex, NULL) != OK) return errno; ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, #ifdef __amigaos__ pth_time(abstime->ts_sec, (abstime->ts_nsec)/1000) #else pth_time(abstime->tv_sec, (abstime->tv_nsec)/1000) #endif ); if (!pth_cond_await((pth_cond_t *)(*cond), (pth_mutex_t *)(*mutex), ev)) return errno; if (pth_event_status(ev) == PTH_STATUS_OCCURRED) return ETIMEDOUT; return OK; } /* ** POSIX 1003.1j */ int pthread_abort(pthread_t thread) { if (!pth_abort((pth_t)thread)) return errno; return OK; } /* ** THREAD-SAFE REPLACEMENT FUNCTIONS */ pid_t __pthread_fork(void) { pthread_initialize(); return pth_fork(); } unsigned int __pthread_sleep(unsigned int sec) { pthread_initialize(); return pth_sleep(sec); } int __pthread_system(const char *cmd) { pthread_initialize(); return pth_system(cmd); } int __pthread_nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { pthread_initialize(); return pth_nanosleep(rqtp, rmtp); } int __pthread_usleep(unsigned int sec) { pthread_initialize(); return pth_usleep(sec); } int __pthread_sigwait(const sigset_t *set, int *sig) { pthread_initialize(); return pth_sigwait(set, sig); } pid_t __pthread_waitpid(pid_t pid, int *status, int options) { pthread_initialize(); return pth_waitpid(pid, status, options); } int __pthread_connect(int s, struct sockaddr *addr, socklen_t addrlen) { pthread_initialize(); return pth_connect(s, addr, addrlen); } int __pthread_accept(int s, struct sockaddr *addr, socklen_t *addrlen) { pthread_initialize(); return pth_accept(s, addr, addrlen); } int __pthread_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { pthread_initialize(); return pth_select(nfds, readfds, writefds, exceptfds, timeout); } int __pthread_poll(struct pollfd *pfd, nfds_t nfd, int timeout) { pthread_initialize(); return pth_poll(pfd, nfd, timeout); } ssize_t __pthread_read(int fd, void *buf, size_t nbytes) { pthread_initialize(); return pth_read(fd, buf, nbytes); } ssize_t __pthread_write(int fd, const void *buf, size_t nbytes) { pthread_initialize(); return pth_write(fd, buf, nbytes); } ssize_t __pthread_readv(int fd, const struct iovec *piovec, int iocnt) { pthread_initialize(); return pth_readv(fd, piovec, iocnt); } ssize_t __pthread_writev(int fd, const struct iovec *piovec, int iocnt) { pthread_initialize(); return pth_writev(fd, piovec, iocnt); } ssize_t __pthread_recv(int fd, void *buf, size_t nbytes, int flags) { pthread_initialize(); return pth_recv(fd, buf, nbytes, flags); } ssize_t __pthread_send(int fd, const void *buf, size_t nbytes, int flags) { pthread_initialize(); return pth_send(fd, buf, nbytes, flags); } ssize_t __pthread_recvfrom(int fd, void *buf, size_t nbytes, int flags, struct sockaddr *from, socklen_t *fromlen) { pthread_initialize(); return pth_recvfrom(fd, buf, nbytes, flags, from, fromlen); } ssize_t __pthread_sendto(int fd, const void *buf, size_t nbytes, int flags, const struct sockaddr *to, socklen_t tolen) { pthread_initialize(); return pth_sendto(fd, buf, nbytes, flags, to, tolen); } ssize_t __pthread_pread(int fd, void *buf, size_t nbytes, off_t offset) { pthread_initialize(); return pth_pread(fd, buf, nbytes, offset); } ssize_t __pthread_pwrite(int fd, const void *buf, size_t nbytes, off_t offset) { pthread_initialize(); return pth_pwrite(fd, buf, nbytes, offset); } @ 1.68 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.67 log @Adjusted all copyright messages for new year 2005. @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.66 log @Fixed prototype for pthread_attr_setschedparam(3) from to use a "const struct sched_param *" argument to comply with SUSv2/v3. Submitted by: Rafael Ávila de Espíndola @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.65 log @Adjusted all copyright messages for new year 2004. @ text @d118 1 a118 1 int pthread_attr_setschedparam(pthread_attr_t *attr, struct sched_param *schedparam) @ 1.64 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.63 log @Added soft syscall mapping for nanosleep(3) and usleep(3) functions also to the Pthread API. @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.62 log @1. The function "int pth_event_occurred(pth_event_t)" was replaced with "pth_status_t pth_event_status(pth_event_t)" where pth_status_t can have values of PTH_STATUS_PENDING (replacing the old FALSE return value of pth_event_occurred), PTH_STATUS_OCCURRED (replacing the old TRUE return value of pth_event_occurred), and PTH_STATUS_FAILED (a new return value indicating an error in processing the event). This was scheduler/event-manager errors can be indicated which happended while processing the event. For backward compatibility reasons, a macro pth_event_occurred() was added. This will be removed soon. 2. Use the new PTH_STATUS_FAILED event status in the scheduler's event-manager for filedescriptor events if the internal select(2) call returned with an error. Additionally this PTH_STATUS_FAILED is recognized by the high-level API functions (pth_select, etc) and produce the necessary POSIX conforming return codes (usually -1 and errno == EBADF). Parts submitted by: Thanh Luu @ text @d1059 12 @ 1.61 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 @d1021 1 a1021 1 if (pth_event_occurred(ev)) @ 1.60 log @Added pth_nanosleep() function. Obtained from: NetBSD, Nick Hudson @ text @d83 1 a83 1 return_errno(EINVAL, EINVAL); d95 1 a95 1 return_errno(EINVAL, EINVAL); d105 1 a105 1 return_errno(EINVAL, EINVAL); d107 1 a107 1 return_errno(ENOSYS, ENOSYS); d113 1 a113 1 return_errno(EINVAL, EINVAL); d115 1 a115 1 return_errno(ENOSYS, ENOSYS); d121 1 a121 1 return_errno(EINVAL, EINVAL); d123 1 a123 1 return_errno(ENOSYS, ENOSYS); d129 1 a129 1 return_errno(EINVAL, EINVAL); d131 1 a131 1 return_errno(ENOSYS, ENOSYS); d137 1 a137 1 return_errno(EINVAL, EINVAL); d139 1 a139 1 return_errno(ENOSYS, ENOSYS); d145 1 a145 1 return_errno(EINVAL, EINVAL); d147 1 a147 1 return_errno(ENOSYS, ENOSYS); d153 1 a153 1 return_errno(EINVAL, EINVAL); d155 1 a155 1 return_errno(ENOSYS, ENOSYS); d161 1 a161 1 return_errno(EINVAL, EINVAL); d163 1 a163 1 return_errno(ENOSYS, ENOSYS); d169 1 a169 1 return_errno(EINVAL, EINVAL); d178 1 a178 1 return_errno(EINVAL, EINVAL); d187 1 a187 1 return_errno(EINVAL, EINVAL); d196 1 a196 1 return_errno(EINVAL, EINVAL); d207 1 a207 1 return_errno(EINVAL, EINVAL); d213 1 a213 1 return_errno(EINVAL, EINVAL); d224 1 a224 1 return_errno(EINVAL, EINVAL); d237 1 a237 1 return_errno(EINVAL, EINVAL); d239 1 a239 1 return_errno(ENOSYS, ENOSYS); d245 1 a245 1 return_errno(EINVAL, EINVAL); d247 1 a247 1 return_errno(ENOSYS, ENOSYS); d253 1 a253 1 return_errno(EINVAL, EINVAL); d262 1 a262 1 return_errno(EINVAL, EINVAL); d271 1 a271 1 return_errno(EINVAL, EINVAL); d280 1 a280 1 return_errno(EINVAL, EINVAL); d298 1 a298 1 return_errno(EINVAL, EINVAL); d300 1 a300 1 return_errno(EAGAIN, EAGAIN); d307 1 a307 1 return_errno(EAGAIN, EAGAIN); d316 1 a316 1 return_errno(EINVAL, EINVAL); d366 1 a366 1 return_errno(EINVAL, EINVAL); d406 1 a406 1 return_errno(EINVAL, EINVAL); d518 1 a518 1 return_errno(ENOSYS, ENOSYS); d524 1 a524 1 return_errno(ENOSYS, ENOSYS); d580 1 a580 1 return_errno(ENOMEM, ENOMEM); d600 1 a600 1 return_errno(EINVAL, EINVAL); d608 1 a608 1 return_errno(EINVAL, EINVAL); d616 1 a616 1 return_errno(EINVAL, EINVAL); d618 1 a618 1 return_errno(ENOSYS, ENOSYS); d624 1 a624 1 return_errno(EINVAL, EINVAL); d626 1 a626 1 return_errno(ENOSYS, ENOSYS); d632 1 a632 1 return_errno(EINVAL, EINVAL); d634 1 a634 1 return_errno(ENOSYS, ENOSYS); d640 1 a640 1 return_errno(EINVAL, EINVAL); d642 1 a642 1 return_errno(ENOSYS, ENOSYS); d648 1 a648 1 return_errno(EINVAL, EINVAL); d650 1 a650 1 return_errno(ENOSYS, ENOSYS); d656 1 a656 1 return_errno(EINVAL, EINVAL); d658 1 a658 1 return_errno(ENOSYS, ENOSYS); d664 1 a664 1 return_errno(EINVAL, EINVAL); d666 1 a666 1 return_errno(ENOSYS, ENOSYS); d672 1 a672 1 return_errno(EINVAL, EINVAL); d674 1 a674 1 return_errno(ENOSYS, ENOSYS); d687 1 a687 1 return_errno(EINVAL, EINVAL); d699 1 a699 1 return_errno(EINVAL, EINVAL); d708 1 a708 1 return_errno(EINVAL, EINVAL); d713 1 a713 1 return_errno(ENOSYS, ENOSYS); d719 1 a719 1 return_errno(EINVAL, EINVAL); d724 1 a724 1 return_errno(ENOSYS, ENOSYS); d730 1 a730 1 return_errno(EINVAL, EINVAL); d742 1 a742 1 return_errno(EINVAL, EINVAL); d754 1 a754 1 return_errno(EINVAL, EINVAL); d771 1 a771 1 return_errno(EINVAL, EINVAL); d779 1 a779 1 return_errno(EINVAL, EINVAL); d787 1 a787 1 return_errno(EINVAL, EINVAL); d789 1 a789 1 return_errno(ENOSYS, ENOSYS); d795 1 a795 1 return_errno(EINVAL, EINVAL); d797 1 a797 1 return_errno(ENOSYS, ENOSYS); d810 1 a810 1 return_errno(EINVAL, EINVAL); d822 1 a822 1 return_errno(EINVAL, EINVAL); d831 1 a831 1 return_errno(EINVAL, EINVAL); d843 1 a843 1 return_errno(EINVAL, EINVAL); d855 1 a855 1 return_errno(EINVAL, EINVAL); d867 1 a867 1 return_errno(EINVAL, EINVAL); d879 1 a879 1 return_errno(EINVAL, EINVAL); d896 1 a896 1 return_errno(EINVAL, EINVAL); d904 1 a904 1 return_errno(EINVAL, EINVAL); d912 1 a912 1 return_errno(EINVAL, EINVAL); d914 1 a914 1 return_errno(ENOSYS, ENOSYS); d920 1 a920 1 return_errno(EINVAL, EINVAL); d922 1 a922 1 return_errno(ENOSYS, ENOSYS); d935 1 a935 1 return_errno(EINVAL, EINVAL); d947 1 a947 1 return_errno(EINVAL, EINVAL); d956 1 a956 1 return_errno(EINVAL, EINVAL); d968 1 a968 1 return_errno(EINVAL, EINVAL); d980 1 a980 1 return_errno(EINVAL, EINVAL); d999 1 a999 1 return_errno(EINVAL, EINVAL); d1005 1 a1005 1 return_errno(EINVAL, EINVAL); @ 1.59 log @remove trailing whitespaces @ text @a991 7 #ifndef HAVE_STRUCT_TIMESPEC struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; #endif @ 1.58 log @The manual page stated that system(3) is supported in the "Soft System Call Mapping", but in fact it was forgotten in the implementation. Submitted by: Jonathan Schilling @ text @d388 1 a388 1 ** @ 1.57 log @bump copyright year @ text @d1060 6 @ 1.56 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.55 log @*** empty log message *** @ text @d387 25 @ 1.54 log @*** empty log message *** @ text @d110 1 a110 1 int pthread_attr_getinheritsched(pthread_attr_t *attr, int *inheritsched) d126 1 a126 1 int pthread_attr_getschedparam(pthread_attr_t *attr, struct sched_param *schedparam) d142 1 a142 1 int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *schedpolicy) d158 1 a158 1 int pthread_attr_getscope(pthread_attr_t *attr, int *scope) d175 1 a175 1 int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize) d193 1 a193 1 int pthread_attr_getstackaddr(pthread_attr_t *attr, void **stackaddr) d219 1 a219 1 int pthread_attr_getdetachstate(pthread_attr_t *attr, int *detachstate) d234 16 d259 1 a259 1 int pthread_attr_getname_np(pthread_attr_t *attr, char **name) d277 1 a277 1 int pthread_attr_getprio_np(pthread_attr_t *attr, int *prio) @ 1.53 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.52 log @*** empty log message *** @ text @d1092 1 a1092 1 ssize_t __pthread_recvfrom(int fd, void *buf, size_t nbytes, int flags, struct sockaddr *from, int *fromlen) d1098 1 a1098 1 ssize_t __pthread_sendto(int fd, const void *buf, size_t nbytes, int flags, struct sockaddr *to, int tolen) @ 1.51 log @*** empty log message *** @ text @d1080 24 @ 1.50 log @*** empty log message *** @ text @a991 1 @ 1.49 log @*** empty log message *** @ text @d987 2 @ 1.48 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.47 log @*** empty log message *** @ text @d25 1 a25 1 /* ``The nice thing about standards is that d30 1 a30 1 -- Tannenbaum, 'Introduction d74 1 a74 1 ** THREAD ATTRIBUTE ROUTINES d270 1 a270 1 /* d275 1 a275 1 pthread_t *thread, const pthread_attr_t *attr, d486 1 a486 1 /* d503 1 a503 1 /* d537 1 a537 1 d544 2 a545 2 if (!pth_atfork_push(pthread_atfork_cb_prepare, pthread_atfork_cb_parent, d551 1 a551 1 /* d722 1 a722 1 /* d759 1 a759 1 /* d847 1 a847 1 /* d884 1 a884 1 /* d958 1 a958 1 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, d978 1 a978 1 ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, d1042 1 a1042 1 int __pthread_select(int nfds, fd_set *readfds, fd_set *writefds, @ 1.46 log @*** empty log message *** @ text @d2 1 a2 2 ** pthread.c -- POSIX Thread ("pthread") API for Pth ** d22 2 @ 1.46.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** pthread.c: POSIX Thread ("Pthread") API for Pth @ 1.46.2.2 log @*** empty log message *** @ text @a986 2 if (pth_event_occurred(ev)) return ETIMEDOUT; @ 1.45 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.44 log @*** empty log message *** @ text @d46 3 a48 1 #ifndef OK a49 1 #endif @ 1.43 log @*** empty log message *** @ text @d32 8 a39 2 /* Include our own Pthread and then the private Pth header. The order here is very important to get correct namespace hiding! */ a43 4 /* ** HEADER STUFF */ @ 1.42 log @*** empty log message *** @ text @d32 2 a33 2 /* Include our own Pthread and then the Pth header. The order is important to get a correct namespace hiding! */ @ 1.41 log @*** empty log message *** @ text @d31 3 a33 1 /* include our own Pthread header */ d36 1 a37 3 /* include Pth and various other vendor headers */ #include "pth_p.h" @ 1.40 log @*** empty log message *** @ text @d1045 1 a1045 1 int __pthread_poll(struct pollfd *pfd, unsigned int nfd, int timeout) @ 1.39 log @*** empty log message *** @ text @d947 7 @ 1.38 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.37 log @*** empty log message *** @ text @d1019 1 a1019 1 int __pthread_connect(int s, struct sockaddr *addr, int addrlen) d1025 1 a1025 1 int __pthread_accept(int s, struct sockaddr *addr, int *addrlen) @ 1.36 log @*** empty log message *** @ text @d291 1 a291 1 int pthread_detach_I(pthread_t thread) @ 1.35 log @*** empty log message *** @ text @d995 1 a995 1 pid_t _pthread_fork(void) d1001 1 a1001 1 unsigned int _pthread_sleep(unsigned int sec) d1007 1 a1007 1 int _pthread_sigwait(const sigset_t *set, int *sig) d1013 1 a1013 1 pid_t _pthread_waitpid(pid_t pid, int *status, int options) d1019 1 a1019 1 int _pthread_connect(int s, struct sockaddr *addr, int addrlen) d1025 1 a1025 1 int _pthread_accept(int s, struct sockaddr *addr, int *addrlen) d1031 1 a1031 1 int _pthread_select(int nfds, fd_set *readfds, fd_set *writefds, d1038 1 a1038 1 int _pthread_poll(struct pollfd *pfd, unsigned int nfd, int timeout) d1044 1 a1044 1 ssize_t _pthread_read(int fd, void *buf, size_t nbytes) d1050 1 a1050 1 ssize_t _pthread_write(int fd, const void *buf, size_t nbytes) d1056 1 a1056 1 ssize_t _pthread_readv(int fd, const struct iovec *piovec, int iocnt) d1062 1 a1062 1 ssize_t _pthread_writev(int fd, const struct iovec *piovec, int iocnt) d1068 1 a1068 1 ssize_t _pthread_pread(int fd, void *buf, size_t nbytes, off_t offset) d1074 1 a1074 1 ssize_t _pthread_pwrite(int fd, const void *buf, size_t nbytes, off_t offset) @ 1.34 log @*** empty log message *** @ text @d291 1 a291 1 int pthread_detach(pthread_t thread) @ 1.33 log @*** empty log message *** @ text @d316 1 a316 1 void pthread_yield_np(void) d320 1 a320 1 return; @ 1.32 log @*** empty log message *** @ text @d318 1 d325 1 d332 1 @ 1.31 log @*** empty log message *** @ text @d950 7 a956 1 if (cond == NULL || mutex == NULL) @ 1.30 log @*** empty log message *** @ text @d24 7 a30 1 @ 1.29 log @*** empty log message *** @ text @d25 1 a25 1 /* now include our own pthread header */ @ 1.28 log @*** empty log message *** @ text @d634 1 a634 1 if ((m = malloc(sizeof(pth_mutex_t))) == NULL) d757 1 a757 1 if ((rw = malloc(sizeof(pth_rwlock_t))) == NULL) d882 1 a882 1 if ((cn = malloc(sizeof(pth_cond_t))) == NULL) d1041 1 a1041 1 ssize_t _pthread_readv(int fd, const struct iovec *iovec, int iocnt) d1044 1 a1044 1 return pth_readv(fd, iovec, iocnt); d1047 1 a1047 1 ssize_t _pthread_writev(int fd, const struct iovec *iovec, int iocnt) d1050 1 a1050 1 return pth_writev(fd, iovec, iocnt); @ 1.27 log @*** empty log message *** @ text @a645 2 if (*mutex == PTHREAD_MUTEX_INITIALIZER) return OK; d647 1 a768 2 if (*rwlock == PTHREAD_RWLOCK_INITIALIZER) return OK; d770 1 a893 2 if (*cond == PTHREAD_COND_INITIALIZER) return OK; d895 1 @ 1.26 log @*** empty log message *** @ text @a24 14 /* protect us from vendor pthread stuff */ #define _PTHREAD_H_ #define _PTHREAD_H #define PTHREAD_H /* include Pth and various vendor headers */ #define PTH_SYSCALL_SOFT FALSE #include "pth_p.h" /* reverse protection hack */ #undef _PTHREAD_H_ #undef _PTHREAD_H #undef PTHREAD_H d29 3 @ 1.26.2.1 log @*** empty log message *** @ text @d657 2 a659 1 *mutex = NULL; d781 2 a783 1 *rwlock = NULL; d907 2 a909 1 *cond = NULL; @ 1.25 log @*** empty log message *** @ text @d1055 12 @ 1.24 log @*** empty log message *** @ text @d289 1 a289 1 na = PTH_ATTR_NULL; @ 1.23 log @*** empty log message *** @ text @d40 1 d42 1 d967 6 a972 1 pth_time(abstime->tv_sec, (abstime->tv_nsec)/1000)); @ 1.22 log @*** empty log message *** @ text @d2 1 a2 1 ** pthread.c -- POSIX Thread ("pthread") API for PTH @ 1.21 log @*** empty log message *** @ text @d1048 1 a1048 8 /* ** SPECIAL POSIX STUFF */ static pth_mutex_t pthread_pwrite_mutex = PTH_MUTEX_INIT; static pth_mutex_t pthread_pread_mutex = PTH_MUTEX_INIT; ssize_t _pthread_pwrite(int fd, const void *buf, size_t nbytes, off_t offset) d1050 2 a1051 12 ssize_t rc; if (!pth_mutex_acquire(&pthread_pwrite_mutex, FALSE, NULL)) return (-1); if (lseek(fd, offset, SEEK_SET) == -1) return (-1); rc = pth_write(fd, buf, nbytes); errno_preserve; if (!pth_mutex_release(&pthread_pwrite_mutex)) return (-1); errno_restore; return rc; d1054 1 a1054 1 ssize_t _pthread_pread(int fd, void *buf, size_t nbytes, off_t offset) d1056 2 a1057 12 ssize_t rc; if (!pth_mutex_acquire(&pthread_pread_mutex, FALSE, NULL)) return (-1); if (lseek(fd, offset, SEEK_SET) == -1) return (-1); rc = pth_read(fd, buf, nbytes); errno_preserve; if (!pth_mutex_release(&pthread_pread_mutex)) return (-1); errno_restore; return rc; @ 1.20 log @*** empty log message *** @ text @a992 6 int _pthread_usleep(unsigned int usec) { pthread_initialize(); return pth_usleep(usec); } @ 1.19 log @*** empty log message *** @ text @d66 1 a68 1 pthread_initialized = TRUE; \ @ 1.18 log @*** empty log message *** @ text @d335 3 a337 2 if (*value_ptr == PTH_CANCELED) *value_ptr = PTHREAD_CANCELED; @ 1.17 log @*** empty log message *** @ text @d61 1 a61 3 static void pthread_initialize(void) { static int init = 0; d63 8 a70 7 if (init == 0) { pth_init(); atexit(pthread_shutdown); init = 1; } return; } d988 1 d994 1 d1000 1 d1006 1 d1012 1 d1018 1 d1024 1 d1031 1 d1037 1 d1043 1 d1049 1 @ 1.16 log @*** empty log message *** @ text @a547 120 ** CONDITION ATTRIBUTE ROUTINES */ int pthread_condattr_init(pthread_condattr_t *attr) { pthread_initialize(); if (attr == NULL) return_errno(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_condattr_destroy(pthread_condattr_t *attr) { if (attr == NULL) return_errno(EINVAL, EINVAL); /* nothing to do for us */ return OK; } int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) { if (attr == NULL) return_errno(EINVAL, EINVAL); /* not supported */ return_errno(ENOSYS, ENOSYS); } int pthread_condattr_getpshared(pthread_condattr_t *attr, int *pshared) { if (attr == NULL) return_errno(EINVAL, EINVAL); /* not supported */ return_errno(ENOSYS, ENOSYS); } /* ** CONDITION ROUTINES */ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { pth_cond_t *cn; pthread_initialize(); if (cond == NULL) return_errno(EINVAL, EINVAL); if ((cn = malloc(sizeof(pth_cond_t))) == NULL) return errno; if (!pth_cond_init(cn)) return errno; (*cond) = (pthread_cond_t)cn; return OK; } int pthread_cond_destroy(pthread_cond_t *cond) { if (cond == NULL) return_errno(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) return OK; free(*cond); return OK; } int pthread_cond_broadcast(pthread_cond_t *cond) { if (cond == NULL) return_errno(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) pth_cond_init((pth_cond_t *)(*cond)); if (!pth_cond_notify((pth_cond_t *)(*cond), TRUE)) return errno; return OK; } int pthread_cond_signal(pthread_cond_t *cond) { if (cond == NULL) return_errno(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) pth_cond_init((pth_cond_t *)(*cond)); if (!pth_cond_notify((pth_cond_t *)(*cond), FALSE)) return errno; return OK; } int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { if (cond == NULL || mutex == NULL) return_errno(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) pth_cond_init((pth_cond_t *)(*cond)); if (*mutex == PTHREAD_MUTEX_INITIALIZER) pth_mutex_init((pth_mutex_t *)(*mutex)); if (!pth_cond_await((pth_cond_t *)(*cond), (pth_mutex_t *)(*mutex), NULL)) return errno; return OK; } int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; if (cond == NULL || mutex == NULL) return_errno(EINVAL, EINVAL); if (*cond == PTHREAD_COND_INITIALIZER) pth_cond_init((pth_cond_t *)(*cond)); if (*mutex == PTHREAD_MUTEX_INITIALIZER) pth_mutex_init((pth_mutex_t *)(*mutex)); ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, pth_time(abstime->tv_sec, (abstime->tv_nsec)/1000)); if (!pth_cond_await((pth_cond_t *)(*cond), (pth_mutex_t *)(*mutex), ev)) return errno; return OK; } /* d666 2 a667 1 pth_mutex_init((pth_mutex_t *)(*mutex)); d677 2 a678 1 pth_mutex_init((pth_mutex_t *)(*mutex)); d688 2 a689 1 pth_mutex_init((pth_mutex_t *)(*mutex)); d700 2 a701 1 pth_mutex_init((pth_mutex_t *)(*mutex)); d712 2 a713 1 pth_mutex_init((pth_mutex_t *)(*mutex)); d790 2 a791 1 pth_rwlock_init((pth_rwlock_t *)(*rwlock)); d802 2 a803 1 pth_rwlock_init((pth_rwlock_t *)(*rwlock)); d814 2 a815 1 pth_rwlock_init((pth_rwlock_t *)(*rwlock)); d826 2 a827 1 pth_rwlock_init((pth_rwlock_t *)(*rwlock)); d838 2 a839 1 pth_rwlock_init((pth_rwlock_t *)(*rwlock)); d844 127 @ 1.15 log @*** empty log message *** @ text @d336 2 @ 1.14 log @*** empty log message *** @ text @a331 7 int pthread_cancel(pthread_t thread) { if (!pth_cancel((pth_t)thread)) return errno; return OK; } d399 8 a406 1 int pthread_testcancel(void) d409 1 a409 1 return TRUE; @ 1.13 log @*** empty log message *** @ text @d332 7 d352 1 a352 1 if (*once_control != TRUE) d354 1 a354 1 *once_control = TRUE; @ 1.12 log @*** empty log message *** @ text @a593 11 pthread_cond_t _pthread_cond_init_static(void) { pth_cond_t *cn; pthread_initialize(); if ((cn = malloc(sizeof(pth_cond_t))) == NULL) return NULL; pth_cond_init(cn); return (pthread_cond_t)cn; } d598 2 d608 2 d619 2 d630 4 d647 4 a761 11 pthread_mutex_t _pthread_mutex_init_static(void) { pth_mutex_t *m; pthread_initialize(); if ((m = malloc(sizeof(pth_mutex_t))) == NULL) return NULL; pth_mutex_init(m); return (pthread_mutex_t)m; } d766 2 d776 2 d786 2 d796 2 d807 2 d818 2 a880 11 pthread_rwlock_t _pthread_rwlock_init_static(void) { pth_rwlock_t *rw; pthread_initialize(); if ((rw = malloc(sizeof(pth_rwlock_t))) == NULL) return NULL; pth_rwlock_init(rw); return (pthread_rwlock_t)rw; } d885 2 d895 2 d906 2 d917 2 d928 2 d939 2 @ 1.11 log @*** empty log message *** @ text @a980 6 int _pthread_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { return pth_select(nfds, readfds, writefds, exceptfds, timeout); } d989 11 @ 1.10 log @*** empty log message *** @ text @d31 1 @ 1.9 log @*** empty log message *** @ text @d980 6 @ 1.8 log @*** empty log message *** @ text @d941 11 d990 5 d1000 6 a1005 4 ssize_t _pthread_read(int fd, void *buf, size_t nbytes) { return pth_read(fd, buf, nbytes); } a1009 1 pth_mutex_t mutex = PTH_MUTEX_INIT; d1011 1 a1011 1 if (!pth_mutex_acquire(&mutex, FALSE, NULL)) d1017 1 a1017 1 if (!pth_mutex_release(&mutex)) a1025 1 pth_mutex_t mutex = PTH_MUTEX_INIT; d1027 1 a1027 1 if (!pth_mutex_acquire(&mutex, FALSE, NULL)) d1033 1 a1033 1 if (!pth_mutex_release(&mutex)) @ 1.7 log @*** empty log message *** @ text @d25 1 a25 1 /* make sure the vendor pthread.h header isn't included implicity */ @ 1.6 log @*** empty log message *** @ text @d30 1 a30 1 /* include PTH and various vendor headers */ @ 1.5 log @*** empty log message *** @ text @d7 1 a7 1 ** which can be found at http://www.engelschall.com/sw/pth/. @ 1.4 log @*** empty log message *** @ text @d6 1 a6 1 ** This file is part of PTH, a non-preemptive thread scheduling library @ 1.3 log @*** empty log message *** @ text @d989 34 @ 1.2 log @*** empty log message *** @ text @d490 48 @ 1.1 log @*** empty log message *** @ text @d103 1 a103 1 if (attr == NULL || *attr == NULL) d111 1 a111 1 if (attr == NULL || *attr == NULL || inheritsched == NULL) d119 1 a119 1 if (attr == NULL || *attr == NULL) d127 1 a127 1 if (attr == NULL || *attr == NULL || schedparam == NULL) d135 1 a135 1 if (attr == NULL || *attr == NULL) d143 1 a143 1 if (attr == NULL || *attr == NULL || schedpolicy == NULL) d151 1 a151 1 if (attr == NULL || *attr == NULL) d159 1 a159 1 if (attr == NULL || *attr == NULL || scope == NULL) d167 1 a167 1 if (attr == NULL || *attr == NULL) d176 1 a176 1 if (attr == NULL || *attr == NULL || stacksize == NULL) d185 1 a185 1 if (attr == NULL || *attr == NULL) d194 1 a194 1 if (attr == NULL || *attr == NULL || stackaddr == NULL) d205 1 a205 1 if (attr == NULL || *attr == NULL) d222 1 a222 1 if (attr == NULL || *attr == NULL || detachstate == NULL) d235 1 a235 1 if (attr == NULL || *attr == NULL || name == NULL) d244 1 a244 1 if (attr == NULL || *attr == NULL || name == NULL) d253 1 a253 1 if (attr == NULL || *attr == NULL || (prio < PTH_PRIO_MIN || prio > PTH_PRIO_MAX)) d262 1 a262 1 if (attr == NULL || *attr == NULL || prio == NULL) d409 1 a409 1 pth_cancel_state(NULL, &os); d416 1 a416 1 pth_cancel_state(NULL, &s); d435 1 a435 1 pth_cancel_state(NULL, &ot); d442 1 a442 1 pth_cancel_state(NULL, &t); d512 1 a512 1 if (attr == NULL || *attr == NULL) d520 1 a520 1 if (attr == NULL || *attr == NULL) d629 1 a629 1 if (attr == NULL || *attr == NULL) d637 1 a637 1 if (attr == NULL || *attr == NULL) d645 1 a645 1 if (attr == NULL || *attr == NULL) d653 1 a653 1 if (attr == NULL || *attr == NULL) d661 1 a661 1 if (attr == NULL || *attr == NULL) d669 1 a669 1 if (attr == NULL || *attr == NULL) d677 1 a677 1 if (attr == NULL || *attr == NULL) d685 1 a685 1 if (attr == NULL || *attr == NULL) d795 1 a795 1 if (attr == NULL || *attr == NULL) d803 1 a803 1 if (attr == NULL || *attr == NULL) @