Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Gerardo Lamastra <gerardo@sssup.it>
 *
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://hartik.sssup.it
 */


/**
 ------------
 CVS :        $Id: teste.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-09-02 09:37:48 $
 ------------

 Test Number 14 (E):

 this test is a simple main() function with one other task.

 This test verify the correctness of the sem module.


**/


/*
 * Copyright (C) 2000 Paolo Gai
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "kernel/kern.h"

#include <modules/sem.h>

sem_t s;

TASK pippo(void *a)
{
  int i=0;
  struct timespec t;
//  int last = 0;

  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();

    if (i==0 && t.tv_sec == (int)a) {
      i = 1;
      kern_printf("before sem_wait %d\n",(int)a);
      sem_wait(&s);
      kern_printf("after sem_wait %d\n",(int)a);
    }

    if (i==1 && t.tv_sec == 2+(int)a) {
      i = 2;
      kern_printf("before sem_post %d\n",(int)a);
      sem_post(&s);
      kern_printf("after sem_post %d\n",(int)a);
      return 0;
    }


  } while (1);
}

int main(int argc, char **argv)
{
//  struct timespec t;
//  int i;
  NRT_TASK_MODEL m;
  PID p2,p3;

  nrt_task_default_model(m);
  nrt_task_def_group(m,1);

  nrt_task_def_arg(m,(void *)1);
  p2 = task_create("pippo1", pippo, &m, NULL);
  if (p2 == NIL)
  { kern_printf("Can't create pippo1 task...\n"); return 1; }

  nrt_task_def_arg(m,(void *)2);
  p3 = task_create("pippo2", pippo, &m, NULL);
  if (p3 == NIL)
  { kern_printf("Can't create pippo2 task...\n"); return 1; }

  sem_init(&s,0,1);

  group_activate(1);

  return 0;
}