File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -359,14 +359,24 @@ static uint32_t read_lock_acquire(struct posix_rwlock *rwl, uint32_t timeout)
359
359
static uint32_t write_lock_acquire (struct posix_rwlock * rwl , uint32_t timeout )
360
360
{
361
361
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 ;
363
364
364
- deadline = sys_timepoint_calc ( SYS_TIMEOUT_MS (timeout ) );
365
+ k_timeout = SYS_TIMEOUT_MS (timeout );
365
366
366
367
/* 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
+
368
378
/* 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 ) {
370
380
rwl -> wr_owner = k_current_get ();
371
381
} else {
372
382
(void )sys_sem_give (& rwl -> wr_sem );
You can’t perform that action at this time.
0 commit comments