diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Action.cc | 1 | ||||
-rw-r--r-- | lib/Buffer.cc | 7 | ||||
-rw-r--r-- | lib/Domain.cc | 11 | ||||
-rw-r--r-- | lib/Handle.cc | 7 | ||||
-rw-r--r-- | lib/MailServer.cc | 13 | ||||
-rw-r--r-- | lib/Output.cc | 5 |
6 files changed, 34 insertions, 10 deletions
diff --git a/lib/Action.cc b/lib/Action.cc index 7cffc70..dbd6d05 100644 --- a/lib/Action.cc +++ b/lib/Action.cc @@ -25,6 +25,7 @@ #include "HttpServ.h" Action * Action::start = 0; +iLock Action::lock; static int counter = 0; static HtmlSkinner default_skinner; diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 447f883..eb97e4d 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -23,6 +23,7 @@ #endif #include "Buffer.h" #include "generic.h" +#include "Atomic.h" int Buffer::nb_buffer = 0; @@ -31,18 +32,18 @@ int Buffer::GetNbBuffer() { } Buffer::Buffer(bool _seekable) : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0), wptr(0), seekable(_seekable), got_eof(false) { - nb_buffer++; + Atomic::Increment(&nb_buffer); } Buffer::~Buffer() { free(buffer); - nb_buffer--; + Atomic::Decrement(&nb_buffer); } Buffer::Buffer(const Buffer & b) : Handle(-1), buffer(0), zero(b.zero), realsiz(b.realsiz), bufsiz(b.bufsiz), ptr(b.ptr), wptr(b.wptr), seekable(b.seekable), got_eof(b.got_eof) { buffer = (Byte *) malloc(bufsiz); memcpy(buffer, b.buffer, bufsiz); - nb_buffer++; + Atomic::Increment(&nb_buffer); } ssize_t Buffer::write(const void *buf, size_t count) throw (GeneralException) { diff --git a/lib/Domain.cc b/lib/Domain.cc index 6114e90..c7af1f1 100644 --- a/lib/Domain.cc +++ b/lib/Domain.cc @@ -20,6 +20,7 @@ #include "Domain.h" Domain * Domain::head = 0; +iLock Domain::lock; Domain * Domain::First() { return head; @@ -36,22 +37,27 @@ String Domain::GetPattern() { Domain::Domain(const Regex & _pattern) : pattern(_pattern) { printm(M_INFO, "Creating Domain with pattern = " + pattern.GetPattern() + "\n"); prev = 0; + lock.lock(); next = head; head = this; if (next) next->prev = this; + lock.unlock(); } Domain::~Domain() { + lock.lock(); if (head == this) head = next; if (next) next->prev = prev; if (prev) prev->next = next; + lock.unlock(); } void Domain::OnTop() { + lock.lock(); if (next) next->prev = prev; if (prev) @@ -61,13 +67,16 @@ void Domain::OnTop() { next = head; head = this; next->prev = this; + lock.unlock(); } Domain * Domain::find_domain(const String & url, int nmatches, regmatch_t * pmatches) { Domain * r = 0; + lock.lock(); if (head) r = head->find_domain_r(url, nmatches, pmatches); + lock.unlock(); return r; } @@ -77,7 +86,7 @@ Domain * Domain::find_domain_r(const String & url, int nmatches, regmatch_t * pm return this; if (next) - return next->find_domain_r(url); + return next->find_domain_r(url, nmatches, pmatches); return 0; } diff --git a/lib/Handle.cc b/lib/Handle.cc index efe2e15..81c72e7 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -56,6 +56,7 @@ inline Uint32 bswap_32(Uint32 w) { #endif #include "Handle.h" +#include "Atomic.h" #include "gettext.h" enum { @@ -73,7 +74,7 @@ Handle::Handle(const Handle & nh) : itell(0), hFile(0), h(nh.h >= 0 ? nh.ndup() if ((h >= 0) && (nh.z)) { SetZ(nh.z); } - nb_handles++; + Atomic::Increment(&nb_handles); } Handle::~Handle() { @@ -81,7 +82,7 @@ Handle::~Handle() { printm(M_INFO, String(_("Destroying handle ")) + h + "\n"); #endif close(); - nb_handles--; + Atomic::Decrement(&nb_handles); } Handle::Handle(int nh) : itell(0), h(nh), closed(false), nonblock(false), zfile(0), z(0), hMapObject(0), mapped(0) @@ -89,7 +90,7 @@ Handle::Handle(int nh) : itell(0), h(nh), closed(false), nonblock(false), zfile( #ifdef DEBUG printm(M_INFO, String(_("Initialising handle ")) + h + "\n"); #endif - nb_handles++; + Atomic::Increment(&nb_handles); } int Handle::GetHandle() { diff --git a/lib/MailServer.cc b/lib/MailServer.cc index 2c394cc..b4eac77 100644 --- a/lib/MailServer.cc +++ b/lib/MailServer.cc @@ -185,38 +185,48 @@ int ProcessSMTPRequest::Do() throw (GeneralException) { } MailHandler * MailHandler::head = 0; +iLock MailHandler::lock; MailHandler::MailHandler() { + lock.lock(); prev = 0; next = head; head = this; if (next) next->prev = this; + lock.unlock(); } MailHandler::~MailHandler() { + lock.lock(); if (prev) prev->next = next; if (next) next->prev = prev; if (head == this) head = next; + lock.unlock(); } Task * MailHandler::ProcessMail(Handle * in, const String & from, std::vector<String> tos) { MailHandler * cur; Task * r; + lock.lock(); for (cur = head; cur; cur = cur->next) { - if (( r = cur->ProcessMail(in, from, tos))) + if (( r = cur->doProcessMail(in, from, tos))) { + lock.unlock(); return r; + } } + lock.unlock(); return 0; } void MailHandler::OnTop() { if (head == this) return; + lock.lock(); if (prev) prev->next = next; if (next) @@ -226,6 +236,7 @@ void MailHandler::OnTop() { head = this; if (next) next->prev = this; + lock.unlock(); } MailServer::MailServer(int _port, const String & _name) throw (GeneralException) : name(_name), localport(_port) { diff --git a/lib/Output.cc b/lib/Output.cc index caabfa5..1222ead 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -33,6 +33,7 @@ #include <fcntl.h> #include "Output.h" #include "Exceptions.h" +#include "Atomic.h" #include "gettext.h" #ifndef S_ISREG @@ -52,7 +53,7 @@ Output::Output(String no, int create, int trunc) throw (GeneralException) : throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno)); } - nb_output++; + Atomic::Increment(&nb_output); size = lseek(GetHandle(), 0, SEEK_END); if (trunc) @@ -107,7 +108,7 @@ int Output::wrapopen(const String & n, int create, int trunc) { } Output::Output(const Output & o) : Handle(o), n(o.n) { - nb_output++; + Atomic::Increment(&nb_output); } bool Output::CanWrite() const { |