Example #1
0
int
main(int argc, char *argv[])
{

    processArgs(argc, argv);

    cout << " NumIters " << NumIters << ","
         << " NumEntries " <<  NumEntries << endl;

    if (LockType == FallbackLock::MUTEX_LOCK) {
        GLock = new MutexFallbackLock(PmxLock);
		cout << "Allocated Pthread Mutex lock" << endl;
    } else if (LockType == FallbackLock::SPIN_LOCK) {
        GLock = new SpinFallbackLock(PspLock);
		cout << "Allocated Pthread Spin lock" << endl;
    } else if (LockType == FallbackLock::HLE_LOCK) {
        GLock = new HLELock();
		cout << "Allocated HLE Spin lock" << endl;
    } else if (LockType == FallbackLock::CUSTOM_LOCK) {
        GLock = new CustomSpinLock();
		cout << "Allocated Custom Spin lock" << endl;
    } else {
        cerr << "Error: invalid lock type specified, exiting..." << LockType;
    }

    SharedTable = new KaLib::HashTable<int>(
        NumEntries * NumThreads, GLock);
    for (int ec = NumThreads * NumEntries; ec > 0; --ec) {
        int v = rand();

       	SharedTable->insert(ec, v);
    }

    ThreadWorker_t worker = executeThreadLoopSimple;
	Timer coreTimer("Workers");

	coreTimer.Start();

    createWorkerThreads(NumThreads, worker);
    waitForThreads(NumThreads);

	coreTimer.Stop();

	Timer checker("VerifyHashTable");
	checker.Start();

    checkTable(*SharedTable, NumThreads, NumEntries);

	checker.Stop();

    delete SharedTable;

	coreTimer.PrintElapsedTime("RESULT: Filling up the hash table finished in ");

    checker.PrintElapsedTime("Verification of Hash table done in ");

    return 0;
}
Example #2
0
TheoraVideoManager::TheoraVideoManager(int num_worker_threads) : 
	mDefaultNumPrecachedFrames(16)
{
	g_ManagerSingleton=this;

	logMessage("Initializing Theora Playback Library ("+this->getVersionString()+")");

	mAudioFactory = NULL;
	mWorkMutex=new TheoraMutex();

	// for CPU yuv2rgb decoding
	createYUVtoRGBtables();
	createWorkerThreads(num_worker_threads);
}
Example #3
0
void Controller::runMonitor(double interval) {
  unsigned long intervalUsec =
    static_cast<unsigned long>(interval * concurrency::Util::US_PER_S);
  unsigned long intervalNsec =
    static_cast<unsigned long>(interval * concurrency::Util::NS_PER_S);
  IntervalTimer itimer(intervalNsec);

  itimer.start();
  monitor_->initializeInfo();

  while (true) {
    itimer.sleep();
    monitor_->redisplay(intervalUsec);

    // Break if all the threads are stopped
    bool allStopped = true;
    for (WorkerVector::const_iterator it = workers_.begin();
         it != workers_.end();
         ++it) {
      if ((*it)->isAlive()) {
        allStopped = false;
        break;
      }
    }
    if (allStopped) {
      break;
    }

    // Adjust worker threads based on current QPS
    if (config_->getDesiredQPS() > 0 && numThreads_ < maxThreads_) {
      uint64_t currentQps = monitor_->getCurrentQps();
      uint64_t desiredQps = config_->getDesiredQPS();

      if (currentQps < desiredQps) {
        uint32_t numNewWorkerThreads =
          (desiredQps - currentQps) * numThreads_ / currentQps;
        numNewWorkerThreads =
          std::min(numNewWorkerThreads, maxThreads_ - numThreads_);

        createWorkerThreads(numNewWorkerThreads);
        numThreads_ += numNewWorkerThreads;

        T_LOG_OPER("Total worker threads: %u (max %u)",
                   numThreads_, maxThreads_);
      }
    }
  }
}
Example #4
0
void Controller::startWorkers(uint32_t numThreads) {
  numThreads_ = numThreads;

  intervalTimer_.setRatePerSec(config_->getDesiredQPS());
  intervalTimer_.start();

  // Start all of the WorkerRunners
  createWorkerThreads(numThreads_);

  // Wait for all of the workers to be created.
  //
  // If the monitor starts before all workers are running, the statistics
  // reported for the first interval might be lower than expected.  On the
  // other hand, the monitor correctly handles the case where some workers were
  // already performing operations for some time before the monitor started.
  {
    Synchronized s(initMonitor_);
    while (workers_.size() < numThreads_) {
      initMonitor_.wait();
    }
  }
}
Example #5
0
TheoraVideoManager::TheoraVideoManager(int num_worker_threads) :
    mDefaultNumPrecachedFrames(8)
{
    if (num_worker_threads < 1) throw TheoraGenericException("Unable to create TheoraVideoManager, at least one worker thread is reqired");

    g_ManagerSingleton = this;

    std::string msg = "Initializing Theora Playback Library (" + getVersionString() + ")\n";
#ifdef __THEORA
    msg += "  - libtheora version: " + std::string(th_version_string()) + "\n" +
           "  - libvorbis version: " +  std::string(vorbis_version_string()) + "\n";
#endif
#ifdef _ANDROID
    uint64_t features = android_getCpuFeaturesExt();
    char s[128];
    sprintf(s, "  - Android: CPU Features: %u\n", (unsigned int) features);
    msg += s;
    if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0)
        msg += "  - Android: NEON features NOT SUPPORTED by CPU\n";
    else
        msg += "  - Android: Detected NEON CPU features\n";
#endif

#ifdef __AVFOUNDATION
    msg += "  - using Apple AVFoundation classes.\n";
#endif
#ifdef __FFMPEG
    msg += "  - using FFmpeg library.\n";
#endif

    logMessage(msg + "------------------------------------");
    mAudioFactory = NULL;
    mWorkMutex = new TheoraMutex();

    // for CPU based yuv2rgb decoding
    initYUVConversionModule();

    createWorkerThreads(num_worker_threads);
}
Example #6
0
/**
 * @brief MainWindow::MainWindow
 * @param parent
 */
MainWindow::MainWindow(HashCalcApplication* parent) : QMainWindow()
{
   setWindowTitle(tr("File Hash Calculator"));
   setAttribute(Qt::WA_DeleteOnClose, true);
   setWindowIcon(QIcon(":/mainicon.icns"));

   isOpeningNewProject = false;
   parentapp = parent;

   mainproject = new HashProject;
   filelist = mainproject->getDataTable();

   createActionButtonBox();
   createDirectoryBoxes();
   createOptionsBox();
   createWorkerThreads();
   createFileDisplayBox();

   statusBox = new StatusBoxWidget;

   filedrop = new FileDrop(filelist);
   connect(filedrop, SIGNAL(startProcessWork()), this, SLOT(startFileFinder()));
   connect(filedrop, SIGNAL(directoryDropped(QString)), mainproject->getSourceDirectory(), SLOT(setPath(QString)));

   QVBoxLayout* controlLayout = new QVBoxLayout;
   controlLayout->addWidget(sourceDirectoryBox);
   controlLayout->addWidget(verifyDirectoryBox);
   controlLayout->addWidget(optionsBox);
   controlLayout->addWidget(statusBox);
   controlLayout->addWidget(actionButtonBox);
   controlLayout->addWidget(filedrop);
   controlLayout->setAlignment(displayFileBox, Qt::AlignTop);
   controlLayout->setContentsMargins(0, 0, 0, 0);

   optionsBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
   actionButtonBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
   statusBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
   filedrop->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

   controlWidgets = new QWidget;
   controlWidgets->setLayout(controlLayout);

   QVBoxLayout* rightLayout = new QVBoxLayout;
   rightLayout->addWidget(displayFileBox);
   rightLayout->addWidget(filelist);

   QWidget *rightWidget = new QWidget;
   rightLayout->setContentsMargins(0, 0, 0, 0);
   rightWidget->setLayout(rightLayout);

   mainWidget = new QSplitter(this);
   mainWidget->addWidget(controlWidgets);
   mainWidget->addWidget(rightWidget);
   mainWidget->setMinimumSize(1000, 750);
   mainWidget->setChildrenCollapsible(false);
   mainWidget->setCollapsible(0, false);
   mainWidget->setCollapsible(1, false);

   mainWidget->setStretchFactor(0, 0);
   mainWidget->setStretchFactor(1, 100);

   setCentralWidget(mainWidget);

   actions = new MenuActions(this);
   actions->createMenus();

   QSettings settings;
   algorithmComboBox->setCurrentText(settings.value("selectedalgorithm", "CRC32").toString());
   calcHashSumWhenFoundCheckbox->setChecked(settings.value("calchashsumwhenfound", false).toBool());
   if (!calcHashSumWhenFoundCheckbox->isChecked()) {
      hashCalculationOwnThreadCheckbox->setEnabled(false);
   }
   hashCalculationOwnThreadCheckbox->setChecked(settings.value("hashcalculationownthread", true).toBool());
   mainWidget->restoreState(settings.value("splittersizes").toByteArray());

   connect(filelist, SIGNAL(displayFile(QString,QString)), this, SLOT(updateFileDisplay(QString,QString)));
   connect(filelist, SIGNAL(fileListSizeChanged(int, int, int, int)), statusBox, SLOT(updateStatusBox(int, int, int, int)));
   connect(filelist, SIGNAL(fileListSizeChanged(int, int, int, int)), actions, SLOT(filelistChanged(int, int, int, int)));
}