public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Make StandardApplicationPool thread-safe, and make it cache spawned 
applications with a naive algorithm.
FooBarWidget (author)
Sat Feb 02 15:46:50 -0800 2008
commit  ff5e85d3b3d69dd10a2b433fa1c5612867d93497
tree    80ff0db5e65f227d810af2574b8beccaedb90996
parent  4becb67e448055fb31a89cb4979a8356c54f81c8
...
2
3
4
 
 
5
6
7
...
26
27
28
 
 
29
30
31
32
33
34
35
36
...
37
38
39
40
 
 
 
41
 
 
 
 
42
43
44
45
46
47
48
49
50
51
 
 
 
 
52
53
54
55
56
 
 
 
 
57
58
59
...
2
3
4
5
6
7
8
9
...
28
29
30
31
32
33
34
35
36
37
38
39
40
...
41
42
43
 
44
45
46
47
48
49
50
51
52
 
 
53
54
 
 
55
 
 
56
57
58
59
60
 
 
 
 
61
62
63
64
65
66
67
0
@@ -2,6 +2,8 @@
0
 #define _PASSENGER_APPLICATION_POOL_H_
0
 
0
 #include <boost/shared_ptr.hpp>
0
+#include <boost/thread/mutex.hpp>
0
+
0
 #include <string>
0
 #include <map>
0
 
0
@@ -26,6 +28,8 @@
0
 
0
   SpawnManager spawnManager;
0
   ApplicationMap apps;
0
+ mutex lock;
0
+ bool threadSafe;
0
   
0
   string normalizePath(const string &path) {
0
     // TODO
0
0
0
0
0
0
@@ -37,23 +41,27 @@
0
    const string &logFile = "",
0
    const string &environment = "production",
0
    const string &rubyCommand = "ruby")
0
- : spawnManager(spawnManagerCommand, logFile, environment, rubyCommand) {}
0
+ : spawnManager(spawnManagerCommand, logFile, environment, rubyCommand) {
0
+ threadSafe = false;
0
+ }
0
   
0
+ void setThreadSafe() {
0
+ threadSafe = true;
0
+ }
0
+
0
   // TODO: improve algorithm
0
- // TODO: make thread-safe
0
- // TODO: make it possible to share an ApplicationPool between processes
0
   virtual ApplicationPtr get(const string &appRoot, const string &user = "", const string &group = "") {
0
     string normalizedAppRoot(normalizePath(appRoot));
0
- //scoped_lock l(lock);
0
-
0
     ApplicationPtr app;
0
- //ApplicationMap::iterator it(apps.find(appRoot));
0
- //if (it == apps.end()) {
0
+ mutex::scoped_lock l(lock, threadSafe);
0
+
0
+ ApplicationMap::iterator it(apps.find(appRoot));
0
+ if (it == apps.end()) {
0
       app = spawnManager.spawn(appRoot, user, group);
0
- // apps[appRoot] = app;
0
- //} else {
0
- // app = it->second;
0
- //}
0
+ apps[appRoot] = app;
0
+ } else {
0
+ app = it->second;
0
+ }
0
     return app;
0
   }
0
 };

Comments

    No one has commented yet.