void main_cleanup() { /* * This might seem superfluous, but there needs to be * another thread to cleanup after 'main'. * It can't kill itself. */ cyg_handle_t thandle = 0, *thandleptr = &thandle; cyg_uint16 tid; cyg_thread_info tinfo; cyg_thread_get_next(thandleptr, &tid); do { cyg_thread_get_info(*thandleptr, tid, &tinfo); if(!strcmp(tinfo.name, "main")) { SHELL_DEBUG_PRINT("Found TID for main [%d]\n", tinfo.handle); cyg_thread_kill(thandle); cyg_thread_delete(thandle); } } while(cyg_thread_get_next(thandleptr, &tid)); }
void System::threadInfo(cTerm & t,int argc,char *argv[]) { cyg_handle_t thread = 0; cyg_uint16 id; cyg_thread_info info; bool flag = 1; t<<t.format(UNDERLINE("% 2s% 15s% 6s % 10s % 10s% 5s\n"),"#", "Name" ,"Prior","S_Size","Used","Perc"); while ( cyg_thread_get_next(&thread,&id) ) { if ( !cyg_thread_get_info(thread,id,&info) ) { break; } if(flag) t<<t.format(CYAN("% 2d% 15s% 6d 0x%08X 0x%08X% 5d\n"),info.id, info.name, (int)info.set_pri, info.stack_size, info.stack_used, (int)((info.stack_used*100)/info.stack_size)); else t<<t.format(CYAN_B("% 2d% 15s% 6d 0x%08X 0x%08X% 5d\n"),info.id, info.name, (int)info.set_pri, info.stack_size, info.stack_used, (int)((info.stack_used*100)/info.stack_size)); flag = !flag; } return; }
void show_threads() { cyg_handle_t thread=0; cyg_uint16 id=0; while(cyg_thread_get_next(&thread,&id)){ cyg_thread_info info; if(!cyg_thread_get_info(thread,id,&info)) break; printf("ID:%4x name:%10s pri:%d stat:%d\n",info.id,info.name?info.name:"----",info.set_pri,info.state); printf("stack size:%d\n",cyg_thread_get_stack_size(info.handle)); } }
void thread_join(cyg_handle_t* handle, cyg_thread* thread, cyg_thread_info* info) { BOOL ex = FALSE; while((ex == FALSE) && (handle != NULL)) { cyg_thread_get_info(*handle, thread->unique_id, info); //diag_printf("state is %d\n",info->state); switch(info->state) { case 16: cyg_thread_delete(*handle); ex = TRUE; break; default: cyg_thread_yield(); break; } } }
static void test_tcp_socket_thread_join(int ithread_handle) { cyg_thread_info info; cyg_uint16 id = 0; cyg_bool rc; cyg_handle_t next_thread = 0; cyg_uint16 next_id = 0; while(cyg_thread_get_next(&next_thread, &next_id) != false) { if(ithread_handle == next_thread) { id = next_id; break; } } while(1) { rc = cyg_thread_get_info(ithread_handle, id, &info); if(rc == false) { printf("Error get thread %d info\n", ithread_handle); break; } else { if((info.state & EXITED) != 0) { break; } } cyg_thread_yield(); } }
void slowPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE ]; cyg_handle_t hThread = 0; cyg_uint16 threadID = 0; #ifdef CYGPKG_IO_PCI cyg_pci_device_id pciDeviceID; #endif /* CYGPKG_IO_PCI */ #ifdef CYGPKG_POWER PowerController *powerControllerInfo; #endif /* CYGPKG_POWER */ int itemsAdded = 0, iterationCount; initRandomData( randomState, buffer, RANDOM_BUFSIZE ); /* Get the thread handle, ID, state, priority, and stack usage for every thread in the system */ for( iterationCount = 0; cyg_thread_get_next( &hThread, &threadID ) && \ iterationCount < FAILSAFE_ITERATIONS_MED; iterationCount++ ) { cyg_thread_info threadInfo; if( !cyg_thread_get_info( hThread, threadID, &threadInfo ) ) continue; addRandomData( randomState, &threadInfo, sizeof( cyg_thread_info ) ); itemsAdded++; } /* Walk the power-management info getting the power-management state for each device. This works a bit strangely, the power controller information is a static table created at system build time so all that we're doing is walking down an array getting one entry after another */ #ifdef CYGPKG_POWER for( powerControllerInfo = &( __POWER__[ 0 ] ), iterationCount = 0; powerControllerInfo != &( __POWER_END__ ) && \ iterationCount < FAILSAFE_ITERATIONS_MED; powerControllerInfo++, iterationCount++ ) { const PowerMode power_get_controller_mode( powerControllerInfo ); addRandomValue( randomState, PowerMode ); } #endif /* CYGPKG_POWER */ /* Add PCI device information if there's PCI support present */ #ifdef CYGPKG_IO_PCI if( cyg_pci_find_next( CYG_PCI_NULL_DEVID, &pciDeviceID ) ) { iterationCount = 0; do { cyg_pci_device pciDeviceInfo; cyg_pci_get_device_info( pciDeviceID, &pciDeviceInfo ); addRandomValue( randomState, PowerMode ); addRandomData( randomState, &pciDeviceInfo, sizeof( cyg_pci_device ) ); itemsAdded++; } while( cyg_pci_find_next( pciDeviceID, &pciDeviceID ) && \ iterationCount++ < FAILSAFE_ITERATIONS_MED ); } #endif /* CYGPKG_IO_PCI */ /* eCOS also has a CPU load-monitoring facility that we could in theory use as a source of entropy but this is really meant for performance- monitoring and isn't very suitable for use as an entropy source. The way this works is that your first call a calibration function cyg_cpuload_calibrate() and then when it you want to get load statistics call cyg_cpuload_create()/cyg_cpuload_get()/ cyg_cpuload_delete(), with get() returning the load over a 0.1s, 1s, and 10s interval. The only one of these capabilities that's even potentially usable is cyg_cpuload_calibrate() and even that's rather dubious for general use since it runs a thread at the highest priority level for 0.1s for calibration purposes and measures the elapsed tick count, which will hardly endear us to other threads in the system. It's really meant for development-mode load measurements and can't safely be used as an entropy source */ /* Flush any remaining data through and produce an estimate of its value. Unlike its use in standard OSes this isn't really a true estimate since virtually all of the entropy is coming from the seed file, all this does is complete the seed-file quality estimate to make sure that we don't fail the entropy test */ endRandomData( randomState, ( itemsAdded > 5 ) ? 20 : 0 ); }