📄 wrappthread.c
字号:
/* * pthreads wrapper functions. */#include "unpipc.h"voidPthread_attr_init(pthread_attr_t *attr){ int n; if ( (n = pthread_attr_init(attr)) == 0) return; errno = n; err_sys("pthread_attr_init error");}voidPthread_attr_destroy(pthread_attr_t *attr){ int n; if ( (n = pthread_attr_destroy(attr)) == 0) return; errno = n; err_sys("pthread_attr_destroy error");}voidPthread_attr_setdetachstate(pthread_attr_t *attr, int detach){ int n; if ( (n = pthread_attr_setdetachstate(attr, detach)) == 0) return; errno = n; err_sys("pthread_attr_setdetachstate error");}voidPthread_attr_setscope(pthread_attr_t *attr, int scope){ int n; if ( (n = pthread_attr_setscope(attr, scope)) == 0) return; errno = n; err_sys("pthread_attr_setscope error");}voidPthread_create(pthread_t *tid, const pthread_attr_t *attr, void * (*func)(void *), void *arg){ int n; if ( (n = pthread_create(tid, attr, func, arg)) == 0) return; errno = n; err_sys("pthread_create error");}voidPthread_join(pthread_t tid, void **status){ int n; if ( (n = pthread_join(tid, status)) == 0) return; errno = n; err_sys("pthread_join error");}voidPthread_detach(pthread_t tid){ int n; if ( (n = pthread_detach(tid)) == 0) return; errno = n; err_sys("pthread_detach error");}voidPthread_kill(pthread_t tid, int signo){ int n; if ( (n = pthread_kill(tid, signo)) == 0) return; errno = n; err_sys("pthread_kill error");}voidPthread_mutexattr_init(pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutexattr_init(attr)) == 0) return; errno = n; err_sys("pthread_mutexattr_init error");}voidPthread_mutexattr_destroy(pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutexattr_destroy(attr)) == 0) return; errno = n; err_sys("pthread_mutexattr_destroy error");}#ifdef _POSIX_THREAD_PROCESS_SHAREDvoidPthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int flag){ int n; if ( (n = pthread_mutexattr_setpshared(attr, flag)) == 0) return; errno = n; err_sys("pthread_mutexattr_setpshared error");}#endifvoidPthread_mutex_init(pthread_mutex_t *mptr, pthread_mutexattr_t *attr){ int n; if ( (n = pthread_mutex_init(mptr, attr)) == 0) return; errno = n; err_sys("pthread_mutex_init error");}voidPthread_mutex_destroy(pthread_mutex_t *mptr){ int n; if ( (n = pthread_mutex_destroy(mptr)) == 0) return; errno = n; err_sys("pthread_mutex_destroy error");}/* include Pthread_mutex_lock */voidPthread_mutex_lock(pthread_mutex_t *mptr){ int n; if ( (n = pthread_mutex_lock(mptr)) == 0) return; errno = n; err_sys("pthread_mutex_lock error");}/* end Pthread_mutex_lock */voidPthread_mutex_unlock(pthread_mutex_t *mptr){ int n; if ( (n = pthread_mutex_unlock(mptr)) == 0) return; errno = n; err_sys("pthread_mutex_unlock error");}voidPthread_condattr_init(pthread_condattr_t *attr){ int n; if ( (n = pthread_condattr_init(attr)) == 0) return; errno = n; err_sys("pthread_condattr_init error");}voidPthread_condattr_destroy(pthread_condattr_t *attr){ int n; if ( (n = pthread_condattr_destroy(attr)) == 0) return; errno = n; err_sys("pthread_condattr_destroy error");}#ifdef _POSIX_THREAD_PROCESS_SHAREDvoidPthread_condattr_setpshared(pthread_condattr_t *attr, int flag){ int n; if ( (n = pthread_condattr_setpshared(attr, flag)) == 0) return; errno = n; err_sys("pthread_condattr_setpshared error");}#endifvoidPthread_cond_broadcast(pthread_cond_t *cptr){ int n; if ( (n = pthread_cond_broadcast(cptr)) == 0) return; errno = n; err_sys("pthread_cond_broadcast error");}voidPthread_cond_signal(pthread_cond_t *cptr){ int n; if ( (n = pthread_cond_signal(cptr)) == 0) return; errno = n; err_sys("pthread_cond_signal error");}voidPthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr){ int n; if ( (n = pthread_cond_wait(cptr, mptr)) == 0) return; errno = n; err_sys("pthread_cond_wait error");}voidPthread_cond_timedwait(pthread_cond_t *cptr, pthread_mutex_t *mptr, const struct timespec *tsptr){ int n; if ( (n = pthread_cond_timedwait(cptr, mptr, tsptr)) == 0) return; errno = n; err_sys("pthread_cond_timedwait error");}voidPthread_once(pthread_once_t *ptr, void (*func)(void)){ int n; if ( (n = pthread_once(ptr, func)) == 0) return; errno = n; err_sys("pthread_once error");}voidPthread_key_create(pthread_key_t *key, void (*func)(void *)){ int n; if ( (n = pthread_key_create(key, func)) == 0) return; errno = n; err_sys("pthread_key_create error");}voidPthread_setcancelstate(int state, int *oldstate){ int n; if ( (n = pthread_setcancelstate(state, oldstate)) == 0) return; errno = n; err_sys("pthread_setcancelstate error");}voidPthread_setspecific(pthread_key_t key, const void *value){ int n; if ( (n = pthread_setspecific(key, value)) == 0) return; errno = n; err_sys("pthread_setspecific error");}/* include pr_thread_id */longpr_thread_id(pthread_t *ptr){#if defined(sun) return((ptr == NULL) ? pthread_self() : *ptr); /* Solaris */#elif defined(__osf__) && defined(__alpha) pthread_t tid; tid = (ptr == NULL) ? pthread_self() : *ptr; /* Digital Unix */ return(pthread_getsequence_np(tid));#else /* 4everything else */ return((ptr == NULL) ? pthread_self() : *ptr);#endif}/* end pr_thread_id */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -