Skip to content

Commit 7bbb834

Browse files
committed
Revert "posix: rwlock: Refactor locking using k_timepoint_t"
This reverts commit 833eacc. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 0a6e579 commit 7bbb834

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/posix/options/rwlock.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,24 @@ static uint32_t read_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout)
359359
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout)
360360
{
361361
uint32_t ret = 0U;
362-
k_timepoint_t deadline;
362+
int64_t elapsed_time, st_time = k_uptime_get();
363+
k_timeout_t k_timeout;
363364

364-
deadline = sys_timepoint_calc(SYS_TIMEOUT_MS(timeout));
365+
k_timeout = SYS_TIMEOUT_MS(timeout);
365366

366367
/* waiting for release of write lock */
367-
if (sys_sem_take(&rwl->wr_sem, sys_timepoint_timeout(deadline)) == 0) {
368+
if (sys_sem_take(&rwl->wr_sem, k_timeout) == 0) {
369+
/* update remaining timeout time for 2nd sem */
370+
if (timeout != SYS_FOREVER_MS) {
371+
elapsed_time = k_uptime_get() - st_time;
372+
timeout = timeout <= elapsed_time ? 0 :
373+
timeout - elapsed_time;
374+
}
375+
376+
k_timeout = SYS_TIMEOUT_MS(timeout);
377+
368378
/* waiting for reader to complete operation */
369-
if (sys_sem_take(&rwl->reader_active, sys_timepoint_timeout(deadline)) == 0) {
379+
if (sys_sem_take(&rwl->reader_active, k_timeout) == 0) {
370380
rwl->wr_owner = k_current_get();
371381
} else {
372382
(void)sys_sem_give(&rwl->wr_sem);

0 commit comments

Comments
 (0)