系统调用中断相关,高手请答
在看ace源代码的时候遇到了两个宏
#define ACE_OSCALL_RETURN(X,TYPE,FAILVALUE) \
do \
return (TYPE) (X); \
while (0)
#define ACE_OSCALL(X,TYPE,FAILVALUE,RESULT) \
do \
RESULT = (TYPE) (X); \
while (0)
根据作者的注释:
/**
* ACE_OSCALL* macros
*
* @deprecated ACE_OSCALL_RETURN and ACE_OSCALL should not be used.
* Please restart system calls in your application code.
* See the @c sigaction(2) man page for documentation
* regarding enabling restartable system calls across
* signals via the @c SA_RESTART flag.
*
* The following two macros used ensure that system calls are properly
* restarted (if necessary) when interrupts occur. However, that
* capability was never enabled by any of our supported platforms.
* In fact, some parts of ACE would not function properly when that
* ability was enabled. Furthermore, they assumed that ability to
* restart system calls was determined statically. That assumption
* does not hold for modern platforms, where that ability is
* determined dynamically at run-time.
*/
大概是出于考虑系统调用时遇到中断的异常情况,但没体会到这宏这样设计究竟能起到什么作用,
以下是某处代码对该宏的使用:
ACE_INLINE struct tm *
ACE_OS::gmtime (const time_t *t)
{
ACE_OS_TRACE ("ACE_OS::gmtime");
#if defined (ACE_LACKS_GMTIME)
ACE_UNUSED_ARG (t);
ACE_NOTSUP_RETURN (0);
#else
ACE_OSCALL_RETURN (::gmtime (t), struct tm *, 0);
#endif /* ACE_LACKS_GMTIME */
}
大家说说你的看法