OLD | NEW |
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 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 | 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. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | 4 |
5 #include <errno.h> | 5 #include <errno.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 int fflush_wrapper(FILE *file) { | 63 int fflush_wrapper(FILE *file) { |
64 return fflush(file); | 64 return fflush(file); |
65 } | 65 } |
66 | 66 |
67 #if !defined(OS_ANDROID) | 67 #if !defined(OS_ANDROID) |
68 int fdatasync(int fildes) { | 68 int fdatasync(int fildes) { |
69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
70 return _commit(fildes); | 70 return _commit(fildes); |
71 #elif defined(OS_MACOSX) | |
72 return HANDLE_EINTR(fcntl(fildes, F_FULLFSYNC, 0)); | |
73 #else | 71 #else |
74 return HANDLE_EINTR(fsync(fildes)); | 72 return HANDLE_EINTR(fsync(fildes)); |
75 #endif | 73 #endif |
76 } | 74 } |
77 #endif | 75 #endif |
78 | 76 |
79 #else | 77 #else |
80 | 78 |
81 class TryToLockFILE { | 79 class TryToLockFILE { |
82 // This class should be deleted if it doesn't turn up anything useful after | 80 // This class should be deleted if it doesn't turn up anything useful after |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 508 |
511 Status ChromiumWritableFile::Sync() { | 509 Status ChromiumWritableFile::Sync() { |
512 TRACE_EVENT0("leveldb", "ChromiumEnv::Sync"); | 510 TRACE_EVENT0("leveldb", "ChromiumEnv::Sync"); |
513 Status result; | 511 Status result; |
514 int error = 0; | 512 int error = 0; |
515 | 513 |
516 if (HANDLE_EINTR(fflush_wrapper(file_))) | 514 if (HANDLE_EINTR(fflush_wrapper(file_))) |
517 error = errno; | 515 error = errno; |
518 // Sync even if fflush gave an error; perhaps the data actually got out, | 516 // Sync even if fflush gave an error; perhaps the data actually got out, |
519 // even though something went wrong. | 517 // even though something went wrong. |
520 if (fdatasync(fileno(file_)) == -1 && !error) | 518 if (fdatasync(fileno(file_)) && !error) |
521 error = errno; | 519 error = errno; |
522 // Report the first error we found. | 520 // Report the first error we found. |
523 if (error) { | 521 if (error) { |
524 result = MakeIOError(filename_, strerror(error), kWritableFileSync, error); | 522 result = MakeIOError(filename_, strerror(error), kWritableFileSync, error); |
525 uma_logger_->RecordErrorAt(kWritableFileSync); | 523 uma_logger_->RecordErrorAt(kWritableFileSync); |
526 } | 524 } |
527 return result; | 525 return result; |
528 } | 526 } |
529 | 527 |
530 ChromiumEnv::ChromiumEnv() | 528 ChromiumEnv::ChromiumEnv() |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 Env* IDBEnv() { | 962 Env* IDBEnv() { |
965 return leveldb_env::idb_env.Pointer(); | 963 return leveldb_env::idb_env.Pointer(); |
966 } | 964 } |
967 | 965 |
968 Env* Env::Default() { | 966 Env* Env::Default() { |
969 return leveldb_env::default_env.Pointer(); | 967 return leveldb_env::default_env.Pointer(); |
970 } | 968 } |
971 | 969 |
972 } // namespace leveldb | 970 } // namespace leveldb |
973 | 971 |
OLD | NEW |