Last change
on this file since 388 was 388, checked in by coas-nagasima, 5 years ago |
Azure IoT Hub Device C SDK を使ったサンプルの追加
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
-
Property svn:mime-type
set to
text/x-csrc
|
File size:
915 bytes
|
Rev | Line | |
---|
[388] | 1 | #include "pthread_impl.h"
|
---|
| 2 |
|
---|
| 3 | int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
|
---|
| 4 | {
|
---|
| 5 | if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
|
---|
| 6 | && !a_cas(&m->_m_lock, 0, EBUSY))
|
---|
| 7 | return 0;
|
---|
| 8 |
|
---|
| 9 | int r, t, priv = (m->_m_type & 128) ^ 128;
|
---|
| 10 |
|
---|
| 11 | r = pthread_mutex_trylock(m);
|
---|
| 12 | if (r != EBUSY) return r;
|
---|
| 13 |
|
---|
| 14 | int spins = 100;
|
---|
| 15 | while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
|
---|
| 16 |
|
---|
| 17 | while ((r=pthread_mutex_trylock(m)) == EBUSY) {
|
---|
| 18 | if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))
|
---|
| 19 | continue;
|
---|
| 20 | if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK
|
---|
| 21 | && (r&0x7fffffff) == __pthread_self()->tid)
|
---|
| 22 | return EDEADLK;
|
---|
| 23 |
|
---|
| 24 | a_inc(&m->_m_waiters);
|
---|
| 25 | t = r | 0x80000000;
|
---|
| 26 | a_cas(&m->_m_lock, r, t);
|
---|
| 27 | r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv);
|
---|
| 28 | a_dec(&m->_m_waiters);
|
---|
| 29 | if (r && r != EINTR) break;
|
---|
| 30 | }
|
---|
| 31 | return r;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);
|
---|
Note:
See
TracBrowser
for help on using the repository browser.