Changeset View
Changeset View
Standalone View
Standalone View
src/leveldb/port/port_posix.cc
// Copyright (c) 2011 The LevelDB Authors. All rights reserved. | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | ||||
// Use of this source code is governed by a BSD-style license that can be | // Use of this source code is governed by a BSD-style license that can be | ||||
// found in the LICENSE file. See the AUTHORS file for names of contributors. | // found in the LICENSE file. See the AUTHORS file for names of contributors. | ||||
#include "port/port_posix.h" | #include "port/port_posix.h" | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) | |||||
#include <cpuid.h> | |||||
#endif | |||||
namespace leveldb { | namespace leveldb { | ||||
namespace port { | namespace port { | ||||
static void PthreadCall(const char* label, int result) { | static void PthreadCall(const char* label, int result) { | ||||
if (result != 0) { | if (result != 0) { | ||||
fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); | ||||
abort(); | abort(); | ||||
} | } | ||||
Show All 25 Lines | |||||
void CondVar::SignalAll() { | void CondVar::SignalAll() { | ||||
PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); | ||||
} | } | ||||
void InitOnce(OnceType* once, void (*initializer)()) { | void InitOnce(OnceType* once, void (*initializer)()) { | ||||
PthreadCall("once", pthread_once(once, initializer)); | PthreadCall("once", pthread_once(once, initializer)); | ||||
} | } | ||||
bool HasAcceleratedCRC32C() { | |||||
#if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) | |||||
unsigned int eax, ebx, ecx, edx; | |||||
__get_cpuid(1, &eax, &ebx, &ecx, &edx); | |||||
return (ecx & (1 << 20)) != 0; | |||||
#else | |||||
return false; | |||||
#endif | |||||
} | |||||
} // namespace port | } // namespace port | ||||
} // namespace leveldb | } // namespace leveldb |