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

Side by Side Diff: ui/ozone/platform/drm/gpu/gpu_lock.cc

Issue 1007993007: [Ozone-Drm] Change file locking from Posix to BSD style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698