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