Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: runtime/bin/file_linux.cc

Issue 2050413002: Adds blocking file locks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update docs and CHANGELOG Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { 130 bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
131 ASSERT(handle_->fd() >= 0); 131 ASSERT(handle_->fd() >= 0);
132 ASSERT((end == -1) || (end > start)); 132 ASSERT((end == -1) || (end > start));
133 struct flock fl; 133 struct flock fl;
134 switch (lock) { 134 switch (lock) {
135 case File::kLockUnlock: 135 case File::kLockUnlock:
136 fl.l_type = F_UNLCK; 136 fl.l_type = F_UNLCK;
137 break; 137 break;
138 case File::kLockShared: 138 case File::kLockShared:
139 case File::kLockBlockingShared:
139 fl.l_type = F_RDLCK; 140 fl.l_type = F_RDLCK;
140 break; 141 break;
141 case File::kLockExclusive: 142 case File::kLockExclusive:
143 case File::kLockBlockingExclusive:
142 fl.l_type = F_WRLCK; 144 fl.l_type = F_WRLCK;
143 break; 145 break;
144 default: 146 default:
145 return false; 147 return false;
146 } 148 }
147 fl.l_whence = SEEK_SET; 149 fl.l_whence = SEEK_SET;
148 fl.l_start = start; 150 fl.l_start = start;
149 fl.l_len = end == -1 ? 0 : end - start; 151 fl.l_len = end == -1 ? 0 : end - start;
150 // fcntl does not block, but fails if the lock cannot be acquired. 152 int cmd = F_SETLK;
151 int rc = fcntl(handle_->fd(), F_SETLK, &fl); 153 if ((lock == File::kLockBlockingShared) ||
152 return rc != -1; 154 (lock == File::kLockBlockingExclusive)) {
155 cmd = F_SETLKW;
156 }
157 return TEMP_FAILURE_RETRY(fcntl(handle_->fd(), cmd, &fl)) != -1;
153 } 158 }
154 159
155 160
156 int64_t File::Length() { 161 int64_t File::Length() {
157 ASSERT(handle_->fd() >= 0); 162 ASSERT(handle_->fd() >= 0);
158 struct stat64 st; 163 struct stat64 st;
159 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) { 164 if (TEMP_FAILURE_RETRY(fstat64(handle_->fd(), &st)) == 0) {
160 return st.st_size; 165 return st.st_size;
161 } 166 }
162 return -1; 167 return -1;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 return ((file_1_info.st_ino == file_2_info.st_ino) && 518 return ((file_1_info.st_ino == file_2_info.st_ino) &&
514 (file_1_info.st_dev == file_2_info.st_dev)) ? 519 (file_1_info.st_dev == file_2_info.st_dev)) ?
515 File::kIdentical : 520 File::kIdentical :
516 File::kDifferent; 521 File::kDifferent;
517 } 522 }
518 523
519 } // namespace bin 524 } // namespace bin
520 } // namespace dart 525 } // namespace dart
521 526
522 #endif // defined(TARGET_OS_LINUX) 527 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_macos.cc » ('j') | sdk/lib/io/file.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698