Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / src / leveldb / port / port_posix.cc
blobec39e921957f6507e3eb5f5ed5b6e15fea69e527
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
5 #include "port/port_posix.h"
7 #include <cstdlib>
8 #include <stdio.h>
9 #include <string.h>
11 #if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__)
12 #include <cpuid.h>
13 #endif
15 namespace leveldb {
16 namespace port {
18 static void PthreadCall(const char* label, int result) {
19 if (result != 0) {
20 fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
21 abort();
25 Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
27 Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
29 void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
31 void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }
33 CondVar::CondVar(Mutex* mu)
34 : mu_(mu) {
35 PthreadCall("init cv", pthread_cond_init(&cv_, NULL));
38 CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); }
40 void CondVar::Wait() {
41 PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
44 void CondVar::Signal() {
45 PthreadCall("signal", pthread_cond_signal(&cv_));
48 void CondVar::SignalAll() {
49 PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
52 void InitOnce(OnceType* once, void (*initializer)()) {
53 PthreadCall("once", pthread_once(once, initializer));
56 bool HasAcceleratedCRC32C() {
57 #if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__)
58 unsigned int eax, ebx, ecx, edx;
59 __get_cpuid(1, &eax, &ebx, &ecx, &edx);
60 return (ecx & (1 << 20)) != 0;
61 #else
62 return false;
63 #endif
66 } // namespace port
67 } // namespace leveldb