Procházet zdrojové kódy

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

legacy
Sam Hocevar sam před 13 roky
rodič
revize
db728e48fe
4 změnil soubory, kde provedl 10 přidání a 10 odebrání
  1. +2
    -2
      src/thread/thread.h
  2. +6
    -6
      src/thread/threadbase.h
  3. +1
    -1
      src/ticker.cpp
  4. +1
    -1
      test/tutorial/tut03.cpp

+ 2
- 2
src/thread/thread.h Zobrazit soubor

@@ -31,10 +31,10 @@ public:
Mutex() : MutexBase() {}
};

class Queue : public QueueBase
template<typename T, int N = 128> class Queue : public QueueBase<T, N>
{
public:
Queue() : QueueBase() {}
Queue() : QueueBase<T, N>() {}
};

class Thread : ThreadBase


+ 6
- 6
src/thread/threadbase.h Zobrazit soubor

@@ -74,7 +74,7 @@ private:
#endif
};

class QueueBase
template<typename T, int N> class QueueBase
{
public:
QueueBase()
@@ -105,7 +105,7 @@ public:
#endif
}

void Push(int value)
void Push(T value)
{
#if defined HAVE_PTHREAD_H
pthread_mutex_lock(&m_mutex);
@@ -134,7 +134,7 @@ public:
#endif
}

int Pop()
T Pop()
{
#if defined HAVE_PTHREAD_H
pthread_mutex_lock(&m_mutex);
@@ -151,7 +151,7 @@ public:
#endif

/* Pop value */
int ret = m_values[m_start];
T ret = m_values[m_start];
m_start = (m_start + 1) % CAPACITY;
m_count--;

@@ -169,8 +169,8 @@ public:
}

private:
static size_t const CAPACITY = 100;
int m_values[CAPACITY];
static size_t const CAPACITY = N;
T m_values[CAPACITY];
size_t m_start, m_count;
#if defined HAVE_PTHREAD_H
size_t m_poppers, m_pushers;


+ 1
- 1
src/ticker.cpp Zobrazit soubor

@@ -75,7 +75,7 @@ private:
static void *DrawThreadMain(void *p); /* unused */
static void *DiskThreadMain(void *p);
Thread *gamethread, *drawthread, *diskthread;
Queue gametick, drawtick;
Queue<int> gametick, drawtick;

/* Shutdown management */
int quit, quitframe, quitdelay, panic;


+ 1
- 1
test/tutorial/tut03.cpp Zobrazit soubor

@@ -769,7 +769,7 @@ private:

/* Worker threads */
Thread *m_threads[MAX_THREADS];
Queue m_spawnqueue, m_jobqueue, m_donequeue;
Queue<int> m_spawnqueue, m_jobqueue, m_donequeue;

/* Debug information */
#if !defined __native_client__


||||||
x
 
000:0
Načítá se…
Zrušit
Uložit