summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2008-05-20 23:53:15 +0000
committerpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2008-05-20 23:53:15 +0000
commit9c700c5876acb50bbaf910049f6a9535bb6327f4 (patch)
tree69e5e8df88b4356a5413bd60d9735c1105327b7b
parent043247600e4f3363887003433baffc36d832478a (diff)
Added some new methods to Buffer and ContactAsyncQueue
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@107 c086bb3d-8645-0410-b8da-73a8550f86e7
-rw-r--r--Plugins/utils/ContactAsyncQueue.cpp17
-rw-r--r--Plugins/utils/ContactAsyncQueue.h2
-rw-r--r--Plugins/utils/mir_buffer.h40
3 files changed, 55 insertions, 4 deletions
diff --git a/Plugins/utils/ContactAsyncQueue.cpp b/Plugins/utils/ContactAsyncQueue.cpp
index 7be4cfe..ca6bf83 100644
--- a/Plugins/utils/ContactAsyncQueue.cpp
+++ b/Plugins/utils/ContactAsyncQueue.cpp
@@ -48,12 +48,11 @@ ContactAsyncQueue::ContactAsyncQueue(pfContactAsyncQueueCallback fContactAsyncQu
ContactAsyncQueue::~ContactAsyncQueue()
{
- if (finished == 0)
- finished = 1;
- SetEvent(hEvent);
+ Finish();
+
int count = 0;
while(finished != 2 && ++count < 50)
- Sleep(10);
+ Sleep(30);
for (int i = 0; i < queue.getCount(); i++)
if (queue[i] != NULL)
@@ -62,6 +61,13 @@ ContactAsyncQueue::~ContactAsyncQueue()
DeleteCriticalSection(&cs);
}
+void ContactAsyncQueue::Finish()
+{
+ if (finished == 0)
+ finished = 1;
+ SetEvent(hEvent);
+}
+
void ContactAsyncQueue::Lock()
{
EnterCriticalSection(&cs);
@@ -170,6 +176,9 @@ void ContactAsyncQueue::Thread()
{
ResetEvent(hEvent);
+ if (finished)
+ break;
+
Lock();
if (queue.getCount() <= 0)
diff --git a/Plugins/utils/ContactAsyncQueue.h b/Plugins/utils/ContactAsyncQueue.h
index a19ba04..fe1032f 100644
--- a/Plugins/utils/ContactAsyncQueue.h
+++ b/Plugins/utils/ContactAsyncQueue.h
@@ -48,6 +48,8 @@ public:
ContactAsyncQueue(pfContactAsyncQueueCallback fContactAsyncQueueCallback, int initialSize = 10);
~ContactAsyncQueue();
+ void Finish();
+
inline int Size() const { return queue.getCount(); }
inline int Remove(int idx) { mir_free(queue[idx]); return queue.remove(idx); }
inline QueueItem* Get(int idx) const { return queue[idx]; }
diff --git a/Plugins/utils/mir_buffer.h b/Plugins/utils/mir_buffer.h
index 51398bd..4daf01e 100644
--- a/Plugins/utils/mir_buffer.h
+++ b/Plugins/utils/mir_buffer.h
@@ -174,6 +174,17 @@ class Buffer
len++;
}
+ void appendn(size_t n, T app)
+ {
+ alloc(len + n);
+
+ for(; n > 0; n--)
+ {
+ str[len] = app;
+ len++;
+ }
+ }
+
void append(const char *app, size_t appLen = -1)
{
if (appLen == -1)
@@ -198,6 +209,28 @@ class Buffer
len += appLen;
}
+ void append(const Buffer<char> &app)
+ {
+ size_t appLen = app.len;
+
+ size_t total = len + appLen + 1;
+ alloc(total);
+
+ __bcopy(&str[len], app.str, appLen);
+ len += appLen;
+ }
+
+ void append(const Buffer<WCHAR> &app)
+ {
+ size_t appLen = app.len;
+
+ size_t total = len + appLen + 1;
+ alloc(total);
+
+ __bcopy(&str[len], app.str , appLen);
+ len += appLen;
+ }
+
void appendPrintf(const T *app, ...)
{
size_t total = len + 512;
@@ -256,6 +289,13 @@ class Buffer
len += appLen - oldLen;
}
+ void replaceAll(T find, T replace)
+ {
+ for(size_t i = 0; i < len; i++)
+ if (str[len] == find)
+ str[len] = replace;
+ }
+
void translate()
{
if (str == NULL || len == 0)