| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <assert.h> | 5 #include <assert.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "ppapi_main/ppapi_queue.h" | 9 #include "ppapi_main/ppapi_queue.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 if (array_) return false; | 28 if (array_) return false; |
| 29 | 29 |
| 30 array_ = new void*[queue_size]; | 30 array_ = new void*[queue_size]; |
| 31 size_ = queue_size; | 31 size_ = queue_size; |
| 32 | 32 |
| 33 memset(array_, 0, sizeof(void*) * queue_size); | 33 memset(array_, 0, sizeof(void*) * queue_size); |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool PPAPIQueue::AddNewMessage(void* msg) { | 37 bool PPAPIQueue::AddNewMessage(void* msg) { |
| 38 // Writting a NULL message is illegal | 38 // Writing a NULL message is illegal |
| 39 assert(array_ != NULL); | 39 assert(array_ != NULL); |
| 40 assert(msg != NULL); | 40 assert(msg != NULL); |
| 41 | 41 |
| 42 // If the slot not empty, the queue must be full. Calling RemoveStaleMessage | 42 // If the slot not empty, the queue must be full. Calling RemoveStaleMessage |
| 43 // may create space by freeing messages that have already been read. | 43 // may create space by freeing messages that have already been read. |
| 44 if (array_[write_] != NULL) return false; | 44 if (array_[write_] != NULL) return false; |
| 45 | 45 |
| 46 // Write to the spot | 46 // Write to the spot |
| 47 array_[write_] = msg; | 47 array_[write_] = msg; |
| 48 | 48 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void PPAPIQueue::ReleaseTopMessage(void* msg) { | 88 void PPAPIQueue::ReleaseTopMessage(void* msg) { |
| 89 // Verify we currently acquire message. | 89 // Verify we currently acquire message. |
| 90 assert(msg != NULL); | 90 assert(msg != NULL); |
| 91 assert(msg == last_msg_); | 91 assert(msg == last_msg_); |
| 92 | 92 |
| 93 last_msg_ = NULL; | 93 last_msg_ = NULL; |
| 94 | 94 |
| 95 // Signal that the message can be freed. | 95 // Signal that the message can be freed. |
| 96 read_ = (read_ + 1) % size_; | 96 read_ = (read_ + 1) % size_; |
| 97 } | 97 } |
| OLD | NEW |