summaryrefslogtreecommitdiff
path: root/plugins/Alarms/src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-04-30 19:44:39 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-04-30 19:44:39 +0000
commit157aa0dfbddd63f75f7eb7c1a8162df960543a64 (patch)
treed4f3efc24f1ee672ed774067ad6044226924da0c /plugins/Alarms/src
parent75cb4a995e44e1ebd1a009f344ab7df00c5c65ba (diff)
minus critical section
git-svn-id: http://svn.miranda-ng.org/main/trunk@13315 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Alarms/src')
-rw-r--r--plugins/Alarms/src/alarmlist.cpp53
-rw-r--r--plugins/Alarms/src/frame.cpp14
2 files changed, 18 insertions, 49 deletions
diff --git a/plugins/Alarms/src/alarmlist.cpp b/plugins/Alarms/src/alarmlist.cpp
index 41ae865577..cd60fe2a50 100644
--- a/plugins/Alarms/src/alarmlist.cpp
+++ b/plugins/Alarms/src/alarmlist.cpp
@@ -2,7 +2,7 @@
#include "alarmlist.h"
AlarmList alarms;
-CRITICAL_SECTION alarm_cs;
+mir_cs alarm_cs;
unsigned short next_alarm_id = 1; // 0 is used for invalid id
@@ -41,9 +41,8 @@ void copy_alarm_data(ALARM *dest, ALARM *src) {
}
void GetPluginTime(SYSTEMTIME *t) {
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
*t = last_check;
- LeaveCriticalSection(&alarm_cs);
}
int MinutesInFuture(SYSTEMTIME time, Occurrence occ) {
@@ -184,7 +183,7 @@ void LoadAlarms() {
SYSTEMTIME now;
GetLocalTime(&now);
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
alarms.clear();
for(int i = 0; i < num_alarms; i++) {
@@ -279,14 +278,13 @@ void LoadAlarms() {
}
free_alarm_data(&alarm);
}
- LeaveCriticalSection(&alarm_cs);
}
void SaveAlarms() {
int index = 0;
char buff[256];
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
ALARM *i;
for(alarms.reset(); i = alarms.current(); alarms.next(), index++) {
@@ -348,56 +346,47 @@ void SaveAlarms() {
db_set_dw(0, MODULE, buff, i->flags);
}
db_set_w(0, MODULE, "Count", index);
-
- LeaveCriticalSection(&alarm_cs);
}
void copy_list(AlarmList &copy) {
copy.clear();
ALARM *i;
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
for(alarms.reset(); i = alarms.current(); alarms.next())
copy.push_back(i);
-
- LeaveCriticalSection(&alarm_cs);
}
void copy_list(AlarmList &copy, SYSTEMTIME &start, SYSTEMTIME &end) {
copy.clear();
ALARM *i;
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
for(alarms.reset(); i = alarms.current(); alarms.next())
if (IsBetween(i->time, start, end))
copy.push_back(i);
-
- LeaveCriticalSection(&alarm_cs);
}
void set_list(AlarmList &copy) {
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
alarms.clear();
ALARM *i;
for(copy.reset(); i = copy.current(); copy.next())
alarms.push_back(i);
- LeaveCriticalSection(&alarm_cs);
-
SaveAlarms();
}
void append_to_list(ALARM *alarm) {
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
if (!alarm->id)
alarm->id = next_alarm_id++;
alarms.push_back(alarm);
- LeaveCriticalSection(&alarm_cs);
SaveAlarms();
}
void alter_alarm_list(ALARM *alarm) {
bool found = false;
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
if (alarm->id != 0) {
ALARM *i;
for(alarms.reset(); i = alarms.current(); alarms.next()) {
@@ -414,13 +403,11 @@ void alter_alarm_list(ALARM *alarm) {
alarms.push_back(alarm);
}
- LeaveCriticalSection(&alarm_cs);
-
SaveAlarms();
}
void remove(unsigned short alarm_id) {
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
ALARM *i;
for(alarms.reset(); i = alarms.current(); alarms.next()) {
if (i->id == alarm_id) {
@@ -428,13 +415,12 @@ void remove(unsigned short alarm_id) {
break;
}
}
- LeaveCriticalSection(&alarm_cs);
SaveAlarms();
}
void suspend(unsigned short alarm_id) {
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
ALARM *i;
for(alarms.reset(); i = alarms.current(); alarms.next()) {
if (i->id == alarm_id && i->occurrence != OC_ONCE) {
@@ -442,7 +428,6 @@ void suspend(unsigned short alarm_id) {
break;
}
}
- LeaveCriticalSection(&alarm_cs);
SaveAlarms();
}
@@ -592,7 +577,7 @@ void CheckAlarms() {
// put triggered alarms in another list - so we don't keep the critical section locked for longer than necessary
AlarmList triggered_list, remove_list;
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
ALARM *i;
for(alarms.reset(); i = alarms.current(); alarms.next()) {
if (!UpdateAlarm(i->time, i->occurrence)) {
@@ -624,7 +609,6 @@ void CheckAlarms() {
WriteLastCheckTime();
startup = false;
- LeaveCriticalSection(&alarm_cs);
for(triggered_list.reset(); i = triggered_list.current(); triggered_list.next())
DoAlarm(i);
@@ -667,8 +651,6 @@ int IdleChanged(WPARAM, LPARAM lParam)
void InitList()
{
- InitializeCriticalSection(&alarm_cs);
-
SkinAddNewSoundEx("Triggered1", LPGEN("Alarms"), LPGEN("Alert 1"));
SkinAddNewSoundEx("Triggered2", LPGEN("Alarms"), LPGEN("Alert 2"));
SkinAddNewSoundEx("Triggered3", LPGEN("Alarms"), LPGEN("Alert 3"));
@@ -703,19 +685,12 @@ void DeinitList() {
DeinitAlarmWin();
// i don't think this should be necessary, but...
- EnterCriticalSection(&alarm_cs);
+ mir_cslock lck(alarm_cs);
KillTimer(0, timer_id);
- LeaveCriticalSection(&alarm_cs);
DestroyHookableEvent(hAlarmTriggeredEvent);
DestroyServiceFunction(hAddAlarmService);
- SaveAlarms(); // we may have erased some 'cause they were once-offs that were triggered
-
- //WriteLastCheckTime(); // moved to the CheckAlarms function - for virt db and general crash problems
-
- // delete this after save alarms above
- DeleteCriticalSection(&alarm_cs);
-
+ SaveAlarms(); // we may have erased some 'cause they were once-offs that were triggeredf
}
diff --git a/plugins/Alarms/src/frame.cpp b/plugins/Alarms/src/frame.cpp
index 794d31aa58..a24f04d765 100644
--- a/plugins/Alarms/src/frame.cpp
+++ b/plugins/Alarms/src/frame.cpp
@@ -16,7 +16,7 @@ HBRUSH bk_brush = 0;
#define CLUIFrameTitleBarClassName "CLUIFrameTitleBar"
AlarmList alarm_list;
-CRITICAL_SECTION list_cs;
+mir_cs list_cs;
HGENMENU hMenuShowReminders = 0;
@@ -117,10 +117,9 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
dis = (DRAWITEMSTRUCT *)lParam;
if (dis->itemID != (DWORD)-1) {
ALARM alarm = {0};
- EnterCriticalSection(&list_cs);
+ mir_cslock lck(list_cs);
ALARM &list_alarm = alarm_list.at(dis->itemData);
copy_alarm_data(&alarm, &list_alarm);
- LeaveCriticalSection(&list_cs);
RECT r;
GetClientRect(hwnd, &r);
@@ -296,7 +295,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
SendMessage(hwnd_list, WM_SETREDRAW, FALSE, 0);
- EnterCriticalSection(&list_cs);
+ mir_cslock lck(list_cs);
SendMessage(hwnd_list, LB_RESETCONTENT, 0, 0);
copy_list(alarm_list, t1, t2);
alarm_list.sort();
@@ -307,7 +306,6 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
continue;
SendMessage(hwnd_list, LB_ADDSTRING, 0, (LPARAM)index);
}
- LeaveCriticalSection(&list_cs);
SendMessage(hwnd, WMU_SIZE_LIST, 0, 0);
SendMessage(hwnd_list, WM_SETREDRAW, TRUE, 0);
@@ -350,7 +348,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
GetCursorPos(&pt);
ScreenToClient(hwnd_list, &pt);
- EnterCriticalSection(&list_cs);
+ mir_cslock lck(list_cs);
DWORD item = SendMessage(hwnd_list, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
HMENU menu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1)), submenu = GetSubMenu(menu, 0);
@@ -373,7 +371,6 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
EnableMenuItem(submenu, ID_REMINDERFRAMECONTEXT_EDIT, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(submenu, ID_REMINDERFRAMECONTEXT_DELETE, MF_BYCOMMAND | MF_GRAYED);
}
- LeaveCriticalSection(&list_cs);
//ClientToScreen(hwnd_list, &pt);
GetCursorPos(&pt);
@@ -629,7 +626,6 @@ void RefreshReminderFrame() {
void InitFrames()
{
- InitializeCriticalSection(&list_cs);
CreateFrame();
}
@@ -642,7 +638,5 @@ void DeinitFrames()
if (hwnd_frame) DestroyWindow(hwnd_frame);
DeleteObject(bk_brush);
-
- DeleteCriticalSection(&list_cs);
}