From fa3441cfdf84da5841619c7e2e66fd8ea3aefac6 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 9 Mar 2010 18:57:53 +0000 Subject: [PATCH] XmlRpc: Shortcurcuit mode (server and client are the same), *Draw: Fixed critical deadlock problem in FindIml git-svn-id: svn://ultimatepp.org/upp/trunk@2202 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Path.cpp | 2 +- uppsrc/Draw/Image.cpp | 95 ++++++++++++++++------------------------ uppsrc/Draw/Image.h | 2 - uppsrc/XmlRpc/Client.cpp | 19 +++++++- uppsrc/XmlRpc/XmlRpc.h | 3 +- 5 files changed, 59 insertions(+), 62 deletions(-) diff --git a/uppsrc/Core/Path.cpp b/uppsrc/Core/Path.cpp index 99bab8b31..ca7319a43 100644 --- a/uppsrc/Core/Path.cpp +++ b/uppsrc/Core/Path.cpp @@ -451,7 +451,7 @@ bool FindFile::IsSymLink() const bool FindFile::IsExecutable() const { - return !IsDirectory() && ToLower(GetName()).EndsWith(".exe"); } + return !IsDirectory() && ToLower(GetName()).EndsWith(".exe"); } void FindFile::Close() { diff --git a/uppsrc/Draw/Image.cpp b/uppsrc/Draw/Image.cpp index 93e711bf6..7b2336040 100644 --- a/uppsrc/Draw/Image.cpp +++ b/uppsrc/Draw/Image.cpp @@ -445,37 +445,34 @@ void Iml::Set(int i, const Image& img) map[i].loaded = true; } -static StaticCriticalSection sImgImlLock; - Image Iml::Get(int i) { IImage& m = map[i]; if(!m.loaded) { - INTERLOCKED_(sImgImlLock) { - if(data.GetCount()) { - int ii = 0; - for(;;) { - const Data& d = data[ii]; - if(i < d.count) { - static const char *cached_data; - static Vector cached; - if(cached_data != d.data) { - cached_data = d.data; - cached = UnpackImlData(String(d.data, d.len)); - if(premultiply) - for(int i = 0; i < cached.GetCount(); i++) - cached[i] = Premultiply(cached[i]); - } - m.image = cached[i]; - break; + DrawLock __; + if(data.GetCount()) { + int ii = 0; + for(;;) { + const Data& d = data[ii]; + if(i < d.count) { + static const char *cached_data; + static Vector cached; + if(cached_data != d.data) { + cached_data = d.data; + cached = UnpackImlData(String(d.data, d.len)); + if(premultiply) + for(int i = 0; i < cached.GetCount(); i++) + cached[i] = Premultiply(cached[i]); } - i -= d.count; - ii++; + m.image = cached[i]; + break; } + i -= d.count; + ii++; } - else - m.image = Premultiply(Image(img_init[i])); } + else + m.image = Premultiply(Image(img_init[i])); m.loaded = true; } return m.image; @@ -545,30 +542,16 @@ Iml& GetIml(int i) return *sImgMap()[i]; } -void Iml::Enter() -{ - sImgMapLock.Enter(); -} - -void Iml::Leave() -{ - sImgMapLock.Leave(); -} - String GetImlName(int i) { - String x; - INTERLOCKED_(sImgMapLock) - x = sImgMap().GetKey(i); - return x; + DrawLock __; + return sImgMap().GetKey(i); } int FindIml(const char *name) { - int q; - INTERLOCKED_(sImgMapLock) - q = sImgMap().Find(name); - return q; + DrawLock __; + return sImgMap().Find(name); } Image GetImlImage(const char *name) @@ -576,16 +559,15 @@ Image GetImlImage(const char *name) Image m; const char *w = strchr(name, ':'); if(w) { + DrawLock __; int q = FindIml(String(name, w)); if(q >= 0) { - INTERLOCKED_(sImgMapLock) { - Iml& iml = *sImgMap()[q]; - while(*w == ':') - w++; - q = iml.Find(w); - if(q >= 0) - m = iml.Get(q); - } + Iml& iml = *sImgMap()[q]; + while(*w == ':') + w++; + q = iml.Find(w); + if(q >= 0) + m = iml.Get(q); } } return m; @@ -595,16 +577,15 @@ void SetImlImage(const char *name, const Image& m) { const char *w = strchr(name, ':'); if(w) { + DrawLock __; int q = FindIml(String(name, w)); if(q >= 0) { - INTERLOCKED_(sImgMapLock) { - Iml& iml = *sImgMap()[q]; - while(*w == ':') - w++; - q = iml.Find(w); - if(q >= 0) - iml.Set(q, m); - } + Iml& iml = *sImgMap()[q]; + while(*w == ':') + w++; + q = iml.Find(w); + if(q >= 0) + iml.Set(q, m); } } } diff --git a/uppsrc/Draw/Image.h b/uppsrc/Draw/Image.h index b00ad5ba8..03817affc 100644 --- a/uppsrc/Draw/Image.h +++ b/uppsrc/Draw/Image.h @@ -299,8 +299,6 @@ class Iml { void Init(int n); public: - void Enter(); - void Leave(); void Reset(); int GetCount() const { return map.GetCount(); } String GetId(int i) { return map.GetKey(i); } diff --git a/uppsrc/XmlRpc/Client.cpp b/uppsrc/XmlRpc/Client.cpp index e140e0546..2add38705 100644 --- a/uppsrc/XmlRpc/Client.cpp +++ b/uppsrc/XmlRpc/Client.cpp @@ -2,11 +2,28 @@ #define LLOG(x) // LOG(x) +XmlRpcCall::XmlRpcCall(const char *url) +{ + shorted = true; + if(url && *url) { + server.URL(url); + shorted = false; + } + server.ContentType("text/xml"); + timeout = 30000; +} + +String XmlRpcExecute(const String& request, const char *group, const char *peeraddr); + Value XmlRpcCall::Execute() { String request = XmlHeader(); request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out)); - String response = server.Post(request).TimeoutMsecs(timeout).ExecuteRedirect(); + String response; + if(shorted) + response = XmlRpcExecute(request, "", "127.0.0.1"); + else + response = server.Post(request).TimeoutMsecs(timeout).ExecuteRedirect(); LLOG("response: " << response); if(IsNull(response)) { LLOG("ERROR: " << server.GetError()); diff --git a/uppsrc/XmlRpc/XmlRpc.h b/uppsrc/XmlRpc/XmlRpc.h index fbab55db5..416fde44b 100644 --- a/uppsrc/XmlRpc/XmlRpc.h +++ b/uppsrc/XmlRpc/XmlRpc.h @@ -124,6 +124,7 @@ INITBLOCK { Register(#x, xmlrpc##x, group); } \ void xmlrpc##x(XmlRpcData& rpc) class XmlRpcCall { + bool shorted; HttpClient server; XmlRpcData data; String method; @@ -164,7 +165,7 @@ public: String GetError() const { return error; } XmlRpcCall& TimeOut(int msec) { timeout = msec; } - XmlRpcCall(const char *url) : server(url) { server.ContentType("text/xml"); timeout = 30000; } + XmlRpcCall(const char *url); }; #endif