diff options
author | George Hazan <george.hazan@gmail.com> | 2013-08-06 08:00:37 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-08-06 08:00:37 +0000 |
commit | 7e0fe901cf2f2334c59eafffcdc85de3a02386ae (patch) | |
tree | 3638d6cd148c0f5db75e5335f9b48bd2010e96a8 /plugins/Clist_modern | |
parent | ca2a7e0009653c5f4726b4ec242297b1dbe57119 (diff) |
strange handmade zoo exterminated
git-svn-id: http://svn.miranda-ng.org/main/trunk@5596 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Clist_modern')
-rw-r--r-- | plugins/Clist_modern/src/modern_awaymsg.cpp | 83 |
1 files changed, 22 insertions, 61 deletions
diff --git a/plugins/Clist_modern/src/modern_awaymsg.cpp b/plugins/Clist_modern/src/modern_awaymsg.cpp index 09506e02cc..820572f4d9 100644 --- a/plugins/Clist_modern/src/modern_awaymsg.cpp +++ b/plugins/Clist_modern/src/modern_awaymsg.cpp @@ -32,24 +32,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "hdr/modern_commonheaders.h"
#include "hdr/modern_awaymsg.h"
-#include "newpluginapi.h"
#include "hdr/modern_sync.h"
#define AMASKPERIOD 3000
-#define amlock EnterCriticalSection(&amLockChain)
-#define amunlock LeaveCriticalSection(&amLockChain)
-typedef struct _tag_amChainItem {
- HANDLE hContact;
- _tag_amChainItem *Next;
-} AMCHAINITEM;
-
-static AMCHAINITEM * amFirstChainItem = NULL;
-static AMCHAINITEM * amLastChainItem = NULL;
-static CRITICAL_SECTION amLockChain;
-static HANDLE hamProcessEvent = NULL;
-static DWORD amRequestTick = 0;
+static CRITICAL_SECTION amCS;
+static LIST<void> amItems(10, PtrKeySortT);
+static HANDLE hamProcessEvent = NULL;
+static DWORD amRequestTick = 0;
static int amAddHandleToChain(HANDLE hContact);
static HANDLE amGetCurrentChain();
@@ -59,56 +50,27 @@ static HANDLE amGetCurrentChain(); */
static int amAddHandleToChain(HANDLE hContact)
{
- AMCHAINITEM * workChain;
- amlock;
- {
- //check that handle is present
- AMCHAINITEM * wChain;
- wChain = amFirstChainItem;
- if (wChain)
- do {
- if (wChain->hContact == hContact)
- {
- amunlock;
- return 0;
- }
- } while(wChain = (AMCHAINITEM *)wChain->Next);
- }
- if ( !amFirstChainItem)
- {
- amFirstChainItem = (AMCHAINITEM*)malloc(sizeof(AMCHAINITEM));
- workChain = amFirstChainItem;
- }
- else
- {
- amLastChainItem->Next = (AMCHAINITEM*)malloc(sizeof(AMCHAINITEM));
- workChain = (AMCHAINITEM *)amLastChainItem->Next;
- }
- amLastChainItem = workChain;
- workChain->Next = NULL;
- workChain->hContact = hContact;
- amunlock;
+ mir_cslockfull lck(amCS);
+ if (amItems.find(hContact) != NULL)
+ return 0;
+
+ amItems.insert(hContact);
+ lck.unlock();
SetEvent(hamProcessEvent);
return 1;
}
-
/*
* Gets handle from queue for request
*/
static HANDLE amGetCurrentChain()
{
- AMCHAINITEM * workChain;
- HANDLE res = NULL;
- amlock;
- if (amFirstChainItem)
- {
- res = amFirstChainItem->hContact;
- workChain = amFirstChainItem->Next;
- free(amFirstChainItem);
- amFirstChainItem = (AMCHAINITEM *)workChain;
- }
- amunlock;
+ mir_cslock lck(amCS);
+ if (amItems.getCount() == 0)
+ return NULL;
+
+ HANDLE res = amItems[0];
+ amItems.remove(0);
return res;
}
@@ -186,19 +148,18 @@ BOOL amWakeThread() */
void amRequestAwayMsg(HANDLE hContact)
{
- char *szProto;
if ( !g_CluiData.bInternalAwayMsgDiscovery || !hContact)
return;
+
//Do not re-ask for chat rooms
- szProto = GetContactProto(hContact);
- if (szProto == NULL || db_get_b(hContact, szProto, "ChatRoom", 0) != 0)
- return;
- amAddHandleToChain(hContact);
+ char *szProto = GetContactProto(hContact);
+ if (szProto != NULL && !db_get_b(hContact, szProto, "ChatRoom", 0))
+ amAddHandleToChain(hContact);
}
void InitAwayMsgModule()
{
- InitializeCriticalSection(&amLockChain);
+ InitializeCriticalSection(&amCS);
hamProcessEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
g_hAwayMsgThread = mir_forkthread(amThreadProc, 0);
}
@@ -211,5 +172,5 @@ void UninitAwayMsgModule() SleepEx(50, TRUE);
CloseHandle(hamProcessEvent);
- DeleteCriticalSection(&amLockChain);
+ DeleteCriticalSection(&amCS);
}
|