作者: 谢瑞阳 10225101483 徐翔宇 10225101535
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

64 行
1.5 KiB

  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.
  4. #include "port/port_android.h"
  5. #include <cstdlib>
  6. extern "C" {
  7. size_t fread_unlocked(void *a, size_t b, size_t c, FILE *d) {
  8. return fread(a, b, c, d);
  9. }
  10. size_t fwrite_unlocked(const void *a, size_t b, size_t c, FILE *d) {
  11. return fwrite(a, b, c, d);
  12. }
  13. int fflush_unlocked(FILE *f) {
  14. return fflush(f);
  15. }
  16. int fdatasync(int fd) {
  17. return fsync(fd);
  18. }
  19. }
  20. namespace leveldb {
  21. namespace port {
  22. static void PthreadCall(const char* label, int result) {
  23. if (result != 0) {
  24. fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
  25. abort();
  26. }
  27. }
  28. Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
  29. Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
  30. void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
  31. void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }
  32. CondVar::CondVar(Mutex* mu)
  33. : mu_(mu) {
  34. PthreadCall("init cv", pthread_cond_init(&cv_, NULL));
  35. }
  36. CondVar::~CondVar() {
  37. PthreadCall("destroy cv", pthread_cond_destroy(&cv_));
  38. }
  39. void CondVar::Wait() {
  40. PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
  41. }
  42. void CondVar::Signal(){
  43. PthreadCall("signal", pthread_cond_signal(&cv_));
  44. }
  45. void CondVar::SignalAll() {
  46. PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
  47. }
  48. }
  49. }