-
Notifications
You must be signed in to change notification settings - Fork 294
/
thread_id_map.hh
67 lines (48 loc) · 1.5 KB
/
thread_id_map.hh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// This file is part of khmer, http://github.com/ged-lab/khmer/, and is
// Copyright (C) Michigan State University, 2009-2013. It is licensed under
// the three-clause BSD license; see doc/LICENSE.txt.
// Contact: khmer-project@idyll.org
//
#ifndef THREAD_ID_MAP_HH
# define THREAD_ID_MAP_HH
#include <map>
// TODO? Just use 'pthread_t' everywhere.
// Linux uses standard PIDs for thread IDs.
#if defined (__linux__)
# include <sys/types.h>
// MacOS X uses Mach kernel ports for thread IDs.
#elif defined (__APPLE__) && defined (__MACH__)
# include <mach/mach.h>
# include <pthread.h>
// Else, hope that some POSIX threads implementation is available.
// If so, then try to use 'pthread_t' instances as thread IDs.
#else
# include <pthread.h>
#endif
#include "khmer.hh"
namespace khmer
{
struct InvalidNumberOfThreadsRequested : public khmer_exception {
};
struct TooManyThreads : public khmer_exception {
};
struct ThreadIDMap {
ThreadIDMap( uint32_t number_of_threads );
~ThreadIDMap( );
uint32_t const get_thread_id( );
private:
uint32_t _number_of_threads;
uint32_t _thread_counter;
#if defined (__linux__)
std:: map< pid_t, uint32_t > _thread_id_map;
#elif defined (__APPLE__) && defined (__MACH__)
std:: map< mach_port_t, uint32_t > _thread_id_map;
#else
std:: map< pthread_t, uint32_t > _thread_id_map;
#endif
uint32_t _tid_map_spin_lock;
}; // struct ThreadIDMap
} // namespace khmer
#endif // THREAD_ID_MAP_HH
// vim: set ft=cpp sts=4 sw=4 tw=79: