File: tsk_thread.cpp

package info (click to toggle)
sleuthkit 4.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 17,248 kB
  • sloc: ansic: 142,208; cpp: 50,346; java: 27,140; xml: 2,419; perl: 882; python: 508; makefile: 416; sh: 184
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;
}