Changeset 4040
- Timestamp:
- Dec 2, 2007, 4:35:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/platform.c
r4001 r4040 39 39 #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_PROFILE */ 40 40 #else 41 #define _XOPEN_SOURCE 500 /* needed for recursive locks. */ 41 42 #include <pthread.h> 42 43 #endif … … 190 191 struct tr_lock 191 192 { 192 uint32_t depth;193 int depth; 193 194 #ifdef __BEOS__ 194 195 sem_id lock; … … 211 212 l->lock = create_sem( 1, "" ); 212 213 #elif defined(WIN32) 213 InitializeCriticalSection( &l->lock ); 214 #else 215 pthread_mutex_init( &l->lock, NULL ); 214 InitializeCriticalSection( &l->lock ); /* critical sections support recursion */ 215 #else 216 pthread_mutexattr_t attr; 217 pthread_mutexattr_init( &attr ); 218 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); 219 pthread_mutex_init( &l->lock, &attr ); 216 220 #endif 217 221 … … 237 241 const tr_thread_id currentThread = tr_getCurrentThread( ); 238 242 239 if( l->lockThread == currentThread ) 240 { 241 ++l->depth; 242 } 243 else 244 { 245 #ifdef __BEOS__ 246 acquire_sem( l->lock ); 247 #elif defined(WIN32) 248 EnterCriticalSection( &l->lock ); 249 #else 250 pthread_mutex_lock( &l->lock ); 251 #endif 252 l->lockThread = currentThread; 253 l->depth = 1; 254 } 243 #ifdef __BEOS__ 244 acquire_sem( l->lock ); 245 #elif defined(WIN32) 246 EnterCriticalSection( &l->lock ); 247 #else 248 pthread_mutex_lock( &l->lock ); 249 #endif 250 l->lockThread = currentThread; 251 ++l->depth; 255 252 } 256 253 … … 267 264 assert( tr_lockHave( l ) ); 268 265 269 if( !--l->depth ) 270 { 271 l->lockThread = 0; 272 #ifdef __BEOS__ 273 release_sem( l->lock ); 274 #elif defined(WIN32) 275 LeaveCriticalSection( &l->lock ); 276 #else 277 pthread_mutex_unlock( &l->lock ); 278 #endif 279 } 266 #ifdef __BEOS__ 267 release_sem( l->lock ); 268 #elif defined(WIN32) 269 LeaveCriticalSection( &l->lock ); 270 #else 271 pthread_mutex_unlock( &l->lock ); 272 #endif 273 --l->depth; 280 274 } 281 275 … … 852 846 } 853 847 854 bzero( &snl, sizeof( snl) );848 memset( &snl, 0, sizeof(snl) ); 855 849 snl.nl_family = AF_NETLINK; 856 850 857 bzero( &req, sizeof( req) );851 memset( &req, 0, sizeof(req) ); 858 852 req.nlh.nlmsg_len = NLMSG_LENGTH( sizeof( req.rtg ) ); 859 853 req.nlh.nlmsg_type = RTM_GETROUTE; … … 893 887 for( ;; ) 894 888 { 895 bzero( &snl, sizeof( snl ) );896 889 slen = sizeof( snl ); 890 memset( &snl, 0, slen ); 897 891 res = recvfrom( fd, buf, len, 0, (struct sockaddr *) &snl, &slen ); 898 892 if( 0 > res )
Note: See TracChangeset
for help on using the changeset viewer.