ugBASIC
1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
allow.c
Go to the documentation of this file.
1
/*****************************************************************************
2
* ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3
*****************************************************************************
4
* Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*----------------------------------------------------------------------------
18
* Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19
* (la "Licenza"); è proibito usare questo file se non in conformità alla
20
* Licenza. Una copia della Licenza è disponibile all'indirizzo:
21
*
22
* http://www.apache.org/licenses/LICENSE-2.0
23
*
24
* Se non richiesto dalla legislazione vigente o concordato per iscritto,
25
* il software distribuito nei termini della Licenza è distribuito
26
* "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27
* implicite. Consultare la Licenza per il testo specifico che regola le
28
* autorizzazioni e le limitazioni previste dalla medesima.
29
****************************************************************************/
30
31
/****************************************************************************
32
* INCLUDE SECTION
33
****************************************************************************/
34
35
#include "
../../ugbc.h
"
36
37
/****************************************************************************
38
* CODE SECTION
39
****************************************************************************/
40
46
/* <usermanual>
47
@keyword ALLOW
48
49
@english
50
51
The ''ALLOW'' instruction is the opposite of the ''FORBID'' function. While ''FORBID''
52
completely blocks multitasking, ''ALLOW'' re-enables it, allowing ugBASIC to schedule
53
again the execution of other tasks, passing the execution from one task to another
54
according to its scheduling policy. If a ''PROCEDURE'' has previously called ''FORBID''
55
to assure exclusive access to the CPU, ''ALLOW'' returns control to the other procedures,
56
allowing other procedures to continue execution.
57
58
Note that this type of control is "static": in other words, compilation will stop if
59
the procedure that called ''FORBID'' subsequently wants to call a function that
60
would require multitasking to be active. The call to ''ALLOW'' will restore multitasking,
61
and allow routines of this type to be called.
62
63
Once a procedure has finished executing a section of code that required exclusive access
64
to the processor, it should call ''ALLOW'' to allow other tasks to be executed.
65
66
If a task needs to wait for an event (for example, a signal), it can call ''ALLOW'' before
67
entering a waiting state, allowing other tasks to execute their code while the waiting task
68
is suspended.
69
70
Using ''FORBID'' and ''ALLOW'' in a balanced way is essential to achieve both good
71
performance and correct synchronization between parallel procedures. In many cases,
72
more sophisticated synchronization mechanisms, such as shared variables, could be used
73
without completely disabling multitasking.
74
75
@italian
76
L'istruzione ''ALLOW'' è l'opposto della funzione ''FORBID''. Mentre ''FORBID''
77
blocca completamente il multitasking, ''ALLOW'' lo riattiva, consentendo a ugBASIC
78
di pianificare nuovamente l'esecuzione di altri task, passando l'esecuzione da un
79
task all'altro in base alla sua politica di pianificazione. Se una ''PROCEDURE''
80
ha precedentemente chiamato ''FORBID'' per garantire l'accesso esclusivo alla CPU,
81
''ALLOW'' restituisce il controllo alle altre procedure, consentendo ad altre
82
procedure di continuare l'esecuzione.
83
84
Nota che questo tipo di controllo è "statico": in altre parole, la compilazione
85
si interromperà se la procedura che ha chiamato ''FORBID'' desidera successivamente
86
chiamare una funzione che richiederebbe l'attivazione del multitasking. La chiamata
87
a ''ALLOW'' ripristinerà il multitasking e consentirà la chiamata di routine di
88
questo tipo.
89
90
Una volta che una procedura ha terminato di eseguire una sezione di codice che
91
richiedeva l'accesso esclusivo al processore, dovrebbe chiamare ''ALLOW'' per
92
consentire l'esecuzione di altre attività.
93
94
Se un'attività deve attendere un evento (ad esempio, un segnale), può chiamare
95
''ALLOW'' prima di entrare in uno stato di attesa, consentendo ad altre attività
96
di eseguire il loro codice mentre l'attività di attesa è sospesa.
97
98
Utilizzare ''FORBID'' e ''ALLOW'' in modo equilibrato è essenziale per ottenere
99
sia buone prestazioni che una corretta sincronizzazione tra procedure parallele.
100
In molti casi, meccanismi di sincronizzazione più sofisticati, come le variabili
101
condivise, potrebbero essere utilizzati senza disabilitare completamente il
102
multitasking.
103
104
@syntax ALLOW
105
106
@example PARALLEL PROCEDURE test
107
@example FORBID
108
@example ' busy waiting, multitasking is suspended!
109
@example FOR i=0 TO 1000: WAIT 1 MS : NEXT i
110
@example ALLOW
111
@example END PROC
112
113
@seeAlso FORBID
114
115
@target all
116
</usermanual> */
117
void
allow
(
Environment
* _environment ) {
118
119
_environment->
anyProtothread
= 1;
120
121
if
( _environment->
protothreadForbid
) {
122
_environment->
protothreadForbid
= 0;
123
}
else
{
124
CRITICAL_MULTITASKING_NOT_FORBIDDEN
();
125
}
126
127
}
128
allow
void allow(Environment *_environment)
Emit code for YIELD.
Definition
allow.c:117
_Environment::anyProtothread
int anyProtothread
Definition
ugbc.h:2835
_Environment::protothreadForbid
int protothreadForbid
Definition
ugbc.h:2845
ugbc.h
Environment
struct _Environment Environment
Structure of compilation environment.
CRITICAL_MULTITASKING_NOT_FORBIDDEN
#define CRITICAL_MULTITASKING_NOT_FORBIDDEN()
Definition
ugbc.h:3702
Z:
ugbasic
ugbc
src
targets
common
allow.c
Generated by
1.16.1