Chromium Code Reviews| Index: ppapi/nacl_irt/manifest_service.cc |
| diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc |
| index 8e671b90ceac9f24df864d175a373eb38c643968..130ee6be7a82e4ded93d152083afd5ba4af39383 100644 |
| --- a/ppapi/nacl_irt/manifest_service.cc |
| +++ b/ppapi/nacl_irt/manifest_service.cc |
| @@ -13,6 +13,12 @@ |
| #include "ppapi/nacl_irt/plugin_startup.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| +#if !defined(OS_NACL_SFI) |
| +#include <pthread.h> |
| +#include <map> |
| +#include <string> |
| +#endif |
| + |
| namespace ppapi { |
| const char kFilePrefix[] = "files/"; |
| @@ -120,11 +126,43 @@ bool ManifestService::OpenResource(const char* file, int* fd) { |
| return true; |
| } |
| +#if !defined(OS_NACL_SFI) |
| +namespace { |
| + |
| +pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; |
| +std::map<std::string, int>* g_fds; |
|
Mark Seaborn
2015/02/12 03:57:34
How about "g_prefetched_fds" to be more descriptiv
Yusuke Sato
2015/02/13 23:01:17
Done.
|
| + |
| +} // namespace |
| + |
| +void RegisterPreopenedDescriptorsNonSfi( |
| + const std::map<std::string, int>& key_fd_map) { |
| + pthread_mutex_lock(&g_mu); |
| + DCHECK(!g_fds); |
| + g_fds = new std::map<std::string, int>; |
| + *g_fds = key_fd_map; |
| + pthread_mutex_unlock(&g_mu); |
| +} |
| +#endif |
| + |
| int IrtOpenResource(const char* file, int* fd) { |
| // Remove leading '/' character. |
| if (file[0] == '/') |
| ++file; |
| +#if !defined(OS_NACL_SFI) |
|
Mark Seaborn
2015/02/12 03:57:34
Can you add a comment like:
// Fast path for prefe
Yusuke Sato
2015/02/13 23:01:17
Done.
|
| + pthread_mutex_lock(&g_mu); |
| + if (g_fds) { |
| + std::map<std::string, int>::iterator it = g_fds->find(file); |
| + if (it != g_fds->end()) { |
| + *fd = it->second; |
| + g_fds->erase(it); |
| + pthread_mutex_unlock(&g_mu); |
| + return 0; |
| + } |
| + } |
| + pthread_mutex_unlock(&g_mu); |
| +#endif |
| + |
| ManifestService* manifest_service = GetManifestService(); |
| if (manifest_service == NULL || |
| !manifest_service->OpenResource(file, fd)) { |