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

Side by Side Diff: libraries/nacl-mounts/buffer/BufferMount.cc

Issue 10392070: Socket subsystem implementation (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 #include "BufferMount.h" 6 #include "BufferMount.h"
7 #include <assert.h> 7 #include <assert.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <string.h> 9 #include <string.h>
10 #include "../util/SimpleAutoLock.h" 10 #include "../util/PthreadHelpers.h"
11 11
12 12
13 BufferMount::BufferMount(Mount* source, size_t chunk_size, size_t max_chunks) { 13 BufferMount::BufferMount(Mount* source, size_t chunk_size, size_t max_chunks) {
14 if (pthread_mutex_init(&cache_lock_, NULL)) assert(0); 14 if (pthread_mutex_init(&cache_lock_, NULL)) assert(0);
15 source_ = source; 15 source_ = source;
16 chunk_size_ = chunk_size; 16 chunk_size_ = chunk_size;
17 max_chunks_ = max_chunks; 17 max_chunks_ = max_chunks;
18 assert(max_chunks_ > 0); 18 assert(max_chunks_ > 0);
19 } 19 }
20 20
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 off_t noffset = offset / chunk_size_ * chunk_size_; 209 off_t noffset = offset / chunk_size_ * chunk_size_;
210 sz = source_->Read(node, noffset, buf, chunk_size_); 210 sz = source_->Read(node, noffset, buf, chunk_size_);
211 if (sz < 0) return sz; 211 if (sz < 0) return sz;
212 AddCachedBlock(node, noffset, buf, sz); 212 AddCachedBlock(node, noffset, buf, sz);
213 213
214 // Now it should be in the cache. 214 // Now it should be in the cache.
215 sz = GetCachedBlock(node, offset, data, count); 215 sz = GetCachedBlock(node, offset, data, count);
216 assert(sz >= 0); 216 assert(sz >= 0);
217 return sz; 217 return sz;
218 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698