Changeset 1744
- Timestamp:
- 08/11/11 11:45:43 (7 months ago)
- File:
-
- 1 edited
-
trunk/src/napi.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/napi.c
r1739 r1744 34 34 #include <stdarg.h> 35 35 #include <stdint.h> 36 37 #include "nxconfig.h" 36 38 #include "napi.h" 37 39 #include "nxstack.h" … … 58 60 #include "nx_stptok.h" 59 61 60 #if def _WIN3262 #if defined(_WIN32) 61 63 /* 62 64 * HDF5 on windows does not do locking for multiple threads conveniently so we will implement it ourselves. … … 88 90 ( nxilock() , nxiunlock(__call) ) 89 91 92 #elif HAVE_LIBPTHREAD 93 94 #include <pthread.h> 95 96 static pthread_mutex_t nx_mutex; 97 98 static void nx_pthread_init() 99 { 100 pthread_mutexattr_t attr; 101 pthread_mutexattr_init(&attr); 102 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 103 pthread_mutex_init(&nx_mutex, &attr); 104 } 105 106 static int nxilock() 107 { 108 static pthread_once_t once_control = PTHREAD_ONCE_INIT; 109 if (pthread_once(&once_control, nx_pthread_init) != 0) 110 { 111 NXReportError("pthread_once failed"); 112 return NX_ERROR; 113 } 114 if (pthread_mutex_lock(&nx_mutex) != 0) 115 { 116 NXReportError("pthread_mutex_lock failed"); 117 return NX_ERROR; 118 } 119 return NX_OK; 120 } 121 122 static int nxiunlock(int ret) 123 { 124 if (pthread_mutex_unlock(&nx_mutex) != 0) 125 { 126 NXReportError("pthread_mutex_unlock failed"); 127 return NX_ERROR; 128 } 129 return ret; 130 } 131 132 #define LOCKED_CALL(__call) \ 133 ( nxilock() , nxiunlock(__call) ) 134 90 135 #else 91 136 92 137 #define LOCKED_CALL(__call) \ 93 __call138 __call 94 139 95 140 #endif /* _WIN32 */
Note: See TracChangeset
for help on using the changeset viewer.
