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
This commit is contained in:
cxl 2010-03-09 18:57:53 +00:00
parent 50e36e842e
commit fa3441cfdf
5 changed files with 59 additions and 62 deletions

View file

@ -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() {

View file

@ -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<Image> 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<Image> 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);
}
}
}

View file

@ -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); }

View file

@ -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());

View file

@ -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