db/upnp/WorkQueue: use std::list instead of std::unordered_map
Reduce bloat.
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <unordered_map>
|
#include <list>
|
||||||
|
|
||||||
//#include "debuglog.h"
|
//#include "debuglog.h"
|
||||||
#define LOGINFO(X)
|
#define LOGINFO(X)
|
||||||
@@ -49,16 +49,6 @@
|
|||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
class WorkQueue {
|
class WorkQueue {
|
||||||
/**
|
|
||||||
* Store per-worker-thread data. Just an initialized timespec,
|
|
||||||
* and used at the moment.
|
|
||||||
*/
|
|
||||||
class WQTData {
|
|
||||||
public:
|
|
||||||
WQTData() {wstart.tv_sec = 0; wstart.tv_nsec = 0;}
|
|
||||||
struct timespec wstart;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
const std::string name;
|
const std::string name;
|
||||||
const size_t high;
|
const size_t high;
|
||||||
@@ -69,9 +59,7 @@ class WorkQueue {
|
|||||||
unsigned n_workers_exited;
|
unsigned n_workers_exited;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
// Per-thread data. The data is not used currently, this could be
|
std::list<pthread_t> threads;
|
||||||
// a set<pthread_t>
|
|
||||||
std::unordered_map<pthread_t, WQTData> threads;
|
|
||||||
|
|
||||||
// Synchronization
|
// Synchronization
|
||||||
std::queue<T> queue;
|
std::queue<T> queue;
|
||||||
@@ -121,7 +109,7 @@ public:
|
|||||||
name.c_str(), err));
|
name.c_str(), err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
threads.insert(std::make_pair(thr, WQTData()));
|
threads.push_back(thr);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -226,9 +214,9 @@ public:
|
|||||||
// Workers return (void*)1 if ok
|
// Workers return (void*)1 if ok
|
||||||
while (!threads.empty()) {
|
while (!threads.empty()) {
|
||||||
void *status;
|
void *status;
|
||||||
auto it = threads.begin();
|
auto thread = threads.front();
|
||||||
pthread_join(it->first, &status);
|
pthread_join(thread, &status);
|
||||||
threads.erase(it);
|
threads.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to start state.
|
// Reset to start state.
|
||||||
|
Reference in New Issue
Block a user