📄 fsu_pthread.h
字号:
/* Copyright (C) 1992-2000 the Florida State University Distributed by the Florida State University under the terms of the GNU Library General Public License.This file is part of Pthreads.Pthreads is free software; you can redistribute it and/ormodify it under the terms of the GNU Library General PublicLicense as published by the Free Software Foundation (version 2).Pthreads is distributed "AS IS" in the hope that it will beuseful, but WITHOUT ANY WARRANTY; without even the impliedwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU Library General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with Pthreads; see the file COPYING. If not, writeto the Free Software Foundation, 675 Mass Ave, Cambridge,MA 02139, USA.Report problems and direct all questions to: pthreads-bugs@ada.cs.fsu.edu Gaisler Research, Konrad Eisele<eiselekd@web.de> @(#)pthread.h 3.14 11/8/00*/#ifndef _pthread_pthread_h#define _pthread_pthread_h/* * Pthreads interface definition */#include <fsu_pthread/config.h>#include <fsu_pthread/signal.h>#include <fsu_pthread/unistd.h>#include <stdio.h>#include <fsu_pthread/limits.h>#include <sys/time.h> /* needed for struct timeval */#include <fsu_pthread/errno.h>#include <fsu_pthread/asm.h>#include <setjmp.h>#include <reent.h>#include <sys/fsu_pthread_queue.h>#include <asm-leon/contextswitch.h>#ifdef IO_NP#include <sys/types.h>#endif /* IO_NP */#if defined(MALLOC_NP) || defined(STAND_ALONE)#ifdef malloc#undef malloc#endif#ifdef calloc#undef calloc#endif#ifdef free#undef free#endif#ifdef cfree#undef cfree#endif#endif /* MALLOC_NP */#include <fsu_pthread/setjmp.h>/* contentionscope attribute values */#define PTHREAD_SCOPE_SYSTEM 0#define PTHREAD_SCOPE_PROCESS 1/* creation modes */#define PTHREAD_CREATE_JOINABLE 0#define PTHREAD_CREATE_DETACHED 1/* inheritsched attribute values */#define PTHREAD_INHERIT_SCHED 0#define PTHREAD_EXPLICIT_SCHED 1/* Allow variable stack sizes */#ifndef _POSIX_THREAD_ATTR_STACKSIZE#define _POSIX_THREAD_ATTR_STACKSIZE#endif#if defined (__GNUC__) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)#ifndef _C_PROTOTYPE#define _C_PROTOTYPE(arglist) arglist#endif /* !_C_PROTOTYPE */typedef void *any_t;#else /* !(defined (__GNUC__) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)) */#ifndef _C_PROTOTYPE#define _C_PROTOTYPE(arglist) ()#endif /* !_C_PROTOTYPE */typedef char *any_t;#ifndef const#define const#endif#ifndef volatile#define volatile#endif#endif /* defined(__GNUC__) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) */#ifndef TRUE#define TRUE 1#define FALSE 0#endif#if !defined(__sys_stdtypes_h) && !defined(_SIZE_T) && !defined(__FreeBSD__) && !defined(_M_UNIX) && !defined(__linux__) && !defined(__dos__)typedef unsigned int size_t;#endif/* * Mutex objects. */#include <sys/fsu_pthread_mutex.h>/* * Once Objects. */typedef struct { short init; short exec; pthread_mutex_t mutex;} pthread_once_t;#define PTHREAD_ONCE_INIT(p) {FALSE,FALSE,PTHREAD_MUTEX_INITIALIZER(p.mutex)};/* * Condition variables. */typedef struct pthread_cond { struct pthread_queue queue; int flags; int waiters; pthread_mutex_t *mutex; TAILQ_ENTRY(pthread_cond) dbglist; char *dbgname;} pthread_cond_t;typedef struct { int flags;} pthread_condattr_t;#define PTHREAD_COND_INITIALIZER(c) { \ TAILQ_HEAD_INITIALIZER(c.queue), /* queue */ \ 1, /* flags */ \ 0, /* waiters */ \ 0, /* mutex */ \ { 0, 0 }, \ 0 \}#define PTHREAD_COND_DBGSTART(c, n) \ pthread_cond_dbgstart_np(&c); \ c.dbgname = n;#define PTHREAD_COND_DBGSTOP(c, n) \ pthread_cond_dbgstrop_np(&c);#define PTHREAD_MUTEX_DBGSTART(m, n) \ pthread_mutex_dbgstart_np(&m); \ m.dbgname = n;#define PTHREAD_MUTEX_DBGSTOP(m, n) \ pthread_mutex_dbgstop_np(&m);/*******************************//* Condition Functions *//*Condition Attribute Functions*//*******************************/#ifdef __cplusplusextern "C" {#endif extern int pthread_cond_destroy _C_PROTOTYPE((pthread_cond_t *__cond));extern int pthread_cond_init _C_PROTOTYPE((pthread_cond_t *__cond, pthread_condattr_t *__attr));extern int pthread_condattr_init _C_PROTOTYPE((pthread_condattr_t *__attr));extern int pthread_condattr_destroy _C_PROTOTYPE((pthread_condattr_t *__attr));extern int pthread_cond_wait _C_PROTOTYPE((pthread_cond_t *__cond, pthread_mutex_t *__mutex));extern int pthread_cond_timedwait _C_PROTOTYPE((pthread_cond_t *__cond, pthread_mutex_t *__mutex, struct timespec *__timeout));extern int pthread_cond_signal _C_PROTOTYPE((pthread_cond_t *__cond));extern int pthread_cond_broadcast _C_PROTOTYPE((pthread_cond_t *__cond));extern int pthread_condattr_getpshared _C_PROTOTYPE((pthread_condattr_t *__attr, int *__pshared));extern int pthread_condattr_setpshared _C_PROTOTYPE((pthread_condattr_t *__attr, int __pshared));#ifdef __cplusplus} /* extern "C" */#endif/* * Threads. */typedef any_t (*pthread_func_t) _C_PROTOTYPE((any_t __arg));typedef void (*pthread_sighandler_t) _C_PROTOTYPE((int));struct sched_param { int sched_priority;};typedef struct { int flags;#ifdef _POSIX_THREAD_ATTR_STACKSIZE int stacksize;#endif#ifdef _POSIX_THREAD_ATTR_CUSTOM char *stack; char *name;#endif int contentionscope; int inheritsched; int detachstate; int sched; struct sched_param param; struct timespec starttime, deadline, period;} pthread_attr_t;typedef struct { int state; pthread_queue_t queue; pthread_cond_t *cond;} pthread_suspend_t; typedef struct timer_ent { struct timeval tp; /* wake-up time */ struct pthread *thread; /* thread */ int mode; /* mode of timer (ABS/REL/RR) */ TAILQ_ENTRY(timer_ent) timerlist; TAILQ_ENTRY(timer_ent) threadlist;} *timer_ent_t;/* * Queue indices */#define PRIMARY_QUEUE 0/* this slot may be used by the TIMER_QUEUE with index 2 */#define NUM_QUEUES 3#define K_QUEUES_TIMEOUT 2#define K_QUEUES_ALL 1#define K_QUEUES_PRIMARY 0typedef int pthread_key_t;typedef struct pthread_cleanup *pthread_cleanup_t;typedef TAILQ_HEAD(pthread_timer_q, timer_ent) *pthread_timer_q_t;typedef struct pthread { threadctx_t context __attribute__((aligned(8))); /* save area for context switch */ threadctx_t body __attribute__((aligned(8))); /* save area for pthread_body */ volatile int ret; /* return value (EINTR --> -1) */ char *stack_base; /* bottom of run-time stack */ int state; /* thread state, -> pthread_asm.h */ TAILQ_ENTRY(pthread) pt_qelem[NUM_QUEUES]; struct pthread_timer_q pt_active_timers; struct pthread_timer_q pt_free_timers; char *pt_name; int num_timers; /* number of timers for thread */ struct timeval interval; /* time left for SCHED_RR */ struct p_siginfo sig_info[NNSIG]; /* info for user handlers */ struct _reent pt_reent; /* reentrant structure for newlib */ struct _reent *pt_reentp; /* pointer to eather pt_reent or global reent */ int sig; /* latest received signal */ int code; /* latest received signal code */ int osp, opc, obp; /* save area for old context sw */ struct context_t *nscp; /* UNIX signal context (new sig) */ struct context_t *scp; /* UNIX signal context (current) */ struct pthread_queue joinq; /* queue to await termination */ pthread_cond_t *cond; /* cond var. if in cond_wait */ pthread_queue_t queue;/* primary queue thread is contained in */ sigset_t mask; /* set of signals thread has masked out */ sigset_t pending; /* set of signals pending on thread */ sigset_t sigwaitset; /* set of signals thread is waiting for */ pthread_func_t func; /* actual function to call upon activation */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -