Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: cancel.c,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-03-29 14:12:51 $
26
 ------------
27
 
28
 This file contains:
29
 
30
 - the cancellation point function
31
 - the setcancelstate and setcanceltype functions
32
 
33
**/
34
 
35
/*
36
 * Copyright (C) 2000 Paolo Gai
37
 *
38
 * This program is free software; you can redistribute it and/or modify
39
 * it under the terms of the GNU General Public License as published by
40
 * the Free Software Foundation; either version 2 of the License, or
41
 * (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
51
 *
52
 */
53
 
54
#include <stdarg.h>
55
#include <ll/ll.h>
56
#include <ll/stdlib.h>
57
#include <ll/stdio.h>
58
#include <ll/string.h>
59
#include <kernel/config.h>
60
#include <kernel/model.h>
61
#include <kernel/const.h>
62
#include <sys/types.h>
63
#include <kernel/types.h>
64
#include <kernel/descr.h>
65
#include <errno.h>
66
#include <kernel/var.h>
67
#include <kernel/func.h>
68
/*+
69
  This primitive creates a cancellation point in the calling task
70
+*/
71
void task_testcancel(void)
72
{
73
  SYS_FLAGS f;  // testcancel may be called from primitives, i.e. task_join
74
 
75
  f = kern_fsave();
76
 
77
  if (proc_table[exec_shadow].control & KILL_ENABLED &&
78
      proc_table[exec_shadow].control & KILL_REQUEST ) {
79
    task_makefree(TASK_CANCELED);
80
    ll_context_to(proc_table[exec_shadow].context);
81
  }
82
  kern_frestore(f);
83
}
84
 
85
/*+ This primitive set the cancellation state of the task +*/
86
int task_setcancelstate(int state, int *oldstate)
87
{
88
  kern_cli();
89
  if (state != TASK_CANCEL_ENABLE &&
90
      state != TASK_CANCEL_DISABLE)
91
    return -1;
92
 
93
  *oldstate = (proc_table[exec_shadow].control & KILL_ENABLED) != 0;
94
  proc_table[exec_shadow].control &= ~KILL_ENABLED;
95
  proc_table[exec_shadow].control |= state;
96
 
97
  kern_sti();
98
  return 0;
99
}
100
 
101
/*+ This primitive set the cancellation type of the task +*/
102
int task_setcanceltype(int type, int *oldtype)
103
{
104
  kern_cli();
105
  if (type != TASK_CANCEL_DEFERRED &&
106
      type != TASK_CANCEL_ASYNCHRONOUS)
107
    return -1;
108
 
109
  *oldtype = (proc_table[exec_shadow].control & KILL_DEFERRED) != 0;
110
  proc_table[exec_shadow].control &= ~KILL_DEFERRED;
111
  proc_table[exec_shadow].control |= type;
112
 
113
  kern_sti();
114
  return 0;
115
}