GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/util/concurrency.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 34 36 94.4%
Branches: 11 20 55.0%

Line Branch Exec Source
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 #include "util/logging.h"
13
14 #ifdef CVMFS_NAMESPACE_GUARD
15 namespace CVMFS_NAMESPACE_GUARD {
16 #endif
17
18 44 unsigned int GetNumberOfCpuCores() {
19 44 const int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
20
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if (numCPU <= 0) {
22 LogCvmfs(kLogSpooler, kLogWarning, "Unable to determine the available "
23 "number of processors in the system... "
24 "falling back to default '%d'",
25 kFallbackNumberOfCpus);
26 return kFallbackNumberOfCpus;
27 }
28
29 44 return static_cast<unsigned int>(numCPU);
30 }
31
32 3031 Signal::Signal() : fired_(false) {
33 3031 int retval = pthread_mutex_init(&lock_, NULL);
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3031 times.
3031 assert(retval == 0);
35 3031 retval = pthread_cond_init(&signal_, NULL);
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3031 times.
3031 assert(retval == 0);
37 3031 }
38
39
40 3031 Signal::~Signal() {
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3031 times.
3031 assert(IsSleeping());
42 3031 int res = pthread_cond_destroy(&signal_);
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3031 times.
3031 assert(0 == res);
44 3031 res = pthread_mutex_destroy(&lock_);
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3031 times.
3031 assert(0 == res);
46 3031 }
47
48
49 3045 void Signal::Wait() {
50 3045 MutexLockGuard guard(lock_);
51
2/2
✓ Branch 0 taken 3027 times.
✓ Branch 1 taken 3045 times.
6072 while (!fired_) {
52
1/2
✓ Branch 1 taken 3027 times.
✗ Branch 2 not taken.
3027 int retval = pthread_cond_wait(&signal_, &lock_);
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3027 times.
3027 assert(retval == 0);
54 }
55 3045 fired_ = false;
56 3045 }
57
58
59 3045 void Signal::Wakeup() {
60 3045 MutexLockGuard guard(lock_);
61 3045 fired_ = true;
62 3045 int retval = pthread_cond_broadcast(&signal_);
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3045 times.
3045 assert(retval == 0);
64 3045 }
65
66 3040 bool Signal::IsSleeping() {
67 3040 MutexLockGuard guard(lock_);
68 6080 return fired_ == false;
69 3040 }
70
71 #ifdef CVMFS_NAMESPACE_GUARD
72 } // namespace CVMFS_NAMESPACE_GUARD
73 #endif
74