OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <pthread.h> | |
6 | |
7 #include <map> | |
8 #include <string> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
5 #include "components/nacl/loader/nonsfi/irt_interfaces.h" | 12 #include "components/nacl/loader/nonsfi/irt_interfaces.h" |
6 #include "ppapi/nacl_irt/irt_manifest.h" | 13 #include "ppapi/nacl_irt/irt_manifest.h" |
7 | 14 |
8 namespace nacl { | 15 namespace nacl { |
9 namespace nonsfi { | 16 namespace nonsfi { |
10 | 17 |
18 namespace { | |
19 | |
20 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; | |
hidehiko
2015/01/28 09:05:19
base::Lock?
Yusuke Sato
2015/02/04 02:00:28
I used this primitive type to ensure that g_mu nev
Mark Seaborn
2015/02/04 18:52:16
Indeed, I think it's not safe. base::Lock is a no
| |
21 std::map<std::string, int>* g_fds; | |
22 | |
23 } // namespace | |
24 | |
25 void RegisterPreopenedDescriptors( | |
hidehiko
2015/01/28 09:05:19
Could you move the implementation to ppapi/nacl_ir
Mark Seaborn
2015/02/02 23:21:50
I agree. This belongs in ppapi/nacl_irt/manifest_
Yusuke Sato
2015/02/04 02:00:28
Done.
Yusuke Sato
2015/02/04 02:00:29
Done.
| |
26 const std::vector<std::pair<std::string, int> >& key_fd_pairs) { | |
27 pthread_mutex_lock(&g_mu); | |
hidehiko
2015/01/28 09:05:19
and base::AutoLock?
Yusuke Sato
2015/02/04 02:00:28
same
| |
28 g_fds = new std::map<std::string, int>; | |
29 for (size_t i = 0; i < key_fd_pairs.size(); ++i) | |
30 g_fds->insert(key_fd_pairs[i]); | |
31 pthread_mutex_unlock(&g_mu); | |
32 } | |
33 | |
34 int IrtOpenResource(const char* file, int* fd) { | |
35 pthread_mutex_lock(&g_mu); | |
36 if (g_fds) { | |
37 std::map<std::string, int>::iterator it; | |
38 if (file[0] == '/') | |
39 it = g_fds->find(file + 1); | |
40 else | |
41 it = g_fds->find(file); | |
42 if (it != g_fds->end()) { | |
43 *fd = it->second; | |
44 g_fds->erase(it); | |
45 pthread_mutex_unlock(&g_mu); | |
46 return 0; | |
47 } | |
48 } | |
49 pthread_mutex_unlock(&g_mu); | |
50 return ppapi::IrtOpenResource(file, fd); | |
51 } | |
52 | |
11 const nacl_irt_resource_open kIrtResourceOpen = { | 53 const nacl_irt_resource_open kIrtResourceOpen = { |
12 ppapi::IrtOpenResource, | 54 nacl::nonsfi::IrtOpenResource, |
13 }; | 55 }; |
14 | 56 |
15 } // namespace nonsfi | 57 } // namespace nonsfi |
16 } // namespace nacl | 58 } // namespace nacl |
OLD | NEW |