10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
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. }