/* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; int rc; assert( ppThread!=0 ); assert( xTask!=0 ); /* This routine is never used in single-threaded mode */ assert( sqlite3GlobalConfig.bCoreMutex!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; memset(p, 0, sizeof(*p)); p->xTask = xTask; p->pIn = pIn; if( sqlite3FaultSim(200) ){ rc = 1; }else{ rc = pthread_create(&p->tid, 0, xTask, pIn); } if( rc ){ p->done = 1; p->pOut = xTask(pIn); } *ppThread = p; return SQLITE_OK; }
/* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; if( sqlite3GlobalConfig.bCoreMutex==0 ){ memset(p, 0, sizeof(*p)); }else{ p->xTask = xTask; p->pIn = pIn; p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id); if( p->tid==0 ){ memset(p, 0, sizeof(*p)); } } if( p->xTask==0 ){ p->id = GetCurrentThreadId(); p->pResult = xTask(pIn); } *ppThread = p; return SQLITE_OK; }
/* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; int rc; assert( ppThread!=0 ); assert( xTask!=0 ); /* This routine is never used in single-threaded mode */ assert( sqlite3GlobalConfig.bCoreMutex!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM_BKPT; memset(p, 0, sizeof(*p)); p->xTask = xTask; p->pIn = pIn; /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a ** function that returns SQLITE_ERROR when passed the argument 200, that ** forces worker threads to run sequentially and deterministically ** for testing purposes. */ if( sqlite3FaultSim(200) ){ rc = 1; }else{ rc = pthread_create(&p->tid, 0, xTask, pIn); } if( rc ){ p->done = 1; p->pOut = xTask(pIn); } *ppThread = p; return SQLITE_OK; }
/* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM_BKPT; /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a ** function that returns SQLITE_ERROR when passed the argument 200, that ** forces worker threads to run sequentially and deterministically ** (via the sqlite3FaultSim() term of the conditional) for testing ** purposes. */ if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ memset(p, 0, sizeof(*p)); }else{ p->xTask = xTask; p->pIn = pIn; p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id); if( p->tid==0 ){ memset(p, 0, sizeof(*p)); } } if( p->xTask==0 ){ p->id = GetCurrentThreadId(); p->pResult = xTask(pIn); } *ppThread = p; return SQLITE_OK; }
/* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; if( (SQLITE_PTR_TO_INT(p)/17)&1 ){ p->xTask = xTask; p->pIn = pIn; }else{ p->xTask = 0; p->pResult = xTask(pIn); } *ppThread = p; return SQLITE_OK; }
int main(void) { volatile int vcnt=0; volatile int mscnt=0; /* Set Basis System For STM32 Primer2 */ Set_System(); /* Set SysTickCounter for _delay_ms(); / _delay_us(); */ SysTickInit(INTERVAL); /* Select GPS-LOGGER/USB-MSC/USB-CDC Mode */ for(; mscnt<3; mscnt++){ _delay_ms(1000); if(!(GPIO_ReadInputDataBit(GPIOE, KEY_R) | GPIO_ReadInputDataBit(GPIOE, KEY_L))){ vcnt = 1; break; } } /* Enable IWDG */ IWDG_Enable(); /* Install Main GPS tracker Function */ if(vcnt){ xTask = gps_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = NOP_Process; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = NOP_Process; } /* Install USB-CDC VirtualCOM Function */ else if(GPIO_ReadInputDataBit(GPIOE, KEY_L)){ TaskStat = STM32_VCOM; xTask = cdc_task; xUART_IRQ = CDC_IRQ; xEP1_IN_Callback = CDC_EP1_IN_Callback; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = CDC_EP3_OUT_Callback; xSOF_Callback = CDC_SOF_Callback; xUSB_Istr = CDC_USB_Istr; CDC_SetStructure(); } /* Install USB-MSC Function */ else if(GPIO_ReadInputDataBit(GPIOE, KEY_R)){ TaskStat = STM32_MSC; xTask = msc_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = MSC_EP1_IN_Callback; xEP2_OUT_Callback = MSC_EP2_OUT_Callback; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = MSC_USB_Istr; MSC_SetStructure(); } else{ /* Fool Proof */ xTask = gps_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = NOP_Process; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = NOP_Process; } /* Main Loop */ while (1) { xTask(); } }