⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lock.h

📁 磁盘管理工具,主要管理光盘信息和内容希望大家喜欢
💻 H
📖 第 1 页 / 共 3 页
字号:
typedef struct        {          pthread_mutex_t recmutex; /* recursive mutex */          pthread_mutex_t guard;    /* protects the initialization */          int initialized;        }        gl_recursive_lock_t;#   define gl_recursive_lock_define(STORAGECLASS, NAME) \      STORAGECLASS gl_recursive_lock_t NAME;#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \      STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;#   define gl_recursive_lock_initializer \      { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }#   define gl_recursive_lock_init(NAME) \      if (pthread_in_use ()) glthread_recursive_lock_init (&NAME)#   define gl_recursive_lock_lock(NAME) \      if (pthread_in_use ()) glthread_recursive_lock_lock (&NAME)#   define gl_recursive_lock_unlock(NAME) \      if (pthread_in_use ()) glthread_recursive_lock_unlock (&NAME)#   define gl_recursive_lock_destroy(NAME) \      if (pthread_in_use ()) glthread_recursive_lock_destroy (&NAME)extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock);#  endif# else/* Old versions of POSIX threads on Solaris did not have recursive locks.   We have to implement them ourselves.  */typedef struct        {          pthread_mutex_t mutex;          pthread_t owner;          unsigned long depth;        }        gl_recursive_lock_t;#  define gl_recursive_lock_define(STORAGECLASS, NAME) \     STORAGECLASS gl_recursive_lock_t NAME;#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \     STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;#  define gl_recursive_lock_initializer \     { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }#  define gl_recursive_lock_init(NAME) \     if (pthread_in_use ()) glthread_recursive_lock_init (&NAME)#  define gl_recursive_lock_lock(NAME) \     if (pthread_in_use ()) glthread_recursive_lock_lock (&NAME)#  define gl_recursive_lock_unlock(NAME) \     if (pthread_in_use ()) glthread_recursive_lock_unlock (&NAME)#  define gl_recursive_lock_destroy(NAME) \     if (pthread_in_use ()) glthread_recursive_lock_destroy (&NAME)extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock);extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock);# endif/* -------------------------- gl_once_t datatype -------------------------- */typedef pthread_once_t gl_once_t;# define gl_once_define(STORAGECLASS, NAME) \    STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;# define gl_once(NAME, INITFUNCTION) \    do                                                   \      {                                                  \        if (pthread_in_use ())                           \          {                                              \            if (pthread_once (&NAME, INITFUNCTION) != 0) \              abort ();                                  \          }                                              \        else                                             \          {                                              \            if (glthread_once_singlethreaded (&NAME))    \              INITFUNCTION ();                           \          }                                              \      }                                                  \    while (0)extern int glthread_once_singlethreaded (pthread_once_t *once_control);# ifdef __cplusplus}# endif#endif/* ========================================================================= */#if USE_PTH_THREADS/* Use the GNU Pth threads library.  */# include <pth.h># include <stdlib.h># ifdef __cplusplusextern "C" {# endif# if USE_PTH_THREADS_WEAK/* Use weak references to the GNU Pth threads library.  */#  pragma weak pth_mutex_init#  pragma weak pth_mutex_acquire#  pragma weak pth_mutex_release#  pragma weak pth_rwlock_init#  pragma weak pth_rwlock_acquire#  pragma weak pth_rwlock_release#  pragma weak pth_once#  pragma weak pth_cancel#  define pth_in_use() (pth_cancel != NULL)# else#  define pth_in_use() 1# endif/* -------------------------- gl_lock_t datatype -------------------------- */typedef pth_mutex_t gl_lock_t;# define gl_lock_define(STORAGECLASS, NAME) \    STORAGECLASS pth_mutex_t NAME;# define gl_lock_define_initialized(STORAGECLASS, NAME) \    STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;# define gl_lock_initializer \    PTH_MUTEX_INIT# define gl_lock_init(NAME) \    if (pth_in_use() && !pth_mutex_init (&NAME)) abort ()# define gl_lock_lock(NAME) \    if (pth_in_use() && !pth_mutex_acquire (&NAME, 0, NULL)) abort ()# define gl_lock_unlock(NAME) \    if (pth_in_use() && !pth_mutex_release (&NAME)) abort ()# define gl_lock_destroy(NAME) \    (void)(&NAME)/* ------------------------- gl_rwlock_t datatype ------------------------- */typedef pth_rwlock_t gl_rwlock_t;#  define gl_rwlock_define(STORAGECLASS, NAME) \     STORAGECLASS pth_rwlock_t NAME;#  define gl_rwlock_define_initialized(STORAGECLASS, NAME) \     STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;#  define gl_rwlock_initializer \     PTH_RWLOCK_INIT#  define gl_rwlock_init(NAME) \     if (pth_in_use() && !pth_rwlock_init (&NAME)) abort ()#  define gl_rwlock_rdlock(NAME) \     if (pth_in_use() && !pth_rwlock_acquire (&NAME, PTH_RWLOCK_RD, 0, NULL)) abort ()#  define gl_rwlock_wrlock(NAME) \     if (pth_in_use() && !pth_rwlock_acquire (&NAME, PTH_RWLOCK_RW, 0, NULL)) abort ()#  define gl_rwlock_unlock(NAME) \     if (pth_in_use() && !pth_rwlock_release (&NAME)) abort ()#  define gl_rwlock_destroy(NAME) \     (void)(&NAME)/* --------------------- gl_recursive_lock_t datatype --------------------- *//* In Pth, mutexes are recursive by default.  */typedef pth_mutex_t gl_recursive_lock_t;#  define gl_recursive_lock_define(STORAGECLASS, NAME) \     STORAGECLASS pth_mutex_t NAME;#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \     STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;#  define gl_recursive_lock_initializer \     PTH_MUTEX_INIT#  define gl_recursive_lock_init(NAME) \     if (pth_in_use() && !pth_mutex_init (&NAME)) abort ()#  define gl_recursive_lock_lock(NAME) \     if (pth_in_use() && !pth_mutex_acquire (&NAME, 0, NULL)) abort ()#  define gl_recursive_lock_unlock(NAME) \     if (pth_in_use() && !pth_mutex_release (&NAME)) abort ()#  define gl_recursive_lock_destroy(NAME) \     (void)(&NAME)/* -------------------------- gl_once_t datatype -------------------------- */typedef pth_once_t gl_once_t;# define gl_once_define(STORAGECLASS, NAME) \    STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;# define gl_once(NAME, INITFUNCTION) \    do                                                                \      {                                                               \        if (pth_in_use ())                                            \          {                                                           \            void (*gl_once_temp) (void) = INITFUNCTION;               \            if (!pth_once (&NAME, glthread_once_call, &gl_once_temp)) \              abort ();                                               \          }                                                           \        else                                                          \          {                                                           \            if (glthread_once_singlethreaded (&NAME))                 \              INITFUNCTION ();                                        \          }                                                           \      }                                                               \    while (0)extern void glthread_once_call (void *arg);extern int glthread_once_singlethreaded (pth_once_t *once_control);# ifdef __cplusplus}# endif#endif/* ========================================================================= */#if USE_SOLARIS_THREADS/* Use the old Solaris threads library.  */# include <thread.h># include <synch.h># include <stdlib.h># ifdef __cplusplusextern "C" {# endif# if USE_SOLARIS_THREADS_WEAK/* Use weak references to the old Solaris threads library.  */#  pragma weak mutex_init#  pragma weak mutex_lock#  pragma weak mutex_unlock#  pragma weak mutex_destroy#  pragma weak rwlock_init#  pragma weak rw_rdlock#  pragma weak rw_wrlock#  pragma weak rw_unlock#  pragma weak rwlock_destroy#  pragma weak thr_self#  pragma weak thr_suspend#  define thread_in_use() (thr_suspend != NULL)# else#  define thread_in_use() 1# endif/* -------------------------- gl_lock_t datatype -------------------------- */typedef mutex_t gl_lock_t;# define gl_lock_define(STORAGECLASS, NAME) \    STORAGECLASS mutex_t NAME;# define gl_lock_define_initialized(STORAGECLASS, NAME) \    STORAGECLASS mutex_t NAME = gl_lock_initializer;# define gl_lock_initializer \    DEFAULTMUTEX# define gl_lock_init(NAME) \    if (thread_in_use () && mutex_init (&NAME, USYNC_THREAD, NULL) != 0) abort ()# define gl_lock_lock(NAME) \    if (thread_in_use () && mutex_lock (&NAME) != 0) abort ()# define gl_lock_unlock(NAME) \    if (thread_in_use () && mutex_unlock (&NAME) != 0) abort ()# define gl_lock_destroy(NAME) \    if (thread_in_use () && mutex_destroy (&NAME) != 0) abort ()/* ------------------------- gl_rwlock_t datatype ------------------------- */typedef rwlock_t gl_rwlock_t;# define gl_rwlock_define(STORAGECLASS, NAME) \    STORAGECLASS rwlock_t NAME;# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \    STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;# define gl_rwlock_initializer \    DEFAULTRWLOCK# define gl_rwlock_init(NAME) \    if (thread_in_use () && rwlock_init (&NAME, USYNC_THREAD, NULL) != 0) abort ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -