OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "native_client/src/shared/ppapi_proxy/proxy_var_cache.h" | 5 #include "native_client/src/shared/ppapi_proxy/proxy_var_cache.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "native_client/src/include/ref_counted.h" | 10 #include "native_client/src/include/ref_counted.h" |
11 #include "native_client/src/untrusted/pthread/pthread.h" | 11 #include "native_client/src/untrusted/pthread/pthread.h" |
12 | 12 |
13 namespace ppapi_proxy { | 13 namespace ppapi_proxy { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER; | 17 pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER; |
18 | 18 |
| 19 // Convert the given SharedProxyVar to a PP_Var, incrementing the reference |
| 20 // count by 1. |
| 21 PP_Var GetPPVar(const SharedProxyVar& proxy_var) { |
| 22 PP_Var var; |
| 23 var.type = proxy_var->pp_var_type(); |
| 24 var.padding = 0; |
| 25 var.value.as_id = proxy_var->id(); |
| 26 proxy_var->AddRef(); |
| 27 return var; |
| 28 } |
| 29 |
19 } // namespace | 30 } // namespace |
20 | 31 |
21 ProxyVarCache* ProxyVarCache::cache_singleton = NULL; | 32 ProxyVarCache* ProxyVarCache::cache_singleton = NULL; |
22 | 33 |
23 ProxyVarCache& ProxyVarCache::GetInstance() { | 34 ProxyVarCache& ProxyVarCache::GetInstance() { |
24 // When the deprecated scripting is removed, this crash should disappear. | 35 // When the deprecated scripting is removed, this crash should disappear. |
25 // static ProxyVarCache cache_singleton; | 36 // static ProxyVarCache cache_singleton; |
26 // return cache_singleton; | 37 // return cache_singleton; |
27 pthread_mutex_lock(&mu); | 38 pthread_mutex_lock(&mu); |
28 if (cache_singleton == NULL) | 39 if (cache_singleton == NULL) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 pthread_mutex_lock(&mu); | 90 pthread_mutex_lock(&mu); |
80 ProxyVarDictionary::const_iterator iter = | 91 ProxyVarDictionary::const_iterator iter = |
81 proxy_var_cache_.find(pp_var.value.as_id); | 92 proxy_var_cache_.find(pp_var.value.as_id); |
82 if (iter != proxy_var_cache_.end()) { | 93 if (iter != proxy_var_cache_.end()) { |
83 proxy_var = iter->second; | 94 proxy_var = iter->second; |
84 } | 95 } |
85 pthread_mutex_unlock(&mu); | 96 pthread_mutex_unlock(&mu); |
86 return proxy_var; | 97 return proxy_var; |
87 } | 98 } |
88 | 99 |
| 100 std::vector<PP_Var> ProxyVarCache::GetLiveVars() { |
| 101 std::vector<PP_Var> live_vars; |
| 102 pthread_mutex_lock(&mu); |
| 103 for (ProxyVarDictionary::const_iterator iter(proxy_var_cache_.begin()); |
| 104 iter != proxy_var_cache_.end(); |
| 105 ++iter) |
| 106 live_vars.push_back(GetPPVar(iter->second)); |
| 107 pthread_mutex_unlock(&mu); |
| 108 return live_vars; |
| 109 } |
| 110 |
89 } // namespace ppapi_proxy | 111 } // namespace ppapi_proxy |
OLD | NEW |