Rev 1618 | Details | Compare with Previous | 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 | ------------ |
||
915 | pj | 21 | CVS : $Id: cancel.c,v 1.4 2005-01-08 14:44:06 pj Exp $ |
2 | pj | 22 | |
23 | File: $File$ |
||
915 | pj | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2005-01-08 14:44:06 $ |
||
2 | pj | 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> |
||
1621 | fabio | 56 | #include <arch/stdlib.h> |
57 | #include <arch/stdio.h> |
||
58 | #include <arch/string.h> |
||
2 | pj | 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); |
||
915 | pj | 80 | scheduler(); |
2 | pj | 81 | ll_context_to(proc_table[exec_shadow].context); |
82 | } |
||
83 | kern_frestore(f); |
||
84 | } |
||
85 | |||
86 | /*+ This primitive set the cancellation state of the task +*/ |
||
87 | int task_setcancelstate(int state, int *oldstate) |
||
88 | { |
||
318 | giacomo | 89 | SYS_FLAGS f; |
90 | |||
91 | f = kern_fsave(); |
||
2 | pj | 92 | if (state != TASK_CANCEL_ENABLE && |
228 | giacomo | 93 | state != TASK_CANCEL_DISABLE) { |
318 | giacomo | 94 | kern_frestore(f); |
2 | pj | 95 | return -1; |
228 | giacomo | 96 | } |
2 | pj | 97 | |
98 | *oldstate = (proc_table[exec_shadow].control & KILL_ENABLED) != 0; |
||
99 | proc_table[exec_shadow].control &= ~KILL_ENABLED; |
||
100 | proc_table[exec_shadow].control |= state; |
||
101 | |||
318 | giacomo | 102 | kern_frestore(f); |
2 | pj | 103 | return 0; |
104 | } |
||
105 | |||
106 | /*+ This primitive set the cancellation type of the task +*/ |
||
107 | int task_setcanceltype(int type, int *oldtype) |
||
108 | { |
||
318 | giacomo | 109 | SYS_FLAGS f; |
110 | |||
111 | f = kern_fsave(); |
||
2 | pj | 112 | if (type != TASK_CANCEL_DEFERRED && |
228 | giacomo | 113 | type != TASK_CANCEL_ASYNCHRONOUS) { |
318 | giacomo | 114 | kern_frestore(f); |
2 | pj | 115 | return -1; |
228 | giacomo | 116 | } |
2 | pj | 117 | |
118 | *oldtype = (proc_table[exec_shadow].control & KILL_DEFERRED) != 0; |
||
119 | proc_table[exec_shadow].control &= ~KILL_DEFERRED; |
||
120 | proc_table[exec_shadow].control |= type; |
||
121 | |||
318 | giacomo | 122 | kern_frestore(f); |
2 | pj | 123 | return 0; |
124 | } |