incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] RE: svn commit: r472469 - in /incubator/stdcxx/trunk/tests: include/rw_process.h self/0.process.cpp src/process.cpp
Date Thu, 30 Nov 2006 19:46:38 GMT
Farid Zaripov wrote:
[...]
> 
>   sleep() can be used instead of nanosleep()?

I think so. The only potential issue is that sleep() may be
implemented using alarm() and calling it might reset a previously
set alarm. But that's probably something we'll have to live with.

> 
>   ChangeLog:
>   * process.cpp: Removed unused #include <time.h>
>   (rw_waitpid): Used sleep() instead of nanosleep()
>   (rw_process_kill): Corrected timeout value to 1 second

Looks good.

Thanks
Martin

> 
> Farid.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: process.cpp
> ===================================================================
> --- process.cpp	(revision 480885)
> +++ process.cpp	(working copy)
> @@ -152,10 +152,9 @@
>  
>  #  include <sys/types.h>
>  #  include <sys/wait.h>   // for waitpid()
> -#  include <unistd.h>     // for fork(), execv(), access()
> +#  include <unistd.h>     // for fork(), execv(), access(), sleep()
>  #  include <setjmp.h>     // for setjmp(), longjmp()
>  #  include <signal.h>     // for signal()
> -#  include <time.h>       // for nanosleep()
>  
>  /**************************************************************************/
>  
> @@ -509,37 +508,30 @@
>      if (0 < timeout && 0 == ret) {
>          // process still active, wait
>          sig_handler_t* old_handler = signal (SIGCHLD, sig_handler);
> -        timespec rem = { timeout, 0 };
>  
> +        unsigned utimeout = unsigned (timeout);
> +
>          do {
> -            timespec req = rem;
> -            if (-1 == nanosleep (&req, &rem)) {
> -                if (EINTR == errno) {
> -                    // possible that the child has exited
> -                    ret = waitpid (pid, &status, WNOHANG);
> -                    if (-1 == ret) {
> -                        rw_error (0, __FILE__, __LINE__,
> -                                  "waitpid (%{P}, %#p, WNOHANG) failed: "
> -                                  "errno = %{#m} (%{m})",
> -                                  pid, &status);
> -                    }
> -                    else if (0 == ret) {
> -                        // child still active
> -                        continue;
> -                    }
> -                    else {
> -                        // child has exited
> -                        RW_ASSERT (pid == ret);
> -                    }
> -                }
> -                else {
> +            rw_info (0, 0, 0, "before sleep: %u", utimeout);
> +            utimeout = sleep (utimeout);
> +            rw_info (0, 0, 0, "after sleep: %u", utimeout);
> +            if (utimeout) {
> +                // possible that the child has exited
> +                ret = waitpid (pid, &status, WNOHANG);
> +                if (-1 == ret) {
>                      rw_error (0, __FILE__, __LINE__,
> -                              "nanosleep (&{%i, 0}, %#p) failed: "
> +                              "waitpid (%{P}, %#p, WNOHANG) failed: "
>                                "errno = %{#m} (%{m})",
> -                              timeout, &rem);
> -
> -                    ret = -1;
> +                              pid, &status);
>                  }
> +                else if (0 == ret) {
> +                    // child still active
> +                    continue;
> +                }
> +                else {
> +                    // child has exited
> +                    RW_ASSERT (pid == ret);
> +                }
>              }
>              else {
>                  // timeout elapsed
> @@ -590,7 +582,7 @@
>  rw_process_kill (rw_pid_t pid, int signo)
>  {
>      // timeout for rw_wait_pid
> -    const int timeout = 1000;
> +    const int timeout = 1;
>  
>  #if defined (_WIN32)
>  


Mime
View raw message