1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "cvmfs_config.h" |
6 |
|
|
#include "util_concurrency.h" |
7 |
|
|
|
8 |
|
|
#include <unistd.h> |
9 |
|
|
|
10 |
|
|
#include <cassert> |
11 |
|
|
|
12 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
13 |
|
|
namespace CVMFS_NAMESPACE_GUARD { |
14 |
|
|
#endif |
15 |
|
|
|
16 |
|
88 |
unsigned int GetNumberOfCpuCores() { |
17 |
|
88 |
const int numCPU = sysconf(_SC_NPROCESSORS_ONLN); |
18 |
|
|
|
19 |
✗✓ |
88 |
if (numCPU <= 0) { |
20 |
|
|
LogCvmfs(kLogSpooler, kLogWarning, "Unable to determine the available " |
21 |
|
|
"number of processors in the system... " |
22 |
|
|
"falling back to default '%d'", |
23 |
|
|
kFallbackNumberOfCpus); |
24 |
|
|
return kFallbackNumberOfCpus; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
88 |
return static_cast<unsigned int>(numCPU); |
28 |
|
|
} |
29 |
|
|
|
30 |
|
3029 |
Signal::Signal() : fired_(false) { |
31 |
|
3029 |
int retval = pthread_mutex_init(&lock_, NULL); |
32 |
✗✓ |
3029 |
assert(retval == 0); |
33 |
|
3029 |
retval = pthread_cond_init(&signal_, NULL); |
34 |
✗✓ |
3029 |
assert(retval == 0); |
35 |
|
3029 |
} |
36 |
|
|
|
37 |
|
|
|
38 |
|
3029 |
Signal::~Signal() { |
39 |
✗✓ |
3029 |
assert(IsSleeping()); |
40 |
|
3029 |
int res = pthread_cond_destroy(&signal_); |
41 |
✗✓ |
3029 |
assert(0 == res); |
42 |
|
3029 |
res = pthread_mutex_destroy(&lock_); |
43 |
✗✓ |
3029 |
assert(0 == res); |
44 |
|
3029 |
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
3028 |
void Signal::Wait() { |
48 |
|
3028 |
MutexLockGuard guard(lock_); |
49 |
✓✓ |
3028 |
while (!fired_) { |
50 |
|
3028 |
int retval = pthread_cond_wait(&signal_, &lock_); |
51 |
✗✓ |
3028 |
assert(retval == 0); |
52 |
|
|
} |
53 |
|
3028 |
fired_ = false; |
54 |
|
3028 |
} |
55 |
|
|
|
56 |
|
|
|
57 |
|
3028 |
void Signal::Wakeup() { |
58 |
|
3028 |
MutexLockGuard guard(lock_); |
59 |
|
3028 |
fired_ = true; |
60 |
|
3028 |
int retval = pthread_cond_broadcast(&signal_); |
61 |
✗✓ |
3028 |
assert(retval == 0); |
62 |
|
3028 |
} |
63 |
|
|
|
64 |
|
3029 |
bool Signal::IsSleeping() { |
65 |
|
3029 |
MutexLockGuard guard(lock_); |
66 |
|
3029 |
return fired_ == false; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
70 |
|
|
} // namespace CVMFS_NAMESPACE_GUARD |
71 |
|
|
#endif |