Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: fusl/src/thread/pthread_mutex_timedlock.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "pthread_impl.h" 1 #include "pthread_impl.h"
2 2
3 int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) 3 int __pthread_mutex_timedlock(pthread_mutex_t* restrict m,
4 { 4 const struct timespec* restrict at) {
5 » if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL 5 if ((m->_m_type & 15) == PTHREAD_MUTEX_NORMAL &&
6 » && !a_cas(&m->_m_lock, 0, EBUSY)) 6 !a_cas(&m->_m_lock, 0, EBUSY))
7 » » return 0; 7 return 0;
8 8
9 » int r, t, priv = (m->_m_type & 128) ^ 128; 9 int r, t, priv = (m->_m_type & 128) ^ 128;
10 10
11 » r = pthread_mutex_trylock(m); 11 r = pthread_mutex_trylock(m);
12 » if (r != EBUSY) return r; 12 if (r != EBUSY)
13 » 13 return r;
14 » int spins = 100;
15 » while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
16 14
17 » while ((r=pthread_mutex_trylock(m)) == EBUSY) { 15 int spins = 100;
18 » » if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4))) 16 while (spins-- && m->_m_lock && !m->_m_waiters)
19 » » » continue; 17 a_spin();
20 » » if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK
21 » » && (r&0x7fffffff) == __pthread_self()->tid)
22 » » » return EDEADLK;
23 18
24 » » a_inc(&m->_m_waiters); 19 while ((r = pthread_mutex_trylock(m)) == EBUSY) {
25 » » t = r | 0x80000000; 20 if (!(r = m->_m_lock) || ((r & 0x40000000) && (m->_m_type & 4)))
26 » » a_cas(&m->_m_lock, r, t); 21 continue;
27 » » r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv); 22 if ((m->_m_type & 3) == PTHREAD_MUTEX_ERRORCHECK &&
28 » » a_dec(&m->_m_waiters); 23 (r & 0x7fffffff) == __pthread_self()->tid)
29 » » if (r && r != EINTR) break; 24 return EDEADLK;
30 » } 25
31 » return r; 26 a_inc(&m->_m_waiters);
27 t = r | 0x80000000;
28 a_cas(&m->_m_lock, r, t);
29 r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv);
30 a_dec(&m->_m_waiters);
31 if (r && r != EINTR)
32 break;
33 }
34 return r;
32 } 35 }
33 36
34 weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); 37 weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698