View of xos/kernel/status.c


XOS | Parent Directory | View | Download

/* Copyright (C) 2008  Emmanuel Varoquaux
 
   This file is part of XOS.
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
#include "signal.h"
#include "sched.h"
#include "proc.h"
#include "proc_struct.h"
 
#include <condition.h>
#include <consts.h>
 
void status_init(struct proc_struct *proc)
{
  proc->status_available = 0;
  condition_init(&proc->child_status_available_condition);
}
 
static void notify_parent()
{
  /* si le pere est en train de faire un wait(), il sera reveille par le
     condition_signal() et non par SIGCHLD. */
  condition_signal(&current->parent->child_status_available_condition);
  signal(current->parent, SIGCHLD);
}
 
void set_status(int status)
{
  current->status = status;
  current->status_available = 1;
  if (!is_orphan(current))
    notify_parent();
}
 
int wait_child_status()
{
  return condition_wait_interruptible(&current->child_status_available_condition);
}
 
int report_status(struct proc_struct *child, int *status)
{
  if (!child->status_available)
    return 0;
  if (status)
    *status = child->status;
  child->status_available = 0;
  return 1;
}