⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coroutin.h

📁 eC++编译器源码
💻 H
字号:

#pragma COROUTINE

//***************************** coroutines ********************************
//                                                                        
// This MODULE implements simple coroutine initialization and transfer    
// functions.  The INITCOROUTINE procedure is used to initialize a        
// coroutine starting with a specified procedure.  The TRANSFER procedure 
// is used to transfer control of the cpu from one coroutine to another.  
//                                                                        
// A simple example using this MODULE follows:                            
//                                                                        
/*                                                                                                                                 
 #include <SYSTEM.h>                                                
 #include <stdio.h>                                
 #include <COROUTINE.h>             
                                                                        
 Coroutine                                                                    
    first,                                                               
    coroutine1,                                                         
    coroutine2;                                             
                                                                        
 char                                                                    
    stack1[1000],                                                             
    stack2[1000];                                 
                                                                        
 void Coroutine1()                                                  
 { int i;                                                                 
   for ( i=1;i<20;i=i+1 ) {                                                                 
     printf("running Coroutine1 ...\n", " ");                             
     Transfer(coroutine1, coroutine2);                                  
    };                                                                
 };                                                        
                                                                        
 void Coroutine2()                                                  
 { int i;                                                                 
   for ( i=1;i<20;i=i+1 ) {                                                                 
     printf("running Coroutine2 ...\n", " ");                             
     Transfer(coroutine2, coroutine1);                                  
    };                                                                
 };                                                        
                                                                        
 void main(void)                                                                  
 {
   InitCoroutine(Coroutine1, ADR(stack1), sizeof(stack1), coroutine1);    
   InitCoroutine(Coroutine2, ADR(stack2), sizeof(stack2), coroutine2);    
   Transfer(first, coroutine1);                                          
 }                                                            
*/                                                                        
//************************************************************************


#include <SYSTEM.h>



//*************************** TYPE COROUTINE *****************************
//                                                                        
// A variable of type COROUTINE is used to identify a coroutine.          
// This variable is set by the INITCOROUTINE procedure when the coroutine 
// is initialized.  It may then be used to reference the coroutine        
// when performing a TRANSFER operation.                                  
//                                                                        
//************************************************************************

typedef void * Coroutine;


//**************************** TRANSFER **********************************
//                                                                        
// This routine just implements a simple coroutine transfer from          
// coroutine "from" to coroutine "to".                                    
//                                                                        
//************************************************************************

void Transfer(Coroutine &from, Coroutine &to);


//*************************** INITCOROUTINE ******************************
//                                                                        
// This routine creates a coroutine starting at procedure "p" with stack  
// at address "stack" and of size "size".  The coroutine identifier for   
// the newly created coroutine is returned in the variable "coroutine".   
//                                                                        
//************************************************************************

void InitCoroutine(void p(), ADDRESS stack, unsigned int stackSize, 
                        Coroutine &coroutine);


//************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -