| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/drm/gpu/gpu_lock.h" | 5 #include "ui/ozone/platform/drm/gpu/gpu_lock.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <sys/file.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 const char kGpuLockFile[] = "/run/frecon"; | 16 const char kGpuLockFile[] = "/run/frecon"; |
| 17 } | 17 } |
| 18 | 18 |
| 19 GpuLock::GpuLock() { | 19 GpuLock::GpuLock() { |
| 20 fd_ = open(kGpuLockFile, O_RDWR); | 20 fd_ = open(kGpuLockFile, O_RDWR); |
| 21 if (fd_ < 0) { | 21 if (fd_ < 0) { |
| 22 PLOG(ERROR) << "Failed to open lock file '" << kGpuLockFile << "'"; | 22 PLOG(ERROR) << "Failed to open lock file '" << kGpuLockFile << "'"; |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 | 25 |
| 26 struct flock data; | |
| 27 memset(&data, 0, sizeof(data)); | |
| 28 data.l_type = F_WRLCK; | |
| 29 data.l_whence = SEEK_SET; | |
| 30 | |
| 31 VLOG(1) << "Taking write lock on '" << kGpuLockFile << "'"; | 26 VLOG(1) << "Taking write lock on '" << kGpuLockFile << "'"; |
| 32 if (HANDLE_EINTR(fcntl(fd_, F_SETLKW, &data))) | 27 if (HANDLE_EINTR(flock(fd_, LOCK_EX))) |
| 33 PLOG(ERROR) << "Error while trying to get lock on '" << kGpuLockFile << "'"; | 28 PLOG(ERROR) << "Error while trying to get lock on '" << kGpuLockFile << "'"; |
| 34 | 29 |
| 35 VLOG(1) << "Done trying to take write lock on '" << kGpuLockFile << "'"; | 30 VLOG(1) << "Done trying to take write lock on '" << kGpuLockFile << "'"; |
| 36 } | 31 } |
| 37 | 32 |
| 38 GpuLock::~GpuLock() { | 33 GpuLock::~GpuLock() { |
| 39 // Failed to open the lock file, so nothing to do here. | 34 // Failed to open the lock file, so nothing to do here. |
| 40 if (fd_ < 0) | 35 if (fd_ < 0) |
| 41 return; | 36 return; |
| 42 | 37 |
| 43 VLOG(1) << "Releasing write lock on '" << kGpuLockFile << "'"; | 38 VLOG(1) << "Releasing write lock on '" << kGpuLockFile << "'"; |
| 44 close(fd_); | 39 close(fd_); |
| 45 } | 40 } |
| 46 | 41 |
| 47 } // namespace ui | 42 } // namespace ui |
| OLD | NEW |