db/upnp/WorkQueue: simplify start()

This commit is contained in:
Max Kellermann 2014-01-16 08:43:57 +01:00
parent 876a095166
commit 028fd268b8
1 changed files with 5 additions and 4 deletions

View File

@ -90,7 +90,7 @@ public:
* @param arg initial parameter to thread function. * @param arg initial parameter to thread function.
* @return true if ok. * @return true if ok.
*/ */
bool start(int nworkers, void *(*workproc)(void *), void *arg) bool start(unsigned nworkers, void *(*workproc)(void *), void *arg)
{ {
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
@ -99,11 +99,12 @@ public:
assert(n_threads == 0); assert(n_threads == 0);
assert(threads == nullptr); assert(threads == nullptr);
threads = new pthread_t[nworkers]; n_threads = nworkers;
threads = new pthread_t[n_threads];
for (int i = 0; i < nworkers; i++) { for (unsigned i = 0; i < nworkers; i++) {
int err; int err;
if ((err = pthread_create(&threads[n_threads++], 0, workproc, arg))) { if ((err = pthread_create(&threads[i], 0, workproc, arg))) {
LOGERR(("WorkQueue:%s: pthread_create failed, err %d\n", LOGERR(("WorkQueue:%s: pthread_create failed, err %d\n",
name.c_str(), err)); name.c_str(), err));
return false; return false;