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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc

Issue 18644009: [NaCl SDK] Upate atomic ops in nacl_io (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add declartions for newval and oldval Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 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 "nacl_io/mount_node_mem.h" 5 #include "nacl_io/mount_node_mem.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "nacl_io/osstat.h" 10 #include "nacl_io/osstat.h"
11 #include "sdk_util/auto_lock.h" 11 #include "sdk_util/auto_lock.h"
12 12
13 #define BLOCK_SIZE (1 << 16) 13 #define BLOCK_SIZE (1 << 16)
14 #define BLOCK_MASK (BLOCK_SIZE - 1) 14 #define BLOCK_MASK (BLOCK_SIZE - 1)
15 15
16 MountNodeMem::MountNodeMem(Mount* mount) 16 MountNodeMem::MountNodeMem(Mount* mount)
17 : MountNode(mount), data_(NULL), capacity_(0) { 17 : MountNode(mount), data_(NULL), capacity_(0) {
18 stat_.st_mode |= S_IFREG; 18 stat_.st_mode |= S_IFREG;
19 } 19 }
20 20
21 MountNodeMem::~MountNodeMem() { free(data_); } 21 MountNodeMem::~MountNodeMem() { free(data_); }
22 22
23 Error MountNodeMem::Read(size_t offs, void* buf, size_t count, int* out_bytes) { 23 Error MountNodeMem::Read(size_t offs, void* buf, size_t count, int* out_bytes) {
24 *out_bytes = 0; 24 *out_bytes = 0;
25 25
26 AutoLock lock(&lock_); 26 AUTO_LOCK(node_lock_);
27 if (count == 0) 27 if (count == 0)
28 return 0; 28 return 0;
29 29
30 size_t size = stat_.st_size; 30 size_t size = stat_.st_size;
31 31
32 if (offs + count > size) { 32 if (offs + count > size) {
33 count = size - offs; 33 count = size - offs;
34 } 34 }
35 35
36 memcpy(buf, &data_[offs], count); 36 memcpy(buf, &data_[offs], count);
37 *out_bytes = static_cast<int>(count); 37 *out_bytes = static_cast<int>(count);
38 return 0; 38 return 0;
39 } 39 }
40 40
41 Error MountNodeMem::Write(size_t offs, 41 Error MountNodeMem::Write(size_t offs,
42 const void* buf, 42 const void* buf,
43 size_t count, 43 size_t count,
44 int* out_bytes) { 44 int* out_bytes) {
45 *out_bytes = 0; 45 *out_bytes = 0;
46 AutoLock lock(&lock_); 46 AUTO_LOCK(node_lock_);
47 47
48 if (count == 0) 48 if (count == 0)
49 return 0; 49 return 0;
50 50
51 if (count + offs > stat_.st_size) { 51 if (count + offs > stat_.st_size) {
52 Error error = FTruncate(count + offs); 52 Error error = FTruncate(count + offs);
53 if (error) 53 if (error)
54 return error; 54 return error;
55 55
56 count = stat_.st_size - offs; 56 count = stat_.st_size - offs;
(...skipping 29 matching lines...) Expand all
86 86
87 // If we failed, then adjust size according to what we keep 87 // If we failed, then adjust size according to what we keep
88 if (new_size > capacity_) 88 if (new_size > capacity_)
89 new_size = capacity_; 89 new_size = capacity_;
90 90
91 // Update the size and return the new size 91 // Update the size and return the new size
92 stat_.st_size = static_cast<off_t>(new_size); 92 stat_.st_size = static_cast<off_t>(new_size);
93 return EIO; 93 return EIO;
94 } 94 }
95 95
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698