OLD | NEW |
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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <copyfile.h> // NOLINT | 10 #include <copyfile.h> // NOLINT |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { | 133 bool File::Lock(File::LockType lock, int64_t start, int64_t end) { |
134 ASSERT(handle_->fd() >= 0); | 134 ASSERT(handle_->fd() >= 0); |
135 ASSERT((end == -1) || (end > start)); | 135 ASSERT((end == -1) || (end > start)); |
136 struct flock fl; | 136 struct flock fl; |
137 switch (lock) { | 137 switch (lock) { |
138 case File::kLockUnlock: | 138 case File::kLockUnlock: |
139 fl.l_type = F_UNLCK; | 139 fl.l_type = F_UNLCK; |
140 break; | 140 break; |
141 case File::kLockShared: | 141 case File::kLockShared: |
| 142 case File::kLockBlockingShared: |
142 fl.l_type = F_RDLCK; | 143 fl.l_type = F_RDLCK; |
143 break; | 144 break; |
144 case File::kLockExclusive: | 145 case File::kLockExclusive: |
| 146 case File::kLockBlockingExclusive: |
145 fl.l_type = F_WRLCK; | 147 fl.l_type = F_WRLCK; |
146 break; | 148 break; |
147 default: | 149 default: |
148 return false; | 150 return false; |
149 } | 151 } |
150 fl.l_whence = SEEK_SET; | 152 fl.l_whence = SEEK_SET; |
151 fl.l_start = start; | 153 fl.l_start = start; |
152 fl.l_len = end == -1 ? 0 : end - start; | 154 fl.l_len = end == -1 ? 0 : end - start; |
153 // fcntl does not block, but fails if the lock cannot be acquired. | 155 int cmd = F_SETLK; |
154 int rc = fcntl(handle_->fd(), F_SETLK, &fl); | 156 if ((lock == File::kLockBlockingShared) || |
155 return rc != -1; | 157 (lock == File::kLockBlockingExclusive)) { |
| 158 cmd = F_SETLKW; |
| 159 } |
| 160 return TEMP_FAILURE_RETRY(fcntl(handle_->fd(), cmd, &fl)) != -1; |
156 } | 161 } |
157 | 162 |
158 | 163 |
159 int64_t File::Length() { | 164 int64_t File::Length() { |
160 ASSERT(handle_->fd() >= 0); | 165 ASSERT(handle_->fd() >= 0); |
161 struct stat st; | 166 struct stat st; |
162 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { | 167 if (NO_RETRY_EXPECTED(fstat(handle_->fd(), &st)) == 0) { |
163 return st.st_size; | 168 return st.st_size; |
164 } | 169 } |
165 return -1; | 170 return -1; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 return ((file_1_info.st_ino == file_2_info.st_ino) && | 482 return ((file_1_info.st_ino == file_2_info.st_ino) && |
478 (file_1_info.st_dev == file_2_info.st_dev)) ? | 483 (file_1_info.st_dev == file_2_info.st_dev)) ? |
479 File::kIdentical : | 484 File::kIdentical : |
480 File::kDifferent; | 485 File::kDifferent; |
481 } | 486 } |
482 | 487 |
483 } // namespace bin | 488 } // namespace bin |
484 } // namespace dart | 489 } // namespace dart |
485 | 490 |
486 #endif // defined(TARGET_OS_MACOS) | 491 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |