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
51The ''ALLOW'' instruction is the opposite of the ''FORBID'' function. While ''FORBID''
52completely blocks multitasking, ''ALLOW'' re-enables it, allowing ugBASIC to schedule
53again the execution of other tasks, passing the execution from one task to another
54according to its scheduling policy. If a ''PROCEDURE'' has previously called ''FORBID''
55to assure exclusive access to the CPU, ''ALLOW'' returns control to the other procedures,
56allowing other procedures to continue execution.
57
58Note that this type of control is "static": in other words, compilation will stop if
59the procedure that called ''FORBID'' subsequently wants to call a function that
60would require multitasking to be active. The call to ''ALLOW'' will restore multitasking,
61and allow routines of this type to be called.
62
63Once a procedure has finished executing a section of code that required exclusive access
64to the processor, it should call ''ALLOW'' to allow other tasks to be executed.
65
66If a task needs to wait for an event (for example, a signal), it can call ''ALLOW'' before
67entering a waiting state, allowing other tasks to execute their code while the waiting task
68is suspended.
69
70Using ''FORBID'' and ''ALLOW'' in a balanced way is essential to achieve both good
71performance and correct synchronization between parallel procedures. In many cases,
72more sophisticated synchronization mechanisms, such as shared variables, could be used
73without completely disabling multitasking.
74
75@italian
76L'istruzione ''ALLOW'' è l'opposto della funzione ''FORBID''. Mentre ''FORBID''
77blocca completamente il multitasking, ''ALLOW'' lo riattiva, consentendo a ugBASIC
78di pianificare nuovamente l'esecuzione di altri task, passando l'esecuzione da un
79task all'altro in base alla sua politica di pianificazione. Se una ''PROCEDURE''
80ha precedentemente chiamato ''FORBID'' per garantire l'accesso esclusivo alla CPU,
81''ALLOW'' restituisce il controllo alle altre procedure, consentendo ad altre
82procedure di continuare l'esecuzione.
83
84Nota che questo tipo di controllo è "statico": in altre parole, la compilazione
85si interromperà se la procedura che ha chiamato ''FORBID'' desidera successivamente
86chiamare una funzione che richiederebbe l'attivazione del multitasking. La chiamata
87a ''ALLOW'' ripristinerà il multitasking e consentirà la chiamata di routine di
88questo tipo.
89
90Una volta che una procedura ha terminato di eseguire una sezione di codice che
91richiedeva l'accesso esclusivo al processore, dovrebbe chiamare ''ALLOW'' per
92consentire l'esecuzione di altre attività.
93
94Se 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à
96di eseguire il loro codice mentre l'attività di attesa è sospesa.
97
98Utilizzare ''FORBID'' e ''ALLOW'' in modo equilibrato è essenziale per ottenere
99sia buone prestazioni che una corretta sincronizzazione tra procedure parallele.
100In molti casi, meccanismi di sincronizzazione più sofisticati, come le variabili
101condivise, potrebbero essere utilizzati senza disabilitare completamente il
102multitasking.
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> */
117void allow( Environment * _environment ) {
118
119 _environment->anyProtothread = 1;
120
121 if ( _environment->protothreadForbid ) {
122 _environment->protothreadForbid = 0;
123 } else {
125 }
126
127}
128
void allow(Environment *_environment)
Emit code for YIELD.
Definition allow.c:117
int anyProtothread
Definition ugbc.h:2835
int protothreadForbid
Definition ugbc.h:2845
struct _Environment Environment
Structure of compilation environment.
#define CRITICAL_MULTITASKING_NOT_FORBIDDEN()
Definition ugbc.h:3702