Rev 228 | Go to most recent revision | 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 | ------------ |
||
318 | giacomo | 21 | CVS : $Id: cancel.c,v 1.3 2003-11-05 15:05:11 giacomo Exp $ |
2 | pj | 22 | |
23 | File: $File$ |
||
318 | giacomo | 24 | Revision: $Revision: 1.3 $ |
25 | Last update: $Date: 2003-11-05 15:05:11 $ |
||
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> |
||
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 | { |
||
318 | giacomo | 88 | SYS_FLAGS f; |
89 | |||
90 | f = kern_fsave(); |
||
2 | pj | 91 | if (state != TASK_CANCEL_ENABLE && |
228 | giacomo | 92 | state != TASK_CANCEL_DISABLE) { |
318 | giacomo | 93 | kern_frestore(f); |
2 | pj | 94 | return -1; |
228 | giacomo | 95 | } |
2 | pj | 96 | |
97 | *oldstate = (proc_table[exec_shadow].control & KILL_ENABLED) != 0; |
||
98 | proc_table[exec_shadow].control &= ~KILL_ENABLED; |
||
99 | proc_table[exec_shadow].control |= state; |
||
100 | |||
318 | giacomo | 101 | kern_frestore(f); |
2 | pj | 102 | return 0; |
103 | } |
||
104 | |||
105 | /*+ This primitive set the cancellation type of the task +*/ |
||
106 | int task_setcanceltype(int type, int *oldtype) |
||
107 | { |
||
318 | giacomo | 108 | SYS_FLAGS f; |
109 | |||
110 | f = kern_fsave(); |
||
2 | pj | 111 | if (type != TASK_CANCEL_DEFERRED && |
228 | giacomo | 112 | type != TASK_CANCEL_ASYNCHRONOUS) { |
318 | giacomo | 113 | kern_frestore(f); |
2 | pj | 114 | return -1; |
228 | giacomo | 115 | } |
2 | pj | 116 | |
117 | *oldtype = (proc_table[exec_shadow].control & KILL_DEFERRED) != 0; |
||
118 | proc_table[exec_shadow].control &= ~KILL_DEFERRED; |
||
119 | proc_table[exec_shadow].control |= type; |
||
120 | |||
318 | giacomo | 121 | kern_frestore(f); |
2 | pj | 122 | return 0; |
123 | } |