diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-02 22:30:27 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-02 22:30:27 +0000 |
commit | 980bcaff693a86971750d6e9ffc8ba1e561b8b3a (patch) | |
tree | d8a422e9ccd2357d6e28368447bee8cfcd26123a /src/modules/icolib | |
parent | 990f961261d92fccadb16b495171bb619c0183f0 (diff) |
the core without manual critical sections' control
git-svn-id: http://svn.miranda-ng.org/main/trunk@730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/icolib')
-rw-r--r-- | src/modules/icolib/skin2icons.cpp | 62 | ||||
-rw-r--r-- | src/modules/icolib/skin2opts.cpp | 116 |
2 files changed, 68 insertions, 110 deletions
diff --git a/src/modules/icolib/skin2icons.cpp b/src/modules/icolib/skin2icons.cpp index 7001bbae3b..6527d7a35e 100644 --- a/src/modules/icolib/skin2icons.cpp +++ b/src/modules/icolib/skin2icons.cpp @@ -503,7 +503,7 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid) bool utf = (sid->flags & SIDF_UNICODE) != 0;
bool utf_path = (sid->flags & SIDF_PATH_UNICODE) != 0;
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
IconItem* item = IcoLib_FindIcon(sid->pszName);
if (!item) {
@@ -565,7 +565,6 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid) if (item->section)
item->section->flags = sid->flags & SIDF_SORTED;
- LeaveCriticalSection(&csIconList);
return item;
}
@@ -575,9 +574,9 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid) static INT_PTR IcoLib_RemoveIcon(WPARAM, LPARAM lParam)
{
if (lParam) {
- int indx;
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
+ int indx;
if ((indx = iconList.getIndex((IconItem*)&lParam)) != -1) {
IconItem *item = iconList[ indx ];
IcoLib_FreeIcon(item);
@@ -585,7 +584,6 @@ static INT_PTR IcoLib_RemoveIcon(WPARAM, LPARAM lParam) SAFE_FREE((void**)&item);
}
- LeaveCriticalSection(&csIconList);
return (indx == -1) ? 1 : 0;
}
return 1; // Failed
@@ -678,20 +676,12 @@ HICON IconItem_GetIcon(IconItem* item, bool big) HICON IcoLib_GetIcon(const char* pszIconName, bool big)
{
- IconItem* item;
- HICON result = NULL;
-
if ( !pszIconName)
return hIconBlank;
- EnterCriticalSection(&csIconList);
-
- item = IcoLib_FindIcon(pszIconName);
- if (item) {
- result = IconItem_GetIcon(item, big);
- }
- LeaveCriticalSection(&csIconList);
- return result;
+ mir_cslock lck(csIconList);
+ IconItem* item = IcoLib_FindIcon(pszIconName);
+ return (item) ? IconItem_GetIcon(item, big) : NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -700,16 +690,11 @@ HICON IcoLib_GetIcon(const char* pszIconName, bool big) HANDLE IcoLib_GetIconHandle(const char* pszIconName)
{
- IconItem* item;
-
if ( !pszIconName)
return NULL;
- EnterCriticalSection(&csIconList);
- item = IcoLib_FindIcon(pszIconName);
- LeaveCriticalSection(&csIconList);
-
- return (HANDLE)item;
+ mir_cslock lck(csIconList);
+ return IcoLib_FindIcon(pszIconName);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -722,23 +707,12 @@ HICON IcoLib_GetIconByHandle(HANDLE hItem, bool big) if (hItem == NULL)
return NULL;
- HICON result = hIconBlank;
+ mir_cslock lck(csIconList);
IconItem* pi = (IconItem*)hItem;
+ if ( iconList.getIndex(pi) != -1)
+ return IconItem_GetIcon(pi, big);
- EnterCriticalSection(&csIconList);
-
- // we can get any junk here... but getIndex() is MUCH faster than indexOf().
- __try
- {
- if (iconList.getIndex(pi) != -1)
- result = IconItem_GetIcon(pi, big);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- }
-
- LeaveCriticalSection(&csIconList);
- return result;
+ return hIconBlank;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -748,20 +722,17 @@ HICON IcoLib_GetIconByHandle(HANDLE hItem, bool big) HANDLE IcoLib_IsManaged(HICON hIcon)
{
- IconItem* item;
-
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
bool big;
- item = IcoLib_FindHIcon(hIcon, big);
+ IconItem* item = IcoLib_FindHIcon(hIcon, big);
if (item) {
IconSourceItem* source = big && !item->cx ? item->source_big : item->source_small;
if (source->icon_ref_count == 0)
item = NULL;
}
- LeaveCriticalSection(&csIconList);
- return NULL;
+ return item;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -771,7 +742,7 @@ HANDLE IcoLib_IsManaged(HICON hIcon) static INT_PTR IcoLib_AddRef(WPARAM wParam, LPARAM)
{
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
bool big;
IconItem *item = IcoLib_FindHIcon((HICON)wParam, big);
@@ -785,7 +756,6 @@ static INT_PTR IcoLib_AddRef(WPARAM wParam, LPARAM) }
}
- LeaveCriticalSection(&csIconList);
return res;
}
diff --git a/src/modules/icolib/skin2opts.cpp b/src/modules/icolib/skin2opts.cpp index 9c6f3f2a41..97529762e3 100644 --- a/src/modules/icolib/skin2opts.cpp +++ b/src/modules/icolib/skin2opts.cpp @@ -71,10 +71,9 @@ static HICON ExtractIconFromPath(const TCHAR *path, int cxIcon, int cyIcon) int IcoLib_ReleaseIcon(HICON hIcon, char* szIconName, bool big)
{
- IconItem *item = NULL;
-
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
+ IconItem *item = NULL;
if (szIconName)
item = IcoLib_FindIcon(szIconName);
@@ -93,7 +92,6 @@ int IcoLib_ReleaseIcon(HICON hIcon, char* szIconName, bool big) }
}
- LeaveCriticalSection(&csIconList);
return res;
}
@@ -149,7 +147,7 @@ static void LoadSectionIcons(TCHAR *filename, SectionItem* sectionActive) mir_sntprintf(path, SIZEOF(path), _T("%s,"), filename);
int suffIndx = lstrlen(path);
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[ indx ];
@@ -166,9 +164,8 @@ static void LoadSectionIcons(TCHAR *filename, SectionItem* sectionActive) item->temp_file = mir_tstrdup(path);
item->temp_icon = hIcon;
item->temp_reset = FALSE;
- } }
-
- LeaveCriticalSection(&csIconList);
+ }
+ }
}
void LoadSubIcons(HWND htv, TCHAR *filename, HTREEITEM hItem)
@@ -215,13 +212,11 @@ void UndoSubItemChanges(HWND htv, HTREEITEM hItem, int cmd) TreeItem *treeItem = (TreeItem *)tvi.lParam;
if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE) {
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++)
if (iconList[ indx ]->section == sectionList[ SECTIONPARAM_INDEX(treeItem->value) ])
UndoChanges(indx, cmd);
-
- LeaveCriticalSection(&csIconList);
}
tvi.hItem = TreeView_GetChild(htv, tvi.hItem);
@@ -318,7 +313,7 @@ void DoIconsChanged(HWND hwndDlg) NotifyEventHooks(hIcons2ChangedEvent, 0, 0);
iconEventActive = 0;
- EnterCriticalSection(&csIconList); // Destroy unused icons
+ mir_cslock lck(csIconList); // Destroy unused icons
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
if (item->source_small && !item->source_small->icon_ref_count) {
@@ -330,7 +325,6 @@ void DoIconsChanged(HWND hwndDlg) IconSourceItem_ReleaseIcon(item->source_big);
}
}
- LeaveCriticalSection(&csIconList);
}
static HTREEITEM FindNamedTreeItemAt(HWND hwndTree, HTREEITEM hItem, const TCHAR *name)
@@ -665,17 +659,17 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM //
// Reset temporary data & upload sections list
//
- EnterCriticalSection(&csIconList);
{
- int indx;
- for (indx = 0; indx < iconList.getCount(); indx++) {
+ mir_cslock lck(csIconList);
+
+ for (int indx = 0; indx < iconList.getCount(); indx++) {
iconList[indx]->temp_file = NULL;
iconList[indx]->temp_icon = NULL;
iconList[indx]->temp_reset = FALSE;
}
bNeedRebuild = FALSE;
}
- LeaveCriticalSection(&csIconList);
+
//
// Setup preview listview
//
@@ -775,26 +769,25 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM LVITEM lvi = {0};
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
-
- EnterCriticalSection(&csIconList);
-
- for (int indx = 0; indx < iconList.getCount(); indx++) {
- IconItem *item = iconList[indx];
- if (item->section == sectionActive) {
- lvi.pszText = item->getDescr();
- HICON hIcon = item->temp_icon;
- if (!hIcon)
- hIcon = IconItem_GetIcon_Preview(item);
- lvi.iImage = ImageList_AddIcon(hIml, hIcon);
- lvi.lParam = indx;
- ListView_InsertItem(hPreview, &lvi);
- if (hIcon != item->temp_icon)
- SafeDestroyIcon(&hIcon);
+ {
+ mir_cslock lck(csIconList);
+
+ for (int indx = 0; indx < iconList.getCount(); indx++) {
+ IconItem *item = iconList[indx];
+ if (item->section == sectionActive) {
+ lvi.pszText = item->getDescr();
+ HICON hIcon = item->temp_icon;
+ if (!hIcon)
+ hIcon = IconItem_GetIcon_Preview(item);
+ lvi.iImage = ImageList_AddIcon(hIml, hIcon);
+ lvi.lParam = indx;
+ ListView_InsertItem(hPreview, &lvi);
+ if (hIcon != item->temp_icon)
+ SafeDestroyIcon(&hIcon);
+ }
}
}
- LeaveCriticalSection(&csIconList);
-
if (sectionActive->flags & SIDF_SORTED)
ListView_SortItems(hPreview, DoSortIconsFunc, 0);
else
@@ -816,12 +809,13 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM for (indx = 0; indx < count; indx++) {
lvi.iItem = indx;
ListView_GetItem(hPreview, &lvi);
- EnterCriticalSection(&csIconList);
- hIcon = iconList[lvi.lParam]->temp_icon;
- if ( !hIcon)
- hIcon = IconItem_GetIcon_Preview(iconList[lvi.lParam]);
- LeaveCriticalSection(&csIconList);
-
+ {
+ mir_cslock lck(csIconList);
+ hIcon = iconList[lvi.lParam]->temp_icon;
+ if ( !hIcon)
+ hIcon = IconItem_GetIcon_Preview(iconList[lvi.lParam]);
+ }
+
if (hIcon)
ImageList_ReplaceIcon(hIml, lvi.iImage, hIcon);
if (hIcon != iconList[lvi.lParam]->temp_icon) SafeDestroyIcon(&hIcon);
@@ -837,19 +831,18 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lvi.mask = LVIF_PARAM;
lvi.iItem = wParam;
ListView_GetItem(hPreview, &lvi);
+ {
+ mir_cslock lck(csIconList);
+ IconItem *item = iconList[ lvi.lParam ];
- EnterCriticalSection(&csIconList);
- IconItem *item = iconList[ lvi.lParam ];
-
- SAFE_FREE((void**)&item->temp_file);
- SafeDestroyIcon(&item->temp_icon);
-
- TCHAR *path = (TCHAR*)lParam;
- item->temp_file = mir_tstrdup(path);
- item->temp_icon = (HICON)ExtractIconFromPath(path, item->cx, item->cy);
- item->temp_reset = FALSE;
+ SAFE_FREE((void**)&item->temp_file);
+ SafeDestroyIcon(&item->temp_icon);
- LeaveCriticalSection(&csIconList);
+ TCHAR *path = (TCHAR*)lParam;
+ item->temp_file = mir_tstrdup(path);
+ item->temp_icon = (HICON)ExtractIconFromPath(path, item->cx, item->cy);
+ item->temp_reset = FALSE;
+ }
DoOptionsChanged(hwndDlg);
}
break;
@@ -927,7 +920,7 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM switch(((LPNMHDR)lParam)->code) {
case PSN_APPLY:
{
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
@@ -943,11 +936,10 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM SafeDestroyIcon(&item->temp_icon);
}
}
- LeaveCriticalSection(&csIconList);
-
- DoIconsChanged(hwndDlg);
- return TRUE;
}
+
+ DoIconsChanged(hwndDlg);
+ return TRUE;
}
break;
@@ -969,9 +961,7 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM }
}
if (bNeedRebuild) {
- EnterCriticalSection(&csIconList);
bNeedRebuild = FALSE;
- LeaveCriticalSection(&csIconList);
SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0);
}
break;
@@ -1002,9 +992,9 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM }
}
if (bNeedRebuild) {
- EnterCriticalSection(&csIconList);
- bNeedRebuild = FALSE;
- LeaveCriticalSection(&csIconList);
+ { mir_cslock lck(csIconList);
+ bNeedRebuild = FALSE;
+ }
SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0);
} }
break;
@@ -1012,9 +1002,8 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM case WM_DESTROY:
SaveCollapseState(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
DestroyWindow(dat->hwndIndex);
-
- EnterCriticalSection(&csIconList);
{
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
@@ -1022,7 +1011,6 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM SafeDestroyIcon(&item->temp_icon);
}
}
- LeaveCriticalSection(&csIconList);
SAFE_FREE((void**)&dat);
break;
|