Ignore:
Timestamp:
Sep 8, 2011, 8:03:53 PM (13 years ago)
Author:
ldelgass
Message:

A few mostly style changes to make more consistent with style in vtkvis. Also
fix queueTGA -- no need to copy one scanline at a time and bytes per pixel can
be 3 or 4).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/vtkvis_threaded/ResponseQueue.cpp

    r2488 r2495  
    1 
    2 #ifdef USE_THREADS
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2/*
     3 * Copyright (C) 2011, Purdue Research Foundation
     4 *
     5 * Author: George A. Howlett <gah@purdue.edu>
     6 */
    37
    48#include <pthread.h>
    59#include <semaphore.h>
    6 #include <errno.h>
    7 #include <list>
    8 #include <stdlib.h>
    9 #include <errno.h>
     10#include <cerrno>
    1011#include <cstring>
    1112#include <cstdlib>
     13#include <list>
     14
    1215#include "Trace.h"
    1316#include "ResponseQueue.h"
    1417
    15 ResponseQueue::ResponseQueue(void *clientData)
     18using namespace Rappture::VtkVis;
     19
     20ResponseQueue::ResponseQueue(void *clientData)  :
     21    _clientData(clientData)
    1622{
    1723    pthread_mutex_init(&_idle, NULL);
    1824    if (sem_init(&_ready, 0, 0) < 0) {
    19         ERROR("can't initialize semaphore: %s", strerror(errno));
     25        ERROR("can't initialize semaphore: %s", strerror(errno));
    2026    }
    21     _clientData = clientData;
    2227}
    2328
    24 ResponseQueue::~ResponseQueue(void)
     29ResponseQueue::~ResponseQueue()
    2530{
    2631    pthread_mutex_destroy(&_idle);
    2732    if (sem_destroy(&_ready) < 0) {
    28         ERROR("can't destroy semaphore: %s", strerror(errno));
     33        ERROR("can't destroy semaphore: %s", strerror(errno));
    2934    }
    3035}
    3136
    3237void
    33 ResponseQueue::Enqueue(Response *responsePtr)
     38ResponseQueue::enqueue(Response *response)
    3439{
    3540    if (pthread_mutex_lock(&_idle) != 0) {
    36         ERROR("can't lock mutex: %s", strerror(errno));
     41        ERROR("can't lock mutex: %s", strerror(errno));
    3742    }   
    3843    /* Examine the list and remove any queued responses of the same type. */
    3944    INFO("before # of elements is %d\n", _list.size());
    40     std::list<Response *>::iterator iter;
    41     for (iter = _list.begin(); iter != _list.end(); iter++) {
    42         /* Remove any responses of the same type. There should be no more than
    43         * one. */
    44         if ((*iter)->Type() == responsePtr->Type()) {
    45             _list.erase(iter);
    46         }
     45    for (std::list<Response *>::iterator itr = _list.begin();
     46         itr != _list.end(); ++itr) {
     47        /* Remove any responses of the same type. There should be no more than
     48        * one. */
     49        if ((*itr)->type() == response->type()) {
     50            _list.erase(itr);
     51        }
    4752    }
    4853    /* Add the new response to the end of the list. */
    49     _list.push_back(responsePtr);
     54    _list.push_back(response);
    5055    if (sem_post(&_ready) < 0) {
    51         ERROR("can't post semaphore: %s", strerror(errno));
     56        ERROR("can't post semaphore: %s", strerror(errno));
    5257    }
    5358    if (pthread_mutex_unlock(&_idle) != 0) {
    54         ERROR("can't unlock mutex: %s", strerror(errno));
     59        ERROR("can't unlock mutex: %s", strerror(errno));
    5560    }   
    5661}
    5762
    5863Response *
    59 ResponseQueue::Dequeue(void)
     64ResponseQueue::dequeue()
    6065{
    61     Response *responsePtr;
     66    Response *response;
    6267
    6368    if (sem_wait(&_ready) < 0) {
    64         ERROR("can't wait on semaphore: %s", strerror(errno));
     69        ERROR("can't wait on semaphore: %s", strerror(errno));
    6570    }
    6671    if (pthread_mutex_lock(&_idle) != 0) {
    67         ERROR("can't lock mutex: %s", strerror(errno));
     72        ERROR("can't lock mutex: %s", strerror(errno));
    6873    }   
    69     responsePtr = _list.front();
     74    response = _list.front();
    7075    _list.pop_front();
    7176    if (pthread_mutex_unlock(&_idle) != 0) {
    72         ERROR("can't unlock mutex: %s", strerror(errno));
     77        ERROR("can't unlock mutex: %s", strerror(errno));
    7378    }   
    74     return responsePtr;
     79    return response;
    7580}
    76 
    77 #endif /*USE_THREADS*/
Note: See TracChangeset for help on using the changeset viewer.