ngx_base_fetch: implement locking

This commit is contained in:
Ben Noordhuis
2012-11-08 03:20:01 +01:00
parent 4f3bf2d495
commit 4aad27ccf9
3 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ pagespeed_include="$mod_pagespeed_dir
$mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include/"
ngx_feature_path="$pagespeed_include"
pagespeed_automatic_dir="$mod_pagespeed_dir/net/instaweb/automatic"
pagespeed_libs="-lstdc++ $pagespeed_automatic_dir/pagespeed_automatic.a -lrt"
pagespeed_libs="-lstdc++ $pagespeed_automatic_dir/pagespeed_automatic.a -lrt -pthread"
ngx_feature_libs="$pagespeed_libs"
ngx_feature_test="
GoogleString output_buffer;
+12 -1
View File
@@ -27,10 +27,21 @@ namespace net_instaweb {
NgxBaseFetch::NgxBaseFetch(ngx_http_request_t* r, int pipe_fd)
: request_(r), done_called_(false), last_buf_sent_(false),
pipe_fd_(pipe_fd) {
if (pthread_mutex_init(&mutex_, NULL)) CHECK(0);
PopulateRequestHeaders();
}
NgxBaseFetch::~NgxBaseFetch() { }
NgxBaseFetch::~NgxBaseFetch() {
pthread_mutex_destroy(&mutex_);
}
void NgxBaseFetch::Lock() {
pthread_mutex_lock(&mutex_);
}
void NgxBaseFetch::Unlock() {
pthread_mutex_unlock(&mutex_);
}
void NgxBaseFetch::PopulateRequestHeaders() {
CopyHeadersFromTable<RequestHeaders>(&request_->headers_in.headers,
+4 -9
View File
@@ -33,6 +33,7 @@
#define NGX_BASE_FETCH_H_
extern "C" {
#include <pthread.h>
#include <ngx_http.h>
}
@@ -92,21 +93,15 @@ class NgxBaseFetch : public AsyncFetch {
// buffer_.
ngx_int_t CopyBufferToNginx(ngx_chain_t** link_ptr);
// Acquire this lock before manipulating buffer_.
// TODO(jefftk): Actually implement this. Possibly with ngx_shmtx_lock and
// ngx_shmtx_unlock.
void Lock() {
fprintf(stderr, "Would lock buffer_\n");
}
void Unlock() {
fprintf(stderr, "Would unlock buffer_\n");
}
void Lock();
void Unlock();
ngx_http_request_t* request_;
GoogleString buffer_;
bool done_called_;
bool last_buf_sent_;
int pipe_fd_;
pthread_mutex_t mutex_;
DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch);
};