|
13 | 13 |
|
14 | 14 | #define CONCURRENT_READER_LIMIT (CONFIG_MAX_PTHREAD_COUNT + 1)
|
15 | 15 |
|
16 |
| -static s64_t calculate_timeout(const struct timespec *abstime); |
| 16 | +s64_t timespec_to_timeoutms(const struct timespec *abstime); |
17 | 17 | static u32_t read_lock_acquire(pthread_rwlock_t *rwlock, s32_t timeout);
|
18 | 18 | static u32_t write_lock_acquire(pthread_rwlock_t *rwlock, s32_t timeout);
|
19 | 19 |
|
@@ -93,7 +93,7 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
|
93 | 93 | return EINVAL;
|
94 | 94 | }
|
95 | 95 |
|
96 |
| - timeout = (s32_t) calculate_timeout(abstime); |
| 96 | + timeout = (s32_t) timespec_to_timeoutms(abstime); |
97 | 97 |
|
98 | 98 | if (read_lock_acquire(rwlock, timeout) != 0) {
|
99 | 99 | ret = ETIMEDOUT;
|
@@ -155,7 +155,7 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
|
155 | 155 | return EINVAL;
|
156 | 156 | }
|
157 | 157 |
|
158 |
| - timeout = (s32_t) calculate_timeout(abstime); |
| 158 | + timeout = (s32_t) timespec_to_timeoutms(abstime); |
159 | 159 |
|
160 | 160 | if (write_lock_acquire(rwlock, timeout) != 0) {
|
161 | 161 | ret = ETIMEDOUT;
|
@@ -254,34 +254,4 @@ static u32_t write_lock_acquire(pthread_rwlock_t *rwlock, s32_t timeout)
|
254 | 254 | return ret;
|
255 | 255 | }
|
256 | 256 |
|
257 |
| -static s64_t calculate_timeout(const struct timespec *abstime) |
258 |
| -{ |
259 |
| - s64_t milli_secs; |
260 |
| - s32_t secs; |
261 |
| - struct timespec curtime; |
262 |
| - |
263 |
| - /* FIXME: Zephyr does have CLOCK_REALTIME to get time. |
264 |
| - * As per POSIX standard time should be calculated wrt CLOCK_REALTIME. |
265 |
| - * Zephyr deviates from POSIX 1003.1 standard on this aspect. |
266 |
| - */ |
267 |
| - clock_gettime(CLOCK_MONOTONIC, &curtime); |
268 |
| - secs = abstime->tv_sec - curtime.tv_sec; |
269 |
| - |
270 |
| - if (abstime->tv_sec < curtime.tv_sec || |
271 |
| - (secs == 0 && abstime->tv_nsec <= curtime.tv_nsec)) { |
272 |
| - milli_secs = K_NO_WAIT; |
273 |
| - } else { |
274 |
| - milli_secs = (abstime->tv_nsec - curtime.tv_nsec) / |
275 |
| - NSEC_PER_MSEC; |
276 |
| - |
277 |
| - if (milli_secs < 0) { |
278 |
| - milli_secs += MSEC_PER_SEC; |
279 |
| - secs -= 1; |
280 |
| - } |
281 |
| - |
282 |
| - milli_secs += (long)secs * MSEC_PER_SEC; |
283 |
| - } |
284 |
| - |
285 |
| - return milli_secs; |
286 |
| -} |
287 | 257 |
|
0 commit comments