Source

ocaml / otherlibs / win32unix / winwait.c

xleroy 97fb777 

doligez 6cd742a 
xleroy 97fb777 
xleroy bfc57de 
xleroy 97fb777 

xleroy 06a1e11 
xleroy 0357d04 

xleroy 97fb777 







frisch 04b02ba 
frisch 9cc8769 


xleroy 97fb777 
xleroy bfc57de 
xleroy 97fb777 
xleroy 732b5d2 
xleroy 97fb777 
xleroy bfc57de 

doligez 55d06b6 
doligez 3ed6f24 
xleroy f644b60 
doligez 55d06b6 

xleroy 97fb777 


xleroy d4aaf70 



xleroy 9eaedc5 
xleroy 97fb777 
xleroy 03bd357 
xleroy 156fa48 
xleroy bfc57de 
xleroy 8395973 
xleroy bfc57de 
xleroy d4aaf70 
xleroy 90e652b 
xleroy 156fa48 

xleroy 8395973 
xleroy 156fa48 
xleroy 8395973 

xleroy d4aaf70 



xleroy 9eaedc5 
xleroy bfc57de 

xleroy d4aaf70 

doligez f42b67a 

xleroy d4aaf70 
doligez f42b67a 
xleroy 97fb777 
/***********************************************************************/
/*                                                                     */
/*                                OCaml                                */
/*                                                                     */
/*   Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt  */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License, with    */
/*  the special exception on linking described in file ../../LICENSE.  */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <mlvalues.h>
#include <alloc.h>
#include <memory.h>
#include <signals.h>
#include "unixsupport.h"
#include <windows.h>
#include <sys/types.h>

static value alloc_process_status(HANDLE pid, int status)
{
  value res, st;

  st = alloc(1, 0);
  Field(st, 0) = Val_int(status);
  Begin_root (st);
    res = alloc_small(2, 0);
    Field(res, 0) = Val_long((intnat) pid);
    Field(res, 1) = st;
  End_roots();
  return res;
}

enum { CAML_WNOHANG = 1, CAML_WUNTRACED = 2 };

static int wait_flag_table[] = { CAML_WNOHANG, CAML_WUNTRACED };

CAMLprim value win_waitpid(value vflags, value vpid_req)
{
  int flags;
  DWORD status, retcode;
  HANDLE pid_req = (HANDLE) Long_val(vpid_req);
  DWORD err = 0;

  flags = convert_flag_list(vflags, wait_flag_table);
  if ((flags & CAML_WNOHANG) == 0) {
    enter_blocking_section();
    retcode = WaitForSingleObject(pid_req, INFINITE);
    if (retcode == WAIT_FAILED) err = GetLastError();
    leave_blocking_section();
    if (err) {
      win32_maperr(err);
      uerror("waitpid", Nothing);
    }
  }
  if (! GetExitCodeProcess(pid_req, &status)) {
    win32_maperr(GetLastError());
    uerror("waitpid", Nothing);
  }
  if (status == STILL_ACTIVE)
    return alloc_process_status((HANDLE) 0, 0);
  else {
    CloseHandle(pid_req);
    return alloc_process_status(pid_req, status);
  }
}