hewei преди 6 години
родител
ревизия
387f3f483a
променени са 3 файла, в които са добавени 6 реда и са изтрити 0 реда
  1. 2 0
      http/server/FileCache.cpp
  2. 2 0
      http/server/FileCache.h
  3. 2 0
      http/server/HttpServer.cpp

+ 2 - 0
http/server/FileCache.cpp

@@ -6,6 +6,7 @@
 #include "http_page.h" //make_index_of_page
 
 file_cache_t* FileCache::Open(const char* filepath, void* ctx) {
+    std::lock_guard<std::mutex> locker(mutex_);
     file_cache_t* fc = Get(filepath);
     bool modified = false;
     if (fc) {
@@ -71,6 +72,7 @@ file_cache_t* FileCache::Open(const char* filepath, void* ctx) {
 }
 
 int FileCache::Close(const char* filepath) {
+    std::lock_guard<std::mutex> locker(mutex_);
     auto iter = cached_files.find(filepath);
     if (iter != cached_files.end()) {
         delete iter->second;

+ 2 - 0
http/server/FileCache.h

@@ -7,6 +7,7 @@
 #include "hbuf.h"
 #include "hfile.h"
 #include "hstring.h"
+#include "hmutex.h"
 
 #define HTTP_HEADER_MAX_LENGTH      1024 // 1k
 
@@ -69,6 +70,7 @@ public:
     int Close(const char* filepath);
 protected:
     file_cache_t* Get(const char* filepath);
+    std::mutex mutex_;
 };
 
 #endif // HV_FILE_CACHE_H_

+ 2 - 0
http/server/HttpServer.cpp

@@ -283,6 +283,7 @@ static void fsync_logfile(hidle_t* idle) {
 }
 
 static HTHREAD_ROUTINE(worker_thread) {
+    hlogi("worker_thread pid=%d tid=%d", getpid(), gettid());
     http_server_t* server = (http_server_t*)userdata;
     int listenfd = server->listenfd;
     hloop_t* loop = hloop_new(0);
@@ -365,6 +366,7 @@ int http_server_run(http_server_t* server, int wait) {
             ctx->proc = worker_proc;
             ctx->proc_userdata = server;
             spawn_proc(ctx);
+            hlogi("workers[%d] start/running, pid=%d", i, ctx->pid);
         }
         if (wait) {
             master_init(NULL);