123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- #ifndef _IMPLEMENT_H
- #define _IMPLEMENT_H
- #include "pte_osal.h"
- #include "semaphore.h"
- #include "sched.h"
- typedef enum
- {
-
- PThreadStateInitial = 0,
- PThreadStateRunning,
- PThreadStateSuspended,
- PThreadStateCancelPending,
-
- PThreadStateCanceling,
-
-
- PThreadStateException,
-
- PThreadStateLast
- }
- PThreadState;
- typedef struct pte_thread_t_ pte_thread_t;
- struct pte_thread_t_
- {
- pte_osThreadHandle threadId;
- pthread_t ptHandle;
- pte_thread_t * prevReuse;
- volatile PThreadState state;
- void *exitStatus;
- void *parms;
- int ptErrno;
- int detachState;
- pthread_mutex_t threadLock;
- int sched_priority;
- pthread_mutex_t cancelLock;
- int cancelState;
- int cancelType;
- int cancelEvent;
- #ifdef PTE_CLEANUP_C
- jmp_buf start_mark;
- #endif
- int implicit:
- 1;
- void *keys;
- void *nextAssoc;
- };
- #define PTE_ATTR_VALID ((unsigned long) 0xC4C0FFEE)
- struct pthread_attr_t_
- {
- unsigned long valid;
- void *stackaddr;
- size_t stacksize;
- int detachstate;
- struct sched_param param;
- int inheritsched;
- int contentionscope;
- };
- struct sem_t_
- {
- int value;
- pthread_mutex_t lock;
- pte_osSemaphoreHandle sem;
- };
- #define PTE_OBJECT_AUTO_INIT ((void *) -1)
- #define PTE_OBJECT_INVALID 0
- struct pthread_mutex_t_
- {
- pte_osSemaphoreHandle handle;
- int lock_idx;
-
- int recursive_count;
- int kind;
- pthread_t ownerThread;
- };
- struct pthread_mutexattr_t_
- {
- int pshared;
- int kind;
- };
- #define PTE_SPIN_UNLOCKED (1)
- #define PTE_SPIN_LOCKED (2)
- #define PTE_SPIN_USE_MUTEX (3)
- struct pthread_spinlock_t_
- {
- int interlock;
- union
- {
- int cpus;
- pthread_mutex_t mutex;
- } u;
- };
- struct pthread_barrier_t_
- {
- unsigned int nCurrentBarrierHeight;
- unsigned int nInitialBarrierHeight;
- int iStep;
- int pshared;
- sem_t semBarrierBreeched[2];
- };
- struct pthread_barrierattr_t_
- {
- int pshared;
- };
- struct pthread_key_t_
- {
- unsigned key;
- void (*destructor) (void *);
- pthread_mutex_t keyLock;
- void *threads;
- };
- typedef struct ThreadParms ThreadParms;
- typedef struct ThreadKeyAssoc ThreadKeyAssoc;
- struct ThreadParms
- {
- pthread_t tid;
- void *(*start) (void *);
- void *arg;
- };
- struct pthread_cond_t_
- {
- long nWaitersBlocked;
- long nWaitersGone;
- long nWaitersToUnblock;
- sem_t semBlockQueue;
-
- sem_t semBlockLock;
-
-
- pthread_mutex_t mtxUnblockLock;
-
-
- pthread_cond_t next;
- pthread_cond_t prev;
- };
- struct pthread_condattr_t_
- {
- int pshared;
- };
- #define PTE_RWLOCK_MAGIC 0xfacade2
- struct pthread_rwlock_t_
- {
- pthread_mutex_t mtxExclusiveAccess;
- pthread_mutex_t mtxSharedAccessCompleted;
- pthread_cond_t cndSharedAccessCompleted;
- int nSharedAccessCount;
- int nExclusiveAccessCount;
- int nCompletedSharedAccessCount;
- int nMagic;
- };
- struct pthread_rwlockattr_t_
- {
- int pshared;
- };
- struct pte_mcs_node_t_
- {
- struct pte_mcs_node_t_ **lock;
- struct pte_mcs_node_t_ *next;
- unsigned int readyFlag;
- unsigned int nextFlag;
- };
- typedef struct pte_mcs_node_t_ pte_mcs_local_node_t;
- typedef struct pte_mcs_node_t_ *pte_mcs_lock_t;
- struct ThreadKeyAssoc
- {
-
- pte_thread_t * thread;
- pthread_key_t key;
- ThreadKeyAssoc *nextKey;
- ThreadKeyAssoc *nextThread;
- ThreadKeyAssoc *prevKey;
- ThreadKeyAssoc *prevThread;
- };
- #define PTE_EPS_EXIT (1)
- #define PTE_EPS_CANCEL (2)
- #define PTE_MAX(a,b) ((a)<(b)?(b):(a))
- #define PTE_MIN(a,b) ((a)>(b)?(b):(a))
- #define PTE_THREAD_REUSE_EMPTY ((pte_thread_t *) 1)
- extern int pte_processInitialized;
- extern pte_thread_t * pte_threadReuseTop;
- extern pte_thread_t * pte_threadReuseBottom;
- extern pthread_key_t pte_selfThreadKey;
- extern pthread_key_t pte_cleanupKey;
- extern pthread_cond_t pte_cond_list_head;
- extern pthread_cond_t pte_cond_list_tail;
- extern int pte_mutex_default_kind;
- extern int pte_concurrency;
- extern int pte_features;
- extern pte_osMutexHandle pte_thread_reuse_lock;
- extern pte_osMutexHandle pte_mutex_test_init_lock;
- extern pte_osMutexHandle pte_cond_list_lock;
- extern pte_osMutexHandle pte_cond_test_init_lock;
- extern pte_osMutexHandle pte_rwlock_test_init_lock;
- extern pte_osMutexHandle pte_spinlock_test_init_lock;
- #ifdef __cplusplus
- extern "C"
- {
- #endif
-
- int pte_is_attr (const pthread_attr_t * attr);
- int pte_cond_check_need_init (pthread_cond_t * cond);
- int pte_mutex_check_need_init (pthread_mutex_t * mutex);
- int pte_rwlock_check_need_init (pthread_rwlock_t * rwlock);
- int pte_spinlock_check_need_init (pthread_spinlock_t * lock);
- int pte_processInitialize (void);
- void pte_processTerminate (void);
- void pte_threadDestroy (pthread_t tid);
- void pte_threadExitAndDestroy (pthread_t tid);
- void pte_pop_cleanup_all (int execute);
- pthread_t pte_new (void);
- pthread_t pte_threadReusePop (void);
- void pte_threadReusePush (pthread_t thread);
- int pte_getprocessors (int *count);
- int pte_setthreadpriority (pthread_t thread, int policy, int priority);
- void pte_rwlock_cancelwrwait (void *arg);
- int pte_threadStart (void *vthreadParms);
- void pte_callUserDestroyRoutines (pthread_t thread);
- int pte_tkAssocCreate (pte_thread_t * thread, pthread_key_t key);
- void pte_tkAssocDestroy (ThreadKeyAssoc * assoc);
- int sem_wait_nocancel (sem_t * sem);
- unsigned int pte_relmillisecs (const struct timespec * abstime);
- void pte_mcs_lock_acquire (pte_mcs_lock_t * lock, pte_mcs_local_node_t * node);
- void pte_mcs_lock_release (pte_mcs_local_node_t * node);
-
- void pte_throw (unsigned int exception);
- int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout);
- #define PTE_ATOMIC_EXCHANGE pte_osAtomicExchange
- #define PTE_ATOMIC_EXCHANGE_ADD pte_osAtomicExchangeAdd
- #define PTE_ATOMIC_COMPARE_EXCHANGE pte_osAtomicCompareExchange
- #define PTE_ATOMIC_DECREMENT pte_osAtomicDecrement
- #define PTE_ATOMIC_INCREMENT pte_osAtomicIncrement
- int pte_thread_detach_np();
- int pte_thread_detach_and_exit_np();
- #ifdef __cplusplus
- }
- #endif
- #endif
|