Changeset 1144


Ignore:
Timestamp:
Feb 25, 2012, 2:38:42 PM (8 years ago)
Author:
sam
Message:

threads: change Queue to a template so that we can manage the element type.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/thread/thread.h

    r1098 r1144  
    3232};
    3333
    34 class Queue : public QueueBase
     34template<typename T, int N = 128> class Queue : public QueueBase<T, N>
    3535{
    3636public:
    37     Queue() : QueueBase() {}
     37    Queue() : QueueBase<T, N>() {}
    3838};
    3939
  • trunk/src/thread/threadbase.h

    r1109 r1144  
    7575};
    7676
    77 class QueueBase
     77template<typename T, int N> class QueueBase
    7878{
    7979public:
     
    106106    }
    107107
    108     void Push(int value)
     108    void Push(T value)
    109109    {
    110110#if defined HAVE_PTHREAD_H
     
    135135    }
    136136
    137     int Pop()
     137    T Pop()
    138138    {
    139139#if defined HAVE_PTHREAD_H
     
    152152
    153153        /* Pop value */
    154         int ret = m_values[m_start];
     154        T ret = m_values[m_start];
    155155        m_start = (m_start + 1) % CAPACITY;
    156156        m_count--;
     
    170170
    171171private:
    172     static size_t const CAPACITY = 100;
    173     int m_values[CAPACITY];
     172    static size_t const CAPACITY = N;
     173    T m_values[CAPACITY];
    174174    size_t m_start, m_count;
    175175#if defined HAVE_PTHREAD_H
  • trunk/src/ticker.cpp

    r1125 r1144  
    7676    static void *DiskThreadMain(void *p);
    7777    Thread *gamethread, *drawthread, *diskthread;
    78     Queue gametick, drawtick;
     78    Queue<int> gametick, drawtick;
    7979
    8080    /* Shutdown management */
  • trunk/test/tutorial/tut03.cpp

    r1136 r1144  
    770770    /* Worker threads */
    771771    Thread *m_threads[MAX_THREADS];
    772     Queue m_spawnqueue, m_jobqueue, m_donequeue;
     772    Queue<int> m_spawnqueue, m_jobqueue, m_donequeue;
    773773
    774774    /* Debug information */
Note: See TracChangeset for help on using the changeset viewer.