void cThread::SetMainThreadId(void) { if (mainThreadId == 0) mainThreadId = ThreadId(); else esyslog("ERROR: attempt to set main thread id to %d while it already is %d", ThreadId(), mainThreadId); }
static void WINAPI ServiceSignal(DWORD OpCode) { switch(OpCode) { case SERVICE_CONTROL_PAUSE: { RLOG(ThreadId() << "service pause"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_PAUSE_PENDING; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; PauseService(); ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_PAUSED; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } case SERVICE_CONTROL_CONTINUE: { RLOG(ThreadId() << "service continue"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_CONTINUE_PENDING; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; ContinueService(); ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_RUNNING; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: { RLOG(ThreadId() << "service stop / shutdown"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; ServiceStatus.dwWaitHint = 5000; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) break; StopService(); ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(ServiceStatusHandle, &ServiceStatus); break; } default: { break; } } }
void RunServiceDispatcher(String service_name_) { ASSERT(service_name_.GetLength() < __countof(service_name)); strcpy(service_name, service_name); static SERVICE_TABLE_ENTRY servicetable[] = { { service_name, &ServiceInit }, { NULL, NULL } }; RLOG(ThreadId() << "starting service control dispatcher"); StartServiceCtrlDispatcher(servicetable); RLOG(ThreadId() << "exiting main thread"); return; }
void ThreadsHandler::updateThreads(const GdbMi &data) { // ^done,threads=[{id="1",target-id="Thread 0xb7fdc710 (LWP 4264)", // frame={level="0",addr="0x080530bf",func="testQString",args=[], // file="/.../app.cpp",fullname="/../app.cpp",line="1175"}, // state="stopped",core="0"}],current-thread-id="1" // Emit changed for previous frame. if (m_currentIndex != -1) { dataChanged(m_currentIndex); m_currentIndex = -1; } ThreadId currentId; const GdbMi current = data["current-thread-id"]; if (current.isValid()) currentId = ThreadId(current.data().toLongLong()); const QList<GdbMi> items = data["threads"].children(); const int n = items.size(); for (int index = 0; index != n; ++index) { const GdbMi item = items.at(index); const GdbMi frame = item["frame"]; ThreadData thread; thread.id = ThreadId(item["id"].toInt()); thread.targetId = item["target-id"].toLatin1(); thread.details = item["details"].toLatin1(); thread.core = item["core"].toLatin1(); thread.state = item["state"].toLatin1(); thread.address = frame["addr"].toAddress(); thread.function = frame["func"].toLatin1(); thread.fileName = frame["fullname"].toLatin1(); thread.lineNumber = frame["line"].toInt(); thread.module = QString::fromLocal8Bit(frame["from"].data()); thread.stopped = true; thread.name = item["name"].toLatin1(); if (thread.state == QLatin1String("running")) thread.stopped = false; if (thread.id == currentId) m_currentIndex = index; updateThread(thread); } if (m_currentIndex != -1) dataChanged(m_currentIndex); updateThreadBox(); }
void cThread::SetMainThreadId(void) { if (mainThreadId == 0) mainThreadId = ThreadId(); else XBMC->Log(LOG_ERROR, "ERROR: attempt to set main thread id to %d while it already is %d", ThreadId(), mainThreadId); }
RuntimeQueue* RuntimeQueue::CreateNewThreadQueue(const CString& name, rqe& ec) { C_PTR_CHECK(context); try { DProfContext _(DTEXT(RQ_API "Creating new task queue")); ShPtr<semaphore_t> sem = MkShared<semaphore_t>(); UqLock temp_lock(sem->start_mutex); sem->running.store(true); /* Spawn the thread */ Thread t(ImpCreateNewThreadQueue, name, &sem); auto tid = ThreadId(t.get_id()).hash(); /* Wait for the RuntimeQueue to be created on the thread */ sem->condition.wait(temp_lock); { Lock _(context->globalMod); context->queueThreads[tid] = std::move(t); context->queueFlags.insert({tid, sem}); } return &context->queues.find(tid)->second; } catch(std::exception const& e) { ec = RQE::ThreadSpawn; ec = e.what(); return nullptr; } }
int main(int argc, char *argv[]) { if (argc != 4) errx(1, "need four args: binary, types db, and output file"); init_sli(); const char *binary = argv[1]; const char *typesdb = argv[2]; const char *out = argv[3]; auto ms = MachineState::readELFExec(binary); auto thr = ms->findThread(ThreadId(1)); auto oracle = new Oracle(ms, thr, typesdb); FILE *f = fopen(out, "w"); if (!f) err(1, "opening %s", out); for (auto instrIterator = oracle->type_db->enumerateAllInstructions(); !instrIterator->finished(); instrIterator->advance()) { DynAnalysisRip dar; instrIterator->fetch(&dar); fprintf(f, "%s\n", dar.name()); } if (fclose(f) != 0) err(1, "closing %s", out); return 0; }
LqString LqThreadBase::DebugInfo() const { const char* Prior; switch(Priority) { case LQTHREAD_PRIOR_IDLE: Prior = "idle"; break; case LQTHREAD_PRIOR_LOWER: Prior = "lower"; break; case LQTHREAD_PRIOR_LOW:Prior = "low"; break; case LQTHREAD_PRIOR_NONE: case LQTHREAD_PRIOR_NORMAL: Prior = "normal"; break; case LQTHREAD_PRIOR_HIGH: Prior = "high"; break; case LQTHREAD_PRIOR_HIGHER: Prior = "higher"; break; case LQTHREAD_PRIOR_REALTIME: Prior = "realtime"; break; default: Prior = "unknown"; } char Buf[1024]; LqFbuf_snprintf ( Buf, sizeof(Buf), "--------------\n" "Thread id: %llu\n" "Is work: %c\n" "Priority: %s\n" "Affinity mask: 0x%016llx\n", (unsigned long long)ThreadId(), (char)((IsThreadRunning()) ? '1' : '0'), Prior, AffinMask ); return Buf; }
void ThreadsHandler::removeAll() { beginResetModel(); m_threads.clear(); m_currentId = ThreadId(); endResetModel(); }
void cDirCrawler::Action() { cThreadLock threadLock(this); const char* DirName = pwd.path.c_str(); int LinkLevel = pwd.linkLevel; isyslog("thread %d, Dir '%s'", ThreadId(), DirName); cReadDir d(DirName); struct dirent *e; while (Running() && (e = d.Next()) != NULL) { // Ignore NULL or empty names and all hidden directories and files if (!e->d_name || !strlen(e->d_name) || e->d_name[0] == '.') continue; // construct full path cString buffer(AddDirectory(DirName, e->d_name)); struct stat st; // check if path is a link if (lstat(buffer, &st) != 0) continue; // error if (S_ISLNK(st.st_mode)) { ++LinkLevel; // too many symlink in this path, maybe cyclic if (LinkLevel > MAX_LINK_LEVEL) { isyslog("max link level exceeded - not scanning %s", *buffer); continue; } if (stat(buffer, &st) != 0) continue; // error } cPath nextPath; nextPath.path = *buffer; nextPath.linkLevel = LinkLevel; // if subdirectory, put it in the directory Queue for other threads if (S_ISDIR(st.st_mode)) { isyslog("pwd: %s got '%s' , push '%s'", DirName, e->d_name, *buffer); dirQ->AddPath(nextPath); } else if (S_ISREG(st.st_mode)) { nextPath.filename = e->d_name; // a file AddPathToDatabase(nextPath); } } // while } // Action()
TUint64 CMemSpyEngineHelperSysMemTrackerEntryOpenFile::Key() const { const TUint32 val = ( Type() << 28 ) + ( iUniqueFileId < 24 ) + ThreadId(); TUint64 ret = val; ret <<= 32; // const TUint32 fileNameHash = MemSpyEngineUtils::Hash( *iFileName ); ret += fileNameHash; // return ret; }
static void WINAPI ServiceInit(DWORD argc, LPTSTR *argv) { if(!(ServiceStatusHandle = RegisterServiceCtrlHandler(service_name, &ServiceSignal))) return; ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ServiceStatus.dwCurrentState = SERVICE_START_PENDING; ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwWin32ExitCode = NO_ERROR; ServiceStatus.dwServiceSpecificExitCode = 0; ServiceStatus.dwCheckPoint = 1; ServiceStatus.dwWaitHint = 1000; if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus)) return; RLOG(ThreadId() << "initializing service"); bool inited = InitService(); if(inited) { RLOG(ThreadId() << "service successfully initialized"); ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP; ServiceStatus.dwCurrentState = SERVICE_RUNNING; } else { RLOG(ThreadId() << "service initialization failed"); ServiceStatus.dwControlsAccepted = 0; ServiceStatus.dwCurrentState = SERVICE_STOPPED; } ServiceStatus.dwCheckPoint = 0; if(!SetServiceStatus(ServiceStatusHandle,&ServiceStatus)) return; if(inited) { RLOG(ThreadId() << "running service"); RunService(); RLOG(ThreadId() << "exiting service thread"); service_exited = true; } }
bool CThread::SetPrioritySched_RR(int iPriority) { // Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the // OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects // the thread running away. OSX automatically does this with the CoreAudio audio // device handler thread. int32_t result; thread_extended_policy_data_t theFixedPolicy; // make thread fixed, set to 'true' for a non-fixed thread theFixedPolicy.timeshare = false; result = thread_policy_set(pthread_mach_thread_np(ThreadId()), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); int policy; struct sched_param param; result = pthread_getschedparam(ThreadId(), &policy, ¶m ); // change from default SCHED_OTHER to SCHED_RR policy = SCHED_RR; result = pthread_setschedparam(ThreadId(), policy, ¶m ); return result == 0; }
void ThreadsHandler::notifyStopped(const QByteArray &data) { if (data.isEmpty() || data == "all") { notifyAllStopped(); } else { bool ok; qlonglong id = data.toLongLong(&ok); if (ok) notifyRunning(ThreadId(id)); else // FIXME notifyAllStopped(); } }
int main(void) { threadArg arg[nbThread]; tid MyThreadIds[nbThread]; int i; ftime(&gTime); // On va prendre note du temps de départ du programe. // Initialisation de votre libraire des threads utilisateurs if (ThreadInit() == -1) { perror("Main: Erreur d'initialisation de la librarie!\n"); return 1; } // Il doit maintenant y avoir un thread ID associé au main TIMESTAMPED_PRINTF(("Main: Le thread ID du main est %d.\n", ThreadId())); int y; // Creation des Threads for (i = 0; i < nbThread; i++) { arg[i].Numero = i; // printf("Main: Demarrage du thread numéro //%d\n",arg[i].Numero); if ((MyThreadIds[i] = ThreadCreer(threadFunction, (void *)&arg[i])) < 0) { perror("Erreur lors de la création d'un nouveau thread!\n"); return 1; } TIMESTAMPED_PRINTF( ("Main: Le thread avec ID %d a été créé.\n", MyThreadIds[i])); } // Attendre la fin de tout les threads avec ThreadJoindre for (i = 0; i < nbThread; i++) { // Creation des Threads TIMESTAMPED_PRINTF( ("Main: Je joins le thread ID %d\n", MyThreadIds[i])); ThreadJoindre(MyThreadIds[i]); TIMESTAMPED_PRINTF( ("Main: Le thread ID %d a terminé!\n", MyThreadIds[i])); } TIMESTAMPED_PRINTF(("Main: Tous les threads ont terminé!\n")); // On spin une fois pour s'assurer que le garbage collector fasse son // travail ThreadCeder(); TIMESTAMPED_PRINTF(("Main: je termine.\n")); return EXIT_SUCCESS; }
int CThread::GetMinPriority(void) { #if 0 //#if defined(__APPLE__) struct sched_param sched; int rtn, policy; rtn = pthread_getschedparam(ThreadId(), &policy, &sched); int min = sched_get_priority_min(policy); return(min); #else return(THREAD_PRIORITY_IDLE); #endif }
int CThread::GetMaxPriority(void) { #if 0 //#if defined(__APPLE__) struct sched_param sched; int rtn, policy; rtn = pthread_getschedparam(ThreadId(), &policy, &sched); int max = sched_get_priority_max(policy); return(max); #else return(THREAD_PRIORITY_HIGHEST); #endif }
int CThread::GetNormalPriority(void) { #if 0 //#if defined(__APPLE__) struct sched_param sched; int rtn, policy; rtn = pthread_getschedparam(ThreadId(), &policy, &sched); int min = sched_get_priority_min(policy); int max = sched_get_priority_max(policy); return( min + ((max-min) / 2) ); #else return(THREAD_PRIORITY_NORMAL); #endif }
void ThreadsHandler::setThreads(const Threads &threads) { beginResetModel(); m_threads = threads; bool found = false; for (int i = 0, n = m_threads.size(); i < n; ++i) if (threads.at(i).id == m_currentId) { found = true; break; } if (!found) m_currentId = ThreadId(); m_resetLocationScheduled = false; endResetModel(); updateThreadBox(); }
int main(int argc, char *const argv[]) { if (argc < 7) errx(1, "need at least six arguments: binary, types table, callgraph, static db, output filename, and at least one summary"); const char *binary = argv[1]; const char *types_table = argv[2]; const char *callgraph = argv[3]; const char *staticdb = argv[4]; const char *slidir = argv[5]; const char *const *summary_fnames = argv + 6; int nr_summaries = argc - 6; init_sli(); VexPtr<Oracle> oracle; { MachineState *ms = MachineState::readELFExec(binary); Thread *thr = ms->findThread(ThreadId(1)); oracle = new Oracle(ms, thr, types_table); } oracle->loadCallGraph(oracle, callgraph, staticdb, ALLOW_GC); FILE *logfile = fopen("s2f_perf.log", "w"); for (int i = 0; i < nr_summaries; i++) { fflush(0); std::map<SummaryId, CrashSummary *> summaries; SMScopes scopes; summaries[SummaryId(1)] = readBugReport(&scopes, summary_fnames[i], NULL); fprintf(logfile, "%f: start %s\n", now(), summary_fnames[i]); char *patch = buildPatchForCrashSummary(logfile, oracle, summaries); fprintf(logfile, "%f: start system compile\n", now()); writePatchToFile(false, "s2f_perf.genfix.c", binary, summaries, patch); my_system("/usr/bin/gcc-4.4", "-Wall", "-O", "-shared", "-fPIC", "-I", slidir, "s2f_perf.genfix.c", "-o", "s2f_perf.genfix.so", NULL); fprintf(logfile, "%f: stop system compile\n", now()); fprintf(logfile, "%f: stop\n", now()); unlink("s2f_perf.genfix.c"); unlink("s2f_perf.genfix.so"); } return 0; }
void *cThread::StartThread(cThread *Thread) { Thread->childThreadId = ThreadId(); if (Thread->description) { XBMC->Log(LOG_DEBUG, "%s thread started (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); #ifdef PR_SET_NAME if (prctl(PR_SET_NAME, Thread->description, 0, 0, 0) < 0) XBMC->Log(LOG_ERROR, "%s thread naming failed (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); #endif } Thread->Action(); if (Thread->description) XBMC->Log(LOG_DEBUG, "%s thread ended (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); Thread->running = false; Thread->active = false; return NULL; }
RuntimeQueue* RuntimeQueue::GetCurrentQueue(rqe& ec) { C_PTR_CHECK(context); Lock _(context->globalMod); auto q_id = ThreadId().hash(); auto q_it = context->queues.find(q_id); if(q_it != context->queues.end()) return &(*q_it).second; else { ec = RQE::InvalidQueue; return nullptr; } }
RuntimeQueue* RuntimeQueue::CreateNewQueue(const CString& name) { C_PTR_CHECK(context); Lock _(context->globalMod); auto t_id = ThreadId().hash(); auto q_it = context->queues.find(t_id); if(q_it == context->queues.end()) { context->queues.insert({t_id, RuntimeQueue()}); CurrentThread::SetName(name); return &context->queues[t_id]; } else return &(*q_it).second; }
void threadFunction(void *arg) { long i, cpt; int nTurnToSleep = 3; int nTurnToYield = 2; // On cast le pointeur vers la structure passée lors de l'appel // ThreadCreer(); threadArg *pArg = (threadArg *)arg; // Pour avoir des comportements différents entre threads if (ThreadId() == 2) { nTurnToSleep = 0; nTurnToYield = 1; } for (i = 0; i < 2; i++) { TIMESTAMPED_PRINTF( ("Thread%d: Je tourne avec une variable sur la pile à 0x%p.\n", ThreadId(), &i)); fflush(stdout); for (cpt = 0; cpt < 10000000; cpt++) ; ThreadCeder(); } for (i = 0; i < nTurnToSleep; i++) { TIMESTAMPED_PRINTF( ("Thread%d: Je tourne avec une variable sur la pile à 0x%p.\n", ThreadId(), &i)); fflush(stdout); for (cpt = 0; cpt < 10000000; cpt++) ; int temps = pArg->Numero + 1; TIMESTAMPED_PRINTF(("Thread%d: Je vais dormir pendant %d secondes!\n", ThreadId(), temps)); ThreadDormir(temps); } for (i = 0; i < nTurnToYield; i++) { TIMESTAMPED_PRINTF( ("Thread%d: Je tourne avec une variable sur la pile à 0x%p.\n", ThreadId(), &i)); fflush(stdout); for (cpt = 0; cpt < 300000000; cpt++) ; ThreadCeder(); } TIMESTAMPED_PRINTF(("Thread%d: Je QUITTE!\n", ThreadId())); ThreadQuitter(); return; }
void *cThread::StartThread(cThread *Thread) { Thread->childThreadId = ThreadId(); if (Thread->description) { dsyslog("%s thread started (pid=%d, tid=%d, prio=%s)", Thread->description, getpid(), Thread->childThreadId, Thread->lowPriority ? "low" : "high"); #ifdef PR_SET_NAME if (prctl(PR_SET_NAME, Thread->description, 0, 0, 0) < 0) esyslog("%s thread naming failed (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); #endif } if (Thread->lowPriority) { Thread->SetPriority(19); Thread->SetIOPriority(7); } Thread->Action(); if (Thread->description) dsyslog("%s thread ended (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); Thread->running = false; Thread->active = false; return NULL; }
bool CThread::IsCurrentThread() const { return IsCurrentThread(ThreadId()); }
void Set (void* t,Lock&){ map[ ThreadId() ]=t; }
void Erase( Lock&){ map.erase( ThreadId() );}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ I_Thread::ThreadId Thread_solaris::getSolarisCurrentThreadId() { return ThreadId(new NativeThreadId_solaris(::thr_self())); }
void ThreadsTreeView::rowActivated(const QModelIndex &index) { ThreadId id = ThreadId(index.data(ThreadData::IdRole).toLongLong()); debuggerCore()->currentEngine()->selectThread(id); }