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