File: tsk_thread.cpp

package info (click to toggle)
sleuthkit 4.1.3-3~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 36,800 kB
  • sloc: ansic: 147,143; sh: 40,085; cpp: 36,823; java: 6,886; makefile: 1,248; xml: 529; python: 409; perl: 59; sed: 16
file content (42 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "tsk_thread.h"

// mingw's pthread.h will try to read a config.h if HAVE_CONFIG_H
#undef HAVE_CONFIG_H

#include <pthread.h>
#include <assert.h>

TskThread::~TskThread()
{
    // empty
}

static void *x_thread_top(void *ta)
{
    TskThread *thread = (TskThread *)ta;
    (*thread)();
    return 0;
}

void TskThread::run(TskThread** threads, size_t nthreads)
{
    pthread_t* the_threads = new pthread_t[nthreads];
    pthread_attr_t pat;
    pthread_attr_init(&pat);
    for(size_t p = 0; p < nthreads; p++) {
        pthread_t tid;
        int pt = pthread_create(&tid, 0, x_thread_top, threads[p]);
        assert(0 == pt);
        the_threads[p] = tid;
    }
    /* It's quite annoying, you can't wait for more than one in pthreads. */
    for(size_t p = 0; p < nthreads; p++) {
        void *thread_return;
        int pt;
        pt = pthread_join(the_threads[p], &thread_return);
        assert(0 == pt);
        assert(0 == thread_return);
    }
    pthread_attr_destroy(&pat);
    delete[] the_threads;
}