int main(int argc, char** argv) { //printf("Thread %d bootting\n", thread_id()); if(thread_id() == 0) { ginit(argc, argv); } thread_barrior(); init(argc, argv); thread_barrior(); printf("PacketNgin APP Start\n"); perf(); perf(); perf(); /* uint32_t i = 0; while(1) { uint32_t count = ni_count(); if(count > 0) { i = (i + 1) % count; NetworkInterface* ni = ni_get(i); if(ni_has_input(ni)) { process(ni); } } } */ thread_barrior(); destroy(); thread_barrior(); if(thread_id() == 0) { gdestroy(argc, argv); } while(1); return 0; }
int main(int argc, char** argv) { printf("Test %d\n", argc); printf("Thread %d booting\n", thread_id()); if(thread_id() == 0) { ginit(argc, argv); } thread_barrior(); init(argc, argv); thread_barrior(); char key[] = "password"; char message[] = "Hello World"; printf("Plain text: "); for(int i = 0; i < sizeof(message); i++) { printf("%02x", message[i]); } printf("\n"); char* encrypted = Encrypt(key, message, sizeof(message)); printf("Encry text: "); for(int i = 0; i < sizeof(message); i++) { printf("%02x", encrypted[i]); } printf("\n"); char* decrypted = Decrypt(key, encrypted, sizeof(message)); printf("Decry text: "); for(int i = 0; i < sizeof(message); i++) { printf("%02x", decrypted[i]); } printf("\n"); thread_barrior(); destroy(); thread_barrior(); if(thread_id() == 0) { gdestroy(argc, argv); } return 0; }
/*-------------------------------------------------------------------*/ static void sigint_handler (int signo) { // logmsg ("impl.c: sigint handler entered for thread %lu\n",/*debug*/ // thread_id()); /*debug*/ UNREFERENCED(signo); signal(SIGINT, sigint_handler); /* Ignore signal unless presented on console thread */ if ( !equal_threads( thread_id(), sysblk.cnsltid ) ) return; /* Exit if previous SIGINT request was not actioned */ if (sysblk.sigintreq) { /* Release the configuration */ release_config(); delayed_exit(1); } /* Set SIGINT request pending flag */ sysblk.sigintreq = 1; /* Activate instruction stepping */ sysblk.inststep = 1; SET_IC_TRACE; return; } /* end function sigint_handler */
void dispatch(F fun) { if (std::this_thread::get_id() == thread_id()) { fun(); return; } post(std::move(fun)); }
bool mutex_unlock(mutex_t* mutex) { if (!mutex->lockcount) { log_warnf(0, WARNING_SUSPICIOUS, STRING_CONST("Unable to unlock unlocked mutex %.*s"), (int)mutex->name.length, mutex->name.str); return false; } FOUNDATION_ASSERT(mutex->lockedthread == thread_id()); --mutex->lockcount; #if !BUILD_DEPLOY profile_unlock(mutex->name.str, mutex->name.length); #endif #if FOUNDATION_PLATFORM_WINDOWS LeaveCriticalSection((CRITICAL_SECTION*)mutex->csection); #elif FOUNDATION_PLATFORM_POSIX || FOUNDATION_PLATFORM_PNACL if (pthread_mutex_unlock(&mutex->mutex) != 0) { FOUNDATION_ASSERT_FAILFORMAT("unable to unlock mutex %s", mutex->name.str); return false; } #else # error mutex_unlock not implemented #endif return true; }
char * nast_errmsg(nasth *s) { nast_response *ar; errcodes ec; ec = nast_geterr(s); if (ec == NAST_SERVER_ERR) { nast_array *aa; ar = getmyresponse(s, thread_id()); if (ar == NULL) return nast_errmsgs[NAST_UNKNOWN_RESPONSE]; aa = build_result(s, ar->buffer, ar->bufflen); if (aa == NULL || aa->nitems == 0) return nast_errmsgs[NAST_UNKNOWN_RESPONSE]; if (ar->errmsg != NULL) free(ar->errmsg); ar->errmsg = malloc(aa->items[0]->strlen); if (ar->errmsg == NULL) return nast_errmsgs[NAST_UNKNOWN_RESPONSE]; memcpy(ar->errmsg, aa->items[0]->strdata, aa->items[0]->strlen); nast_free_result(aa); return ar->errmsg; } return nast_errmsgs[ec]; }
void MemoryHeader::unlock(STATE) { while(true) { MemoryFlags h = header.load(std::memory_order_acquire); if(thread_id() == state->vm()->thread_id()) { if(extended_header_p()) { ExtendedHeader* hh = extended_header(); if(hh->lock_extended_p()) { hh->get_lock()->unlock(state); return; } else { int locked_count = locked_count_field.get(hh->header); if(locked_count > 0) { ExtendedHeader* eh = ExtendedHeader::create_copy( locked_count_field.set(hh->header, locked_count - 1), hh); MemoryFlags nh = extended_flags(eh); if(header.compare_exchange_strong(h, nh, std::memory_order_release)) { return; } eh->delete_header(); } else { Exception::raise_runtime_error(state, "unlocking owned, extended-header, non-locked object"); } } } else { int locked_count = locked_count_field.get(h); if(locked_count > 0) { MemoryFlags nh = locked_count_field.set(h, locked_count - 1); if(header.compare_exchange_strong(h, nh, std::memory_order_release)) { return; } } else { Exception::raise_runtime_error(state, "unlocking owned, non-locked object"); } } } else { if(extended_header_p()) { ExtendedHeader* hh = extended_header(); if(hh->lock_extended_p()) { hh->get_lock()->unlock(state); return; } else { Exception::raise_runtime_error(state, "unlocking non-owned, extended-header, non-locked object"); } } else { Exception::raise_runtime_error(state, "unlocking non-owned, non-locked object"); } } } }
static void _log_outputf( uint64_t context, int severity, const char* prefix, const char* format, va_list list, void* std ) { log_timestamp_t timestamp = _log_make_timestamp(); uint64_t tid = thread_id(); unsigned int pid = thread_hardware(); int need, more, remain, size = 383; char local_buffer[385]; char* buffer = local_buffer; while(1) { //This is guaranteed to always fit in minimum size of 383 bytes defined above, so need is always > 0 if( _log_prefix ) need = snprintf( buffer, size, "[%u:%02u:%02u.%03u] <%" PRIx64 ":%d> %s", timestamp.hours, timestamp.minutes, timestamp.seconds, timestamp.milliseconds, tid, pid, prefix ); else need = snprintf( buffer, size, "%s", prefix ); remain = size - need; { va_list clist; va_copy( clist, list ); more = vsnprintf( buffer + need, remain, format, clist ); va_end( clist ); } if( ( more > -1 ) && ( more < remain ) ) { buffer[need+more] = '\n'; buffer[need+more+1] = 0; #if FOUNDATION_PLATFORM_WINDOWS OutputDebugStringA( buffer ); #endif #if FOUNDATION_PLATFORM_ANDROID if( _log_stdout ) __android_log_write( ANDROID_LOG_DEBUG + severity - 1, environment_application()->short_name, buffer ); #else if( _log_stdout && std ) fprintf( std, "%s", buffer ); #endif if( _log_callback ) _log_callback( context, severity, buffer ); break; } if( ( more > -1 ) && ( need > -1 ) ) size = more + need + 1; else size *= 2; if( buffer != local_buffer ) memory_deallocate( buffer ); buffer = memory_allocate( size + 2, 0, MEMORY_TEMPORARY ); } if( buffer != local_buffer ) memory_deallocate( buffer ); }
factor_vm* new_factor_vm() { THREADHANDLE thread = thread_id(); factor_vm* newvm = new factor_vm(thread); register_vm_with_thread(newvm); thread_vms[thread] = newvm; return newvm; }
void profile_begin_block( const char* message ) { uint32_t parent; if( !_profile_enable ) return; parent = get_thread_profile_block(); if( !parent ) { //Allocate new master block profile_block_t* block = _profile_allocate_block(); uint32_t blockindex; if( !block ) return; blockindex = BLOCK_INDEX( block ); block->data.id = atomic_add32( &_profile_counter, 1 ); string_copy( block->data.name, message, MAX_MESSAGE_LENGTH ); block->data.processor = thread_hardware(); block->data.thread = (uint32_t)thread_id(); block->data.start = time_current() - _profile_ground_time; set_thread_profile_block( blockindex ); } else { //Allocate new child block profile_block_t* parentblock; profile_block_t* subblock = _profile_allocate_block(); uint32_t subindex; if( !subblock ) return; subindex = BLOCK_INDEX( subblock ); parentblock = GET_BLOCK( parent ); subblock->data.id = atomic_add32( &_profile_counter, 1 ); subblock->data.parentid = parentblock->data.id; string_copy( subblock->data.name, message, MAX_MESSAGE_LENGTH ); subblock->data.processor = thread_hardware(); subblock->data.thread = (uint32_t)thread_id(); subblock->data.start = time_current() - _profile_ground_time; subblock->previous = parent; subblock->sibling = parentblock->child; if( parentblock->child ) GET_BLOCK( parentblock->child )->previous = subindex; parentblock->child = subindex; set_thread_profile_block( subindex ); } }
factor_vm *new_factor_vm() { factor_vm *newvm = new factor_vm(); register_vm_with_thread(newvm); thread_vms[thread_id()] = newvm; return newvm; }
int _thread_id(int *id) { if (!id) { return ERR_MALLOC; } *id = thread_id(NULL); return 0; }
void lua_release_execution_right(lua_t* env) { FOUNDATION_ASSERT(atomic_load64(&env->executing_thread) == thread_id()); FOUNDATION_ASSERT(env->executing_count > 0); if (!--env->executing_count) { atomic_store64(&env->executing_thread, 0); semaphore_post(&env->execution_right); } }
virtual void* run() { const char* myname = "run"; printf("%s: thread id: %lu, %lu\r\n", myname, thread_id(), acl::thread::thread_self()); if (auto_destroy_) delete this; return NULL; }
int main(int argc, char** argv) { printf("Thread %d booting\n", thread_id()); if(thread_id() == 0) { ginit(argc, argv); } thread_barrior(); init(argc, argv); thread_barrior(); //char name[128] = { 0, }; char *name; printf("Input your name: "); //fflush(stdout); while(1) { //int len = scanf("%s", name); name = readline(); printf("readline()\n"); if(name){ printf("%s\n", name); } int len = strlen(name); printf("%s\n", name); if(len > 0) { printf("%d out> Hello %s from thread %d\n", len, name, thread_id()); //fprintf(stdout, "%d out> Hello %s from thread %d\n", len, name, thread_id()); //fprintf(stderr, "%d err> Hello %s from thread %d\n", len, name, thread_id()); fflush(stdout); } } thread_barrior(); destroy(); thread_barrior(); if(thread_id() == 0) { gdestroy(argc, argv); } return 0; }
static int fact(int n) { /* store address of some variable on stack */ stack_array[thread_id()] = (long *)&n; if (n == 1) { return 1; } return n * fact(n - 1); }
DLL_EXPORT void ptt_pthread_trace (int trclass, char * type, void *data1, void *data2, char *loc, int result) { int i, n; if (pttrace == NULL || pttracen == 0 || !(pttclass & trclass) ) return; /* ** Fish debug: it appears MSVC sometimes sets the __FILE__ macro ** to a full path filename (rather than just the filename only) ** under certain circumstances. (I think maybe it's only for .h ** files since vstore.h is the one that's messing up). Therefore ** for MSVC we need to convert it to just the filename. ((sigh)) */ #if defined( _MSVC_ ) // fish debug; appears to be vstore.h // maybe all *.h files are this way?? { char* p = strrchr( loc, '\\' ); if (!p) p = strrchr( loc, '/' ); if (p) loc = p+1; } #endif /* * Messages from timer.c, clock.c and/or logger.c are not usually * that interesting and take up table space. Check the flags to * see if we want to trace them. */ if (!strncasecmp(loc, "timer.c:", 8) && !(pttclass & PTT_CL_TMR)) return; if (!strncasecmp(loc, "clock.c:", 8) && !(pttclass & PTT_CL_TMR)) return; if (!strncasecmp(loc, "logger.c:", 9) && !(pttclass & PTT_CL_LOG)) return; /* check for `nowrap' */ if (pttnowrap && pttracex + 1 >= pttracen) return; OBTAIN_PTTLOCK; if (pttrace == NULL || (n = pttracen) == 0) { RELEASE_PTTLOCK; return; } i = pttracex++; if (pttracex >= n) pttracex = 0; RELEASE_PTTLOCK; pttrace[i].tid = thread_id(); pttrace[i].trclass = trclass; pttrace[i].type = type; pttrace[i].data1 = data1; pttrace[i].data2 = data2; pttrace[i].loc = loc; if (pttnotod == 0) gettimeofday(&pttrace[i].tv,NULL); pttrace[i].result = result; }
nast_array * nast_get_result(nasth *s) { nast_response *ar; ar = getmyresponse(s, thread_id()); if (ar == NULL) return NULL; return build_result(s, ar->buffer, ar->bufflen); }
void define_formatters(Writer& writer) { writer.replace_formatter("osthread", shepherd_thread_id()); writer.replace_formatter("locality", locality_prefix()); writer.replace_formatter("hpxthread", thread_id()); writer.replace_formatter("hpxphase", thread_phase()); writer.replace_formatter("hpxparent", parent_thread_id()); writer.replace_formatter("hpxparentphase", parent_thread_phase()); writer.replace_formatter("parentloc", parent_thread_locality()); writer.replace_formatter("hpxcomponent", thread_component_id()); }
PROCESS_INFORMATION ScopedProcessInformation::Take() { PROCESS_INFORMATION process_information = {}; process_information.hProcess = process_handle_.Take(); process_information.hThread = thread_handle_.Take(); process_information.dwProcessId = process_id(); process_information.dwThreadId = thread_id(); process_id_ = 0; thread_id_ = 0; return process_information; }
static int add_reqid(char *buffer) { unsigned short tid, n_tid; tid = thread_id(); n_tid = htons(tid); memcpy(buffer, &n_tid, sizeof(tid)); return sizeof(tid); }
/*-------------------------------------------------------------------*/ static int hthread_getschedprio( TID tid ) { int prio, dummy; struct sched_param param; memset( ¶m, 0, sizeof( param )); if (equal_threads(tid,0)) tid = thread_id(); prio = (hthread_getschedparam( tid, &dummy, ¶m ) == 0) ? param.sched_priority : INT_MAX; return prio; }
/*-------------------------------------------------------------------*/ static int hthread_setschedprio( TID tid, int prio ) { int rc; struct sched_param param; memset( ¶m, 0, sizeof( param )); if (equal_threads(tid,0)) tid = thread_id(); param.sched_priority = prio; rc = hthread_setschedparam( tid, herc_policy, ¶m ); return rc; }
/* thread to print trace after timeout */ void *ptt_timeout() { struct timeval now; struct timespec tm; WRMSG(HHC00100, "I", (u_long)thread_id(), getpriority(PRIO_PROCESS,0),"PTT timeout timer"); obtain_lock (&ptttolock); gettimeofday (&now, NULL); tm.tv_sec = now.tv_sec + pttto; tm.tv_nsec = now.tv_usec * 1000; timed_wait_condition (&ptttocond, &ptttolock, &tm); if (thread_id() == ptttotid) { ptt_pthread_print(); pttto = 0; ptttotid = 0; } release_lock (&ptttolock); WRMSG(HHC00101, "I", (u_long)thread_id(), getpriority(PRIO_PROCESS,0), "PTT timeout timer"); return NULL; }
int InputModule::recordstart(lua_State* L, int idx) { InputList* list = (InputList*) lua_touserdata(L, idx); if (list->getrecording() == 0) { lua_pushvalue(L, idx); uint32 id = luaL_ref(L, LUA_REGISTRYINDEX); list->setrecording(id); PostThreadMessage(thread_id(), IM_ADDRECORD, id, 0); } return 0; }
/*---------------------------------------------------------------------------*/ static void* hao_thread(void* dummy) { char* msgbuf = NULL; int msgidx = -1; int msgamt = 0; char* msgend = NULL; char svchar = 0; int bufamt = 0; UNREFERENCED(dummy); logmsg(HHCAO001I, thread_id(), getpriority(PRIO_PROCESS,0), getpid()); /* Wait for panel thread to engage */ while (!sysblk.panel_init && !sysblk.shutdown) usleep( 10 * 1000 ); /* Do until shutdown */ while (!sysblk.shutdown && msgamt >= 0) { /* wait for message data */ if ((msgamt = log_read(&msgbuf, &msgidx, LOG_BLOCK)) > 0 ) { /* append to existing data */ if (msgamt > (int)((sizeof(ao_msgbuf) - 1) - bufamt) ) msgamt = (int)((sizeof(ao_msgbuf) - 1) - bufamt); strncpy( &ao_msgbuf[bufamt], msgbuf, msgamt ); ao_msgbuf[bufamt += msgamt] = 0; msgbuf = ao_msgbuf; /* process only complete messages */ while (NULL != (msgend = strchr(msgbuf,'\n'))) { /* null terminate message */ svchar = *(msgend+1); *(msgend+1) = 0; /* process message */ hao_message(msgbuf); /* restore destroyed byte */ *(msgend+1) = svchar; msgbuf = msgend+1; } /* shift message buffer */ memmove( ao_msgbuf, msgbuf, bufamt -= (msgbuf - ao_msgbuf) ); } } logmsg(HHCAO002I); return NULL; }
int InputModule::recordstop(lua_State* L, int idx) { InputList* list = (InputList*) lua_touserdata(L, idx); uint32 id = list->getrecording(); if (id) { e->current_thread()->suspend(); PostThreadMessage(thread_id(), IM_REMRECORD, id, (LPARAM) e->current_thread()); return lua_yield(L, 0); } return 0; }
/*-------------------------------------------------------------------*/ void* socket_thread( void* arg ) { int rc; fd_set sockset; int maxfd = 0; int select_errno; int exit_now; UNREFERENCED( arg ); /* Display thread started message on control panel */ logmsg (_("HHCSD020I Socketdevice listener thread started: " "tid="TIDPAT", pid=%d\n"), thread_id(), getpid()); for (;;) { /* Set the file descriptors for select */ FD_ZERO ( &sockset ); maxfd = add_socket_devices_to_fd_set ( 0, &sockset ); SUPPORT_WAKEUP_SOCKDEV_SELECT_VIA_PIPE( maxfd, &sockset ); /* Do the select and save results */ rc = select ( maxfd+1, &sockset, NULL, NULL, NULL ); select_errno = HSO_errno; /* Clear the pipe signal if necessary */ RECV_SOCKDEV_THREAD_PIPE_SIGNAL(); /* Check if it's time to exit yet */ obtain_lock( &bind_lock ); exit_now = ( sysblk.shutdown || IsListEmpty( &bind_head ) ); release_lock( &bind_lock ); if ( exit_now ) break; /* Log select errors */ if ( rc < 0 ) { if ( HSO_EINTR != select_errno ) logmsg( _( "HHCSD021E select failed; errno=%d: %s\n"), select_errno, strerror( select_errno ) ); continue; } /* Check if any sockets have received new connections */ check_socket_devices_for_connections( &sockset ); } logmsg( _( "HHCSD022I Socketdevice listener thread terminated\n" ) ); return NULL; }
int Manager::shut_down (void) { ACE_TRACE (ACE_TEXT ("Manager::shut_down")); ACE_Unbounded_Queue<Worker* >::ITERATOR iter = this->workers_.begin (); Worker **worker_ptr = NULL; do { iter.next (worker_ptr); Worker *worker = (*worker_ptr); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Attempting shutdown of %d\n"), thread_id (worker))); // Send the hangup message. ACE_Message_Block *mb; ACE_NEW_RETURN (mb, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP), -1); worker->putq (mb); // Wait for the exit. worker->wait (); ACE_ASSERT (worker->msg_queue ()->is_empty ()); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Worker %d shut down.\n)"), thread_id (worker))); delete worker; } while (iter.advance ()); shutdown_ = 1; return 0; }
int main(int argc, char** argv) { printf("Thread %d booting\n", thread_id()); if(thread_id() == 0) { time_init(); event_init(); ginit(argc, argv); } thread_barrior(); init(argc, argv); thread_barrior(); /* Start of User Code Area */ int fd; file_init(); file_opendir("/", open_cb, &fd); if(thread_id() == 0) { while(1) { event_loop(); } } /* End of User Code Area */ thread_barrior(); destroy(); thread_barrior(); if(thread_id() == 0) { gdestroy(argc, argv); } return 0; }