ngx_base_fetch: implement locking
This commit is contained in:
@@ -57,7 +57,7 @@ pagespeed_include="$mod_pagespeed_dir
|
|||||||
$mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include/"
|
$mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include/"
|
||||||
ngx_feature_path="$pagespeed_include"
|
ngx_feature_path="$pagespeed_include"
|
||||||
pagespeed_automatic_dir="$mod_pagespeed_dir/net/instaweb/automatic"
|
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_libs="$pagespeed_libs"
|
||||||
ngx_feature_test="
|
ngx_feature_test="
|
||||||
GoogleString output_buffer;
|
GoogleString output_buffer;
|
||||||
|
|||||||
+12
-1
@@ -27,10 +27,21 @@ namespace net_instaweb {
|
|||||||
NgxBaseFetch::NgxBaseFetch(ngx_http_request_t* r, int pipe_fd)
|
NgxBaseFetch::NgxBaseFetch(ngx_http_request_t* r, int pipe_fd)
|
||||||
: request_(r), done_called_(false), last_buf_sent_(false),
|
: request_(r), done_called_(false), last_buf_sent_(false),
|
||||||
pipe_fd_(pipe_fd) {
|
pipe_fd_(pipe_fd) {
|
||||||
|
if (pthread_mutex_init(&mutex_, NULL)) CHECK(0);
|
||||||
PopulateRequestHeaders();
|
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() {
|
void NgxBaseFetch::PopulateRequestHeaders() {
|
||||||
CopyHeadersFromTable<RequestHeaders>(&request_->headers_in.headers,
|
CopyHeadersFromTable<RequestHeaders>(&request_->headers_in.headers,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#define NGX_BASE_FETCH_H_
|
#define NGX_BASE_FETCH_H_
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include <pthread.h>
|
||||||
#include <ngx_http.h>
|
#include <ngx_http.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,21 +93,15 @@ class NgxBaseFetch : public AsyncFetch {
|
|||||||
// buffer_.
|
// buffer_.
|
||||||
ngx_int_t CopyBufferToNginx(ngx_chain_t** link_ptr);
|
ngx_int_t CopyBufferToNginx(ngx_chain_t** link_ptr);
|
||||||
|
|
||||||
// Acquire this lock before manipulating buffer_.
|
void Lock();
|
||||||
// TODO(jefftk): Actually implement this. Possibly with ngx_shmtx_lock and
|
void Unlock();
|
||||||
// ngx_shmtx_unlock.
|
|
||||||
void Lock() {
|
|
||||||
fprintf(stderr, "Would lock buffer_\n");
|
|
||||||
}
|
|
||||||
void Unlock() {
|
|
||||||
fprintf(stderr, "Would unlock buffer_\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_http_request_t* request_;
|
ngx_http_request_t* request_;
|
||||||
GoogleString buffer_;
|
GoogleString buffer_;
|
||||||
bool done_called_;
|
bool done_called_;
|
||||||
bool last_buf_sent_;
|
bool last_buf_sent_;
|
||||||
int pipe_fd_;
|
int pipe_fd_;
|
||||||
|
pthread_mutex_t mutex_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch);
|
DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user