00001
00002
00003
00004
00005 #include "ace/OS_NS_errno.h"
00006 #include "ace/Global_Macros.h"
00007
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009
00010 ACE_INLINE pid_t
00011 ACE_OS::wait (int *status)
00012 {
00013 ACE_OS_TRACE ("ACE_OS::wait");
00014 #if defined (ACE_LACKS_WAIT)
00015 ACE_UNUSED_ARG (status);
00016 ACE_NOTSUP_RETURN (0);
00017 #else
00018 # if defined (ACE_HAS_UNION_WAIT)
00019 ACE_OSCALL_RETURN (::wait ((union wait *) status), pid_t, -1);
00020 # else
00021 ACE_OSCALL_RETURN (::wait (status), pid_t, -1);
00022 # endif
00023 #endif
00024 }
00025
00026 ACE_INLINE pid_t
00027 ACE_OS::waitpid (pid_t pid,
00028 ACE_exitcode *status,
00029 int wait_options,
00030 ACE_HANDLE handle)
00031 {
00032 ACE_OS_TRACE ("ACE_OS::waitpid");
00033 #if defined (ACE_LACKS_WAITPID)
00034 ACE_UNUSED_ARG (pid);
00035 ACE_UNUSED_ARG (status);
00036 ACE_UNUSED_ARG (wait_options);
00037 ACE_UNUSED_ARG (handle);
00038
00039 ACE_NOTSUP_RETURN (0);
00040 #elif defined (ACE_WIN32)
00041 int blocking_period = ACE_BIT_ENABLED (wait_options, WNOHANG)
00042 ? 0
00043 : INFINITE;
00044
00045 ACE_HANDLE phandle = handle;
00046
00047 if (phandle == 0)
00048 {
00049 phandle = ::OpenProcess (SYNCHRONIZE,
00050 FALSE,
00051 pid);
00052
00053 if (phandle == 0)
00054 {
00055 ACE_OS::set_errno_to_last_error ();
00056 return -1;
00057 }
00058 }
00059
00060 pid_t result = pid;
00061
00062
00063
00064 switch (::WaitForSingleObject (phandle,
00065 blocking_period))
00066 {
00067 case WAIT_OBJECT_0:
00068 if (status != 0)
00069
00070
00071 ::GetExitCodeProcess (phandle,
00072 status);
00073 break;
00074 case WAIT_TIMEOUT:
00075 errno = ETIME;
00076 result = 0;
00077 break;
00078 default:
00079 ACE_OS::set_errno_to_last_error ();
00080 result = -1;
00081 }
00082 if (handle == 0)
00083 ::CloseHandle (phandle);
00084 return result;
00085 #elif defined(ACE_TANDEM_T1248_PTHREADS)
00086 ACE_UNUSED_ARG (handle);
00087 ACE_OSCALL_RETURN (::spt_waitpid (pid, status, wait_options),
00088 pid_t, -1);
00089 #else
00090 ACE_UNUSED_ARG (handle);
00091 ACE_OSCALL_RETURN (::waitpid (pid, status, wait_options),
00092 pid_t, -1);
00093 #endif
00094 }
00095
00096 ACE_INLINE pid_t
00097 ACE_OS::wait (pid_t pid,
00098 ACE_exitcode *status,
00099 int wait_options,
00100 ACE_HANDLE handle)
00101 {
00102 ACE_OS_TRACE ("ACE_OS::wait");
00103 return ACE_OS::waitpid (pid,
00104 status,
00105 wait_options,
00106 handle);
00107 }
00108
00109 ACE_END_VERSIONED_NAMESPACE_DECL