lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] sys_sem_wait macro


From: Simon Goldschmidt
Subject: Re: [lwip-devel] sys_sem_wait macro
Date: Mon, 13 Feb 2012 14:31:57 +0100

Mason <address@hidden> wrote:
> sys_sem_wait is defined in sys.h
> #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
> 
> There are a few places where sys_sem_wait could be used
> in the 1.4.0 code:
> 
> src/api/api_msg.c:1336:         
> sys_arch_sem_wait(&msg->conn->op_completed, 0);
> src/api/sockets.c:1640:  sys_arch_sem_wait(&sock->conn->op_completed, 0);
> src/api/sockets.c:2050:  sys_arch_sem_wait(&sock->conn->op_completed, 0);
> src/api/tcpip.c:313:    sys_arch_sem_wait(&apimsg->msg.conn->op_completed,
> 0);
> 
> (Maybe this was already changed in the trunk.)

Yes, these could be replaced. The reason it is like it is now is that not too 
long ago (< v1.3.0, I think), sys_sem_wait() called timers while waiting, and 
that wasn't wanted in most situations. Thus the code called sys_arch_sem_wait() 
directly. However, that was a bug which is already fixed, so I see no reason 
not to use sys_sem_wait() in all places where 'timeout' is 0.

> Related question:
> 
> When sys_arch_sem_wait is called with a non-zero timeout
> value, the return value must be the time spent waiting.
> 
> If timeout is 0, meaning "block as long as necessary",
> it seems the caller doesn't care how long he was blocked.
> Can we return 0, or perhaps -1, or -2 or any arbitrary value?

You can return anything but -1 (since that is reserved for SYS_ARCH_TIMEOUT). 
Generally, returning >=0 seems like the best idea to me...

Simon
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



reply via email to

[Prev in Thread] Current Thread [Next in Thread]