OSDN Git Service
(root)
/
zither
/
ds-zither.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
addid library source 20140221
[zither/ds-zither.git]
/
libms
/
safe_pthread_mutex_lock.c
1
2
3
#include<stdio.h>
4
#include<unistd.h>
5
#include<pthread.h>
6
7
int safe_pthread_mutex_lock(pthread_mutex_t * mu)
8
{
9
int ret, uint;
10
uint = 10000;
11
12
while(1){
13
ret = pthread_mutex_trylock(mu);
14
if(0 == ret){
15
break;
16
}
17
else{
18
#ifdef THREAD_LOCK_BUG
19
fprintf(stderr,"pthread trylock err. <%d> <%d>\n", (int)mu, uint);
20
#endif
21
}
22
if(uint > 500000){ uint = 500000; }
23
usleep(uint);
24
uint = uint + 10000;
25
}
26
27
return ret;
28
}