小组成员:谢瑞阳、徐翔宇
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.

65 lines
1.6 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. // TODO(gabor): This is copied from port_posix.cc - not sure if I should do this?
  21. namespace leveldb {
  22. namespace port {
  23. static void PthreadCall(const char* label, int result) {
  24. if (result != 0) {
  25. fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
  26. abort();
  27. }
  28. }
  29. Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
  30. Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
  31. void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
  32. 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));
  36. }
  37. CondVar::~CondVar() {
  38. PthreadCall("destroy cv", pthread_cond_destroy(&cv_));
  39. }
  40. void CondVar::Wait() {
  41. PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
  42. }
  43. void CondVar::Signal(){
  44. PthreadCall("signal", pthread_cond_signal(&cv_));
  45. }
  46. void CondVar::SignalAll() {
  47. PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
  48. }
  49. }
  50. }