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

Side by Side Diff: experimental/conways_life/locking_image_data.h

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 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 | « experimental/conways_life/life_module.cc ('k') | experimental/conways_life/scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef LOCKING_IMAGE_DATA_H_
6 #define LOCKING_IMAGE_DATA_H_
7
8 #include "experimental/conways_life/threading/pthread_ext.h"
9 #include "ppapi/cpp/image_data.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/size.h"
12
13 namespace life {
14
15 // An extension of ImageData that can protect direct pixel access thorugh a
16 // mutex lock.
17 class LockingImageData : public pp::ImageData {
18 public:
19 LockingImageData(pp::Instance* instance,
20 PP_ImageDataFormat format,
21 const pp::Size& size,
22 bool init_to_zero)
23 : ImageData(instance, format, size, init_to_zero) {
24 pthread_mutex_init(&pixel_buffer_mutex_, NULL);
25 }
26
27 virtual ~LockingImageData() {
28 UnlockPixels();
29 pthread_mutex_destroy(&pixel_buffer_mutex_);
30 }
31
32 // Acquire the lock in |pixel_owner_| that governs the pixel buffer. Return
33 // a pointer to the locked pixel buffer if successful; return NULL otherwise.
34 uint32_t* LockPixels() {
35 uint32_t* pixels = NULL;
36 if (pthread_mutex_lock(&pixel_buffer_mutex_) == PTHREAD_MUTEX_SUCCESS) {
37 pixels = PixelBufferNoLock();
38 }
39 return pixels;
40 }
41
42 // Release the lock governing the pixel bugger in |pixel_owner_|.
43 void UnlockPixels() {
44 pthread_mutex_unlock(&pixel_buffer_mutex_);
45 }
46
47 uint32_t* PixelBufferNoLock() {
48 return is_null() ? NULL : static_cast<uint32_t*>(data());
49 }
50
51 private:
52 mutable pthread_mutex_t pixel_buffer_mutex_;
53 };
54 } // namespace life
55
56 #endif // LOCKING_IMAGE_DATA_H_
57
OLDNEW
« no previous file with comments | « experimental/conways_life/life_module.cc ('k') | experimental/conways_life/scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698