Changeset 3600


Ignore:
Timestamp:
Mar 30, 2013 1:06:17 AM (9 years ago)
Author:
ldelgass
Message:

Don't use a separate reader thread in vtkvis, the main thread can function as
the reader. This way we have 2 threads instead of 3 and the main loop is in
main() and can be shared with the non-threaded code path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/RpVtkRenderServer.cpp

    r3535 r3600  
    405405initService()
    406406{
     407    TRACE("Enter");
     408
    407409    const char *user = getenv("USER");
    408410    char *logName = NULL;
     
    433435        free(logName);
    434436    }
     437
     438    TRACE("Leave");
    435439}
    436440
     
    438442exitService()
    439443{
     444    TRACE("Enter");
     445
    440446    serverStats(0);
    441447
     
    448454
    449455#ifdef USE_THREADS
    450 static void *
    451 readerThread(void *clientData)
    452 {
    453     ResponseQueue *queue = (ResponseQueue *)clientData;
    454     Tcl_Interp *interp;
    455 
    456     TRACE("Starting reader thread");
    457     interp = (Tcl_Interp *)queue->clientData();
    458     vtkSmartPointer<vtkUnsignedCharArray> imgData =
    459         vtkSmartPointer<vtkUnsignedCharArray>::New();
    460     for (;;) {
    461         if (processCommands(interp, (ClientData)clientData, g_inBufPtr, g_fdOut) < 0)
    462             break;
    463 
    464         if (g_renderer->render()) {
    465             TRACE("Rendering new frame");
    466             g_renderer->getRenderedFrame(imgData);
    467             queueFrame(queue, imgData);
    468             g_stats.nFrames++;
    469             g_stats.nFrameBytes += imgData->GetDataSize() * imgData->GetDataTypeSize();
    470         } else {
    471             TRACE("No render required");
    472             sendAck((ClientData)clientData, g_fdOut);
    473         }
    474 
    475         if (g_inBufPtr->status() == ReadBuffer::ENDFILE)
    476             break;
    477     }   
    478     return NULL;
    479 }
    480456
    481457static void *
     
    530506    Tcl_Interp *interp = Tcl_CreateInterp();
    531507
     508    ClientData clientData = NULL;
    532509#ifdef USE_THREADS
    533510    ResponseQueue *queue = new ResponseQueue((void *)interp);
    534     initTcl(interp, (ClientData)queue);
    535 
    536     pthread_t readerThreadId, writerThreadId;
    537     if (pthread_create(&readerThreadId, NULL, &readerThread, queue) < 0) {
    538         ERROR("Can't create reader thread: %s", strerror(errno));
    539     }
     511    clientData = (ClientData)queue;
     512    initTcl(interp, clientData);
     513
     514    pthread_t writerThreadId;
    540515    if (pthread_create(&writerThreadId, NULL, &writerThread, queue) < 0) {
    541516        ERROR("Can't create writer thread: %s", strerror(errno));
    542517    }
    543     if (pthread_join(readerThreadId, NULL) < 0) {
    544         ERROR("Can't join reader thread: %s", strerror(errno));
    545     } else {
    546         TRACE("Reader thread exited");
    547     }
     518#else
     519    initTcl(interp, clientData);
     520#endif
     521
     522    vtkSmartPointer<vtkUnsignedCharArray> imgData =
     523        vtkSmartPointer<vtkUnsignedCharArray>::New();
     524
     525    // Start main server loop
     526    for (;;) {
     527        if (processCommands(interp, clientData, g_inBufPtr, g_fdOut) < 0)
     528            break;
     529
     530        if (g_renderer->render()) {
     531            TRACE("Rendering new frame");
     532            g_renderer->getRenderedFrame(imgData);
     533#ifdef USE_THREADS
     534            queueFrame(queue, imgData);
     535#else
     536            writeFrame(g_fdOut, imgData);
     537#endif
     538            g_stats.nFrames++;
     539            g_stats.nFrameBytes += imgData->GetDataSize() * imgData->GetDataTypeSize();
     540        } else {
     541            TRACE("No render required");
     542            sendAck(clientData, g_fdOut);
     543        }
     544
     545        if (g_inBufPtr->status() == ReadBuffer::ENDFILE)
     546            break;
     547    }
     548#ifdef USE_THREADS
    548549    // Writer thread is probably blocked on sem_wait, so cancel instead
    549550    // of joining
     
    557558    delete queue;
    558559    queue = NULL;
    559 #else
    560     initTcl(interp, (ClientData)NULL);
    561 
    562     vtkSmartPointer<vtkUnsignedCharArray> imgData =
    563         vtkSmartPointer<vtkUnsignedCharArray>::New();
    564     for (;;) {
    565         if (processCommands(interp, (ClientData)NULL, g_inBufPtr, g_fdOut) < 0)
    566             break;
    567 
    568         if (g_renderer->render()) {
    569             TRACE("Rendering new frame");
    570             g_renderer->getRenderedFrame(imgData);
    571             writeFrame(g_fdOut, imgData);
    572             g_stats.nFrames++;
    573             g_stats.nFrameBytes += imgData->GetDataSize() * imgData->GetDataTypeSize();
    574         } else {
    575             TRACE("No render required");
    576         }
    577 
    578         if (g_inBufPtr->status() == ReadBuffer::ENDFILE)
    579             break;
    580     }
    581560#endif
    582561
Note: See TracChangeset for help on using the changeset viewer.