Ejemplo n.º 1
0
// Asynchronously load the database in this thread.
static void databaseLoaderEntry(void* threadData)
{
    AutoProfilerRegister registerThread("HRTFDatabaseLdr");
    PR_SetCurrentThreadName("HRTFDatabaseLdr");

    HRTFDatabaseLoader* loader = reinterpret_cast<HRTFDatabaseLoader*>(threadData);
    MOZ_ASSERT(loader);
    loader->load();
}
Ejemplo n.º 2
0
void
StorageDBThread::ThreadFunc(void* aArg)
{
  AutoProfilerRegister registerThread("localStorage DB");
  PR_SetCurrentThreadName("localStorage DB");
  mozilla::IOInterposer::RegisterCurrentThread();

  StorageDBThread* thread = static_cast<StorageDBThread*>(aArg);
  thread->ThreadFunc();
  mozilla::IOInterposer::UnregisterCurrentThread();
}
Ejemplo n.º 3
0
void ThreadSGI::start()
{
   if ( mRunning )
   {
      throw vpr::Exception("Thread already started", VPR_LOCATION);
   }
   else if ( mUserThreadFunctor.empty() )
   {
      throw vpr::IllegalArgumentException("No functor set", VPR_LOCATION);
   }
   else
   {
      // Spawn the thread.
      mStartFunctor = boost::bind(&ThreadSGI::startThread, this);

      try
      {
         spawn();
         mRunning = true;

         ThreadManager::instance()->lock();
         {
            registerThread(true);
         }
         ThreadManager::instance()->unlock();
      }
      catch (vpr::Exception& ex)
      {
         ThreadManager::instance()->lock();
         {
            registerThread(false);     // Failed to create
         }
         ThreadManager::instance()->unlock();

         // Rethrow the exception.
         throw;
      }
   }
}
Ejemplo n.º 4
0
void ClientManager::handle(const std::shared_ptr<ClientsMap <int, ClientManager *>> &blockingMap) {
    registerThread(blockingMap);
    logger->log("Created");

    std::thread socketListenerThread(&SocketListener::handle, socketListener);
    std::thread senderThread(&Sender::handle, sender);

    socketListenerThread.join();
    sender->setConnectionClosed();
    senderThread.join();

    deleteClient();
    unregisterThread(blockingMap);
}
Ejemplo n.º 5
0
void ThreadPosix::start()
{
   if ( mRunning )
   {
      throw vpr::Exception("Thread already started", VPR_LOCATION);
   }
   else if ( mUserThreadFunctor.empty() )
   {
      throw vpr::IllegalArgumentException("No functor set", VPR_LOCATION);
   }
   else
   {
      // Spawn the thread.  If the thread is spawned successfully, the method
      // startThread() will register the actual thread info.
      mThreadStartCompleted = false;  // Make sure this is set correctly
      mStartFunctor = boost::bind(&ThreadPosix::startThread, this);

      try
      {
         spawn();

         // The thread spawned successfully.
         // startThread() will register the thread, so we wait for
         // registration to complete here.
         mThreadStartCondVar.acquire();
         {
            while ( ! mThreadStartCompleted )
            {
               mThreadStartCondVar.wait();
            }
         }
         mThreadStartCondVar.release();

         mRunning = true;
      }
      // Thread spawning failed.  Yikes!
      catch (vpr::Exception& ex)
      {
         ThreadManager::instance()->lock();
         {
            registerThread(false);
         }
         ThreadManager::instance()->unlock();

         // Rethrow the exception.
         throw;
      }
   }
}
Ejemplo n.º 6
0
// Called by the spawn routine to start the user thread function.
void ThreadPosix::startThread()
{
   // WE are a new thread... yeah!!!!
   // TELL EVERYONE THAT WE LIVE!!!!
   ThreadManager::instance()->lock();      // Lock manager
   {
      threadIdKey().setspecific((void*)this);  // Store the pointer to me
      registerThread(true);                    // Finish thread initialization
   }
   ThreadManager::instance()->unlock();

   // Signal that thread registration is complete.
   mThreadStartCondVar.acquire();
   {
      mThreadStartCompleted = true;
      mThreadStartCondVar.signal();
   }
   mThreadStartCondVar.release();

   try
   {
      emitThreadStart(this);

      // --- CALL USER FUNCTOR --- //
      mUserThreadFunctor();

      emitThreadExit(this);
   }
   catch (std::exception& ex)
   {
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << clrOutNORM(clrYELLOW, "WARNING:")
         << " Caught an unhandled exception of type " << typeid(ex).name()
         << " in thread:" << std::endl
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << "Thread exiting due to uncaught exception\n" << vprDEBUG_FLUSH;

      mCaughtException = true;
      mException.setException(ex);
   }
}