Exemplo n.º 1
0
void DoubleBuffer::asyncLoadBatch() {
  int64_t actualSize = 0;
  if (useGpu_) {
    hl_set_device(FLAGS_gpu_id);
  }
  setPending(false);

  while (true) {
    taskReadySem_.wait();
    if (stopping_) break;

    while (batchSize_ == 0 && !stopping_) {
      usleep(5);
    }
    if (stopping_) break;

    do {
      DataBatch newBatch;
      {
        REGISTER_TIMER("getNextBatchInternal");
        actualSize = dataPool_->getNextBatchInternal(batchSize_, &newBatch);
      }
      insertOneBatch(&newBatch);
    } while (actualSize > 0 && !stopping_);
  }
}
Exemplo n.º 2
0
void PlaylistContainer::load()
{
    done_loading = false;
    active_playlist = new Playlist();
    active_playlist->setParent(this);

    backup_playlist = new Playlist();
    backup_playlist->setParent(this);

    stream_playlist = new Playlist();
    stream_playlist->setParent(this);

    all_other_playlists = new QList<Playlist*>;

    cd_playlist.clear();

    active_playlist->loadPlaylist("default_playlist_storage", my_host);

    backup_playlist->loadPlaylist("backup_playlist_storage", my_host);

    stream_playlist->loadPlaylist("stream_playlist", my_host);

    MSqlQuery query(MSqlQuery::InitCon());
    query.prepare("SELECT playlist_id FROM music_playlists "
                  "WHERE playlist_name != :DEFAULT"
                  " AND playlist_name != :BACKUP "
                  " AND (hostname = '' OR hostname = :HOST) "
                  "ORDER BY playlist_name;");
    query.bindValue(":DEFAULT", "default_playlist_storage");
    query.bindValue(":BACKUP", "backup_playlist_storage");
    query.bindValue(":HOST", my_host);

    if (!query.exec())
    {
        MythDB::DBError("Querying playlists", query);
    }
    else
    {
        while (query.next())
        {
            Playlist *temp_playlist = new Playlist();
            //  No, we don't destruct this ...
            temp_playlist->setParent(this);
            temp_playlist->loadPlaylistByID(query.value(0).toInt(), my_host);
            all_other_playlists->push_back(temp_playlist);
            //  ... cause it's sitting on this PtrList
        }
    }
    postLoad();

    pending_writeback_index = 0;

    int x = gCoreContext->GetNumSetting("LastMusicPlaylistPush");
    setPending(x);
    done_loading = true;
}
Exemplo n.º 3
0
void DataLayer::setDataModel(Day* currentDay)
{
    if (_currentDay != NULL)
    {
         _currentDay->deleteLater();
    }
    _currentDay = currentDay;
    _dataModel  = _currentDay->getAppointments();
    emit dataModelChanged();

    saveDataToFile();
    setPending(false);
}
Exemplo n.º 4
0
void ThreadedSocketInitiator::doConnect( const SessionID& s, const Dictionary& d )
{
  try
  {
    Session* session = Session::lookupSession( s );
    if( !session->isSessionTime(UtcTimeStamp()) ) return;

    Log* log = session->getLog();

    std::string address;
    short port = 0;
    std::string sourceAddress;
    short sourcePort = 0;
    getHost( s, d, address, port, sourceAddress, sourcePort );

    socket_handle socket = socket_createConnector();
    if( m_noDelay )
      socket_setsockopt( socket, TCP_NODELAY );
    if( m_sendBufSize )
      socket_setsockopt( socket, SO_SNDBUF, m_sendBufSize );
    if( m_rcvBufSize )
      socket_setsockopt( socket, SO_RCVBUF, m_rcvBufSize );

    setPending( s );
    log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) + " (Source " + sourceAddress + ":" + IntConvertor::convert((unsigned short)sourcePort) + ")");

    ThreadedSocketConnection* pConnection =
      new ThreadedSocketConnection( s, socket, address, port, getLog(), sourceAddress, sourcePort );

    ThreadPair* pair = new ThreadPair( this, pConnection );

    {
      Locker l( m_mutex );
      thread_id thread;
      if ( thread_spawn( &socketThread, pair, thread ) )
      {
        addThread( socket, thread );
      }
      else
      {
        delete pair;
        pConnection->disconnect();
        delete pConnection;
        setDisconnected( s );
      }
    }
  }
  catch ( std::exception& ) {}
}
Exemplo n.º 5
0
void DataLayer::loadDataFromClient(int day)
{
    setPending(true);
    if (day > 0)
    {
        _webClient.setTerminUrl(_currentDay->getNextDay());
    }
    else if(day < 0)
    {
        _webClient.setTerminUrl(_currentDay->getPrevDay());
    }
    else
    {
        _webClient.resetTerminUrl();
    }
    _webClient.getData();
}
Exemplo n.º 6
0
void DoubleBuffer::removeOneBatch(DataBatch* dataBatch) {
  // get data
  BufferBatch* batch = dataQueue_->dequeue();
  batch->syncEvent();  // when use GPU, need synchronized with the cuEvent
  *dataBatch = *(batch->getDataBatch());

  // push anothor buffer
  if (*usingBatch_ == nullptr) {
    *usingBatch_ = std::make_shared<BufferBatch>();
  }

  // Mark the using-batch
  batch->swap((*usingBatch_).get());
  bufferQueue_->enqueue(batch);

  if (0 == dataBatch->getSize()) {
    setPending(true);
  }
}
Exemplo n.º 7
0
ByteArray UDPInternalConnection::receiveImpl(unsigned long size)
{
  if (readyForRead() == 0) {

    if (!isPending())
      setPending();
    else
      throw netman::SockConnectionError("Already pending");

    std::unique_lock<std::mutex> lock(syncMutex);
    waitVar.wait(lock, [&] {return !isPending();});

    if (isTimedOut()) {
      setIdle();
      throw netman::SockRecieveFailed("Operation timeout");
    } else
      setIdle();
  }

  return readBuffer();
}
void ThreadedSSLSocketInitiator::doConnect(const SessionID &s,
                                           const Dictionary &d)
{
  try
  {
    Session *session = Session::lookupSession(s);
    if (!session->isSessionTime(UtcTimeStamp()))
      return;

    Log *log = session->getLog();

    std::string address;
    short port = 0;
    getHost(s, d, address, port);

    int socket = socket_createConnector();
    if (m_noDelay)
      socket_setsockopt(socket, TCP_NODELAY);
    if (m_sendBufSize)
      socket_setsockopt(socket, SO_SNDBUF, m_sendBufSize);
    if (m_rcvBufSize)
      socket_setsockopt(socket, SO_RCVBUF, m_rcvBufSize);

    setPending(s);
    log->onEvent("Connecting to " + address + " on port " +
                 IntConvertor::convert((unsigned short)port));

    SSL *ssl = SSL_new(m_ctx);
    if (ssl == 0)
    {
      log->onEvent("Failed to create ssl object");
      return;
    }
    SSL_clear(ssl);
    BIO *sbio = BIO_new_socket(socket, BIO_CLOSE);
    SSL_set_bio(ssl, sbio, sbio);

    ThreadedSSLSocketConnection *pConnection = new ThreadedSSLSocketConnection(
        s, socket, ssl, address, port, getLog());

    ThreadPair *pair = new ThreadPair(this, pConnection);

    {
      Locker l(m_mutex);
      thread_id thread;
      if (thread_spawn(&socketThread, pair, thread))
      {
        addThread(SocketKey(socket, ssl), thread);
      }
      else
      {
        delete pair;
        pConnection->disconnect();
        delete pConnection;
        SSL_free(ssl);
        setDisconnected(s);
      }
    }
  }
  catch (std::exception &)
  {
  }
}
Exemplo n.º 9
0
void DataLayer::abortLogin()
{
    setPending(false);
    _authRequired = false;
    emit authRequiredChanged();
}