CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
concurrency.cc
Go to the documentation of this file.
1 
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 unsigned int GetNumberOfCpuCores() {
19  const int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
20 
21  if (numCPU <= 0) {
23  "Unable to determine the available "
24  "number of processors in the system... "
25  "falling back to default '%d'",
27  return kFallbackNumberOfCpus;
28  }
29 
30  return static_cast<unsigned int>(numCPU);
31 }
32 
33 Signal::Signal() : fired_(false) {
34  int retval = pthread_mutex_init(&lock_, NULL);
35  assert(retval == 0);
36  retval = pthread_cond_init(&signal_, NULL);
37  assert(retval == 0);
38 }
39 
40 
42  assert(IsSleeping());
43  int res = pthread_cond_destroy(&signal_);
44  assert(0 == res);
45  res = pthread_mutex_destroy(&lock_);
46  assert(0 == res);
47 }
48 
49 
50 void Signal::Wait() {
51  MutexLockGuard guard(lock_);
52  while (!fired_) {
53  int retval = pthread_cond_wait(&signal_, &lock_);
54  assert(retval == 0);
55  }
56  fired_ = false;
57 }
58 
59 
61  MutexLockGuard guard(lock_);
62  fired_ = true;
63  int retval = pthread_cond_broadcast(&signal_);
64  assert(retval == 0);
65 }
66 
68  MutexLockGuard guard(lock_);
69  return fired_ == false;
70 }
71 
72 #ifdef CVMFS_NAMESPACE_GUARD
73 } // namespace CVMFS_NAMESPACE_GUARD
74 #endif
const int kLogWarning
pthread_cond_t signal_
Definition: concurrency.h:366
void Wakeup()
Definition: concurrency.cc:60
unsigned int GetNumberOfCpuCores()
Definition: concurrency.cc:18
assert((mem||(size==0))&&"Out Of Memory")
bool IsSleeping()
Definition: concurrency.cc:67
bool fired_
Definition: concurrency.h:364
static const unsigned int kFallbackNumberOfCpus
Definition: concurrency.h:349
void Wait()
Definition: concurrency.cc:50
Definition: mutex.h:42
pthread_mutex_t lock_
Definition: concurrency.h:365
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545