📄 thread.h
字号:
pthread_mutex (pthread_mutexattr * = NULL); pthread_mutex (pthread_mutex_t *, pthread_mutexattr *); ~pthread_mutex ();private: class nativeMutex { public: bool init(); bool lock(); void unlock(); private: HANDLE theHandle; }; static nativeMutex mutexInitializationLock;};class pthread:public verifyable_object{public: HANDLE win32_obj_id; class pthread_attr attr; void *(*function) (void *); void *arg; void *return_ptr; bool suspended; int cancelstate, canceltype; HANDLE cancel_event; pthread_t joiner; // int joinable; /* signal handling */ struct sigaction *sigs; sigset_t *sigmask; LONG *sigtodo; virtual void create (void *(*)(void *), pthread_attr *, void *); pthread (); virtual ~pthread (); static void initMainThread (bool); static bool isGoodObject(pthread_t const *); static void atforkprepare(); static void atforkparent(); static void atforkchild(); /* API calls */ static int cancel (pthread_t); static int join (pthread_t * thread, void **return_val); static int detach (pthread_t * thread); static int create (pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine) (void *), void *arg); static int once (pthread_once_t *, void (*)(void)); static int atfork(void (*)(void), void (*)(void), void (*)(void)); static int suspend (pthread_t * thread); static int resume (pthread_t * thread); virtual void exit (void *value_ptr); virtual int cancel (); virtual void testcancel (); static void static_cancel_self (); virtual int setcancelstate (int state, int *oldstate); virtual int setcanceltype (int type, int *oldtype); virtual void push_cleanup_handler (__pthread_cleanup_handler *handler); virtual void pop_cleanup_handler (int const execute); static pthread* self (); static void *thread_init_wrapper (void *); virtual unsigned long getsequence_np();private: DWORD thread_id; __pthread_cleanup_handler *cleanup_stack; pthread_mutex mutex; void pop_all_cleanup_handlers (void); void precreate (pthread_attr *); void postcreate (); void setThreadIdtoCurrent (); static void setTlsSelfPointer (pthread *); static pthread *getTlsSelfPointer (); void cancel_self (); DWORD getThreadId (); void initCurrentThread ();};class pthreadNull : public pthread{ public: static pthread *getNullpthread(); ~pthreadNull(); /* From pthread These should never get called * as the ojbect is not verifyable */ void create (void *(*)(void *), pthread_attr *, void *); void exit (void *value_ptr); int cancel (); void testcancel (); int setcancelstate (int state, int *oldstate); int setcanceltype (int type, int *oldtype); void push_cleanup_handler (__pthread_cleanup_handler *handler); void pop_cleanup_handler (int const execute); unsigned long getsequence_np(); private: pthreadNull (); static pthreadNull _instance;};class pthread_condattr:public verifyable_object{public: static bool isGoodObject(pthread_condattr_t const *); int shared; pthread_condattr (); ~pthread_condattr ();};class pthread_cond:public verifyable_object{public: static bool isGoodObject(pthread_cond_t const *); static bool isGoodInitializer(pthread_cond_t const *); static bool isGoodInitializerOrObject(pthread_cond_t const *); int shared; LONG waiting; LONG ExitingWait; pthread_mutex *mutex; /* to allow atomic behaviour for cond_broadcast */ pthread_mutex_t cond_access; HANDLE win32_obj_id; class pthread_cond * next; int TimedWait (DWORD dwMilliseconds); void BroadCast (); void Signal (); void fixup_after_fork (); pthread_cond (pthread_condattr *); ~pthread_cond ();};class pthread_once{public: pthread_mutex_t mutex; int state;};/* shouldn't be here */class semaphore:public verifyable_object{public: static bool isGoodObject(sem_t const *); /* API calls */ static int init (sem_t * sem, int pshared, unsigned int value); static int destroy (sem_t * sem); static int wait (sem_t * sem); static int trywait (sem_t * sem); static int post (sem_t * sem); HANDLE win32_obj_id; class semaphore * next; int shared; long currentvalue; void Wait (); void Post (); int TryWait (); void fixup_after_fork (); semaphore (int, unsigned int); ~semaphore ();};class callback{public: void (*cb)(void); class callback * next;};class MTinterface{public: // General int concurrency; long int threadcount; // Used for main thread data, and sigproc thread struct __reent_t reents; struct _winsup_t winsup_reent; callback *pthread_prepare; callback *pthread_child; callback *pthread_parent; // lists of pthread objects. USE THREADSAFE INSERTS AND DELETES. class pthread_mutex * mutexs; class pthread_cond * conds; class semaphore * semaphores; pthread_key reent_key; pthread_key thread_self_key; void Init (int); void fixup_before_fork (void); void fixup_after_fork (void); MTinterface () : concurrency (0), threadcount (1), pthread_prepare (NULL), pthread_child (NULL), pthread_parent (NULL), mutexs (NULL), conds (NULL), semaphores (NULL), reent_key (NULL), thread_self_key (NULL) { }}; #define MT_INTERFACE user_data->threadinterfaceextern "C"{int __pthread_attr_init (pthread_attr_t * attr);int __pthread_attr_destroy (pthread_attr_t * attr);int __pthread_attr_setdetachstate (pthread_attr_t *, int);int __pthread_attr_getdetachstate (const pthread_attr_t *, int *);int __pthread_attr_setstacksize (pthread_attr_t * attr, size_t size);int __pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * size);int __pthread_attr_getinheritsched (const pthread_attr_t *, int *);int __pthread_attr_getschedparam (const pthread_attr_t *, struct sched_param *);int __pthread_attr_getschedpolicy (const pthread_attr_t *, int *);int __pthread_attr_getscope (const pthread_attr_t *, int *);int __pthread_attr_getstackaddr (const pthread_attr_t *, void **);int __pthread_attr_setinheritsched (pthread_attr_t *, int);int __pthread_attr_setschedparam (pthread_attr_t *, const struct sched_param *);int __pthread_attr_setschedpolicy (pthread_attr_t *, int);int __pthread_attr_setscope (pthread_attr_t *, int);int __pthread_attr_setstackaddr (pthread_attr_t *, void *);/* Thread SpecificData */int __pthread_key_create (pthread_key_t * key, void (*destructor) (void *));int __pthread_key_delete (pthread_key_t key);int __pthread_setspecific (pthread_key_t key, const void *value);void *__pthread_getspecific (pthread_key_t key);/* Thead synchroniation */int __pthread_cond_destroy (pthread_cond_t * cond);int __pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr);int __pthread_cond_signal (pthread_cond_t * cond);int __pthread_cond_broadcast (pthread_cond_t * cond);int __pthread_condattr_init (pthread_condattr_t * condattr);int __pthread_condattr_destroy (pthread_condattr_t * condattr);int __pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared);int __pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared);/* Thread signal */int __pthread_kill (pthread_t thread, int sig);int __pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set);/* ID */int __pthread_equal (pthread_t * t1, pthread_t * t2);/* Mutexes */int __pthread_mutex_lock (pthread_mutex_t *);int __pthread_mutex_trylock (pthread_mutex_t *);int __pthread_mutex_unlock (pthread_mutex_t *);int __pthread_mutex_destroy (pthread_mutex_t *);int __pthread_mutex_setprioceiling (pthread_mutex_t * mutex, int prioceiling, int *old_ceiling);int __pthread_mutex_getprioceiling (const pthread_mutex_t * mutex, int *prioceiling);int __pthread_mutexattr_destroy (pthread_mutexattr_t *);int __pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *, int *);int __pthread_mutexattr_getprotocol (const pthread_mutexattr_t *, int *);int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *, int *);int __pthread_mutexattr_gettype (const pthread_mutexattr_t *, int *);int __pthread_mutexattr_init (pthread_mutexattr_t *);int __pthread_mutexattr_setprioceiling (pthread_mutexattr_t *, int);int __pthread_mutexattr_setprotocol (pthread_mutexattr_t *, int);int __pthread_mutexattr_setpshared (pthread_mutexattr_t *, int);int __pthread_mutexattr_settype (pthread_mutexattr_t *, int);/* Scheduling */int __pthread_getconcurrency (void);int __pthread_setconcurrency (int new_level);int __pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param);int __pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param);};#endif // MT_SAFE#endif // _CYGNUS_THREADS_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -