@@ -43,56 +43,52 @@ DllExport void* MDD_ProcessPriorityConstructor(void) {
43
43
DllExport void MDD_ProcessPriorityDestructor (void * prioObj ) {
44
44
ProcPrio * prio = (ProcPrio * ) prioObj ;
45
45
if (prio ) {
46
- BOOL ret = 0 ;
47
- ModelicaFormatMessage ("setting...\n" );
48
- switch (prio -> lastPrio ) {
49
- case IDLE_PRIORITY_CLASS :
50
- ret = SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS );
51
- if (ret ) {
52
- ModelicaFormatMessage ("ProcessPriority set to idle.\n" );
53
- }
54
- break ;
55
-
56
- case BELOW_NORMAL_PRIORITY_CLASS :
57
- ret = SetPriorityClass (GetCurrentProcess (), BELOW_NORMAL_PRIORITY_CLASS );
58
- if (ret ) {
59
- ModelicaFormatMessage ("ProcessPriority set to below normal.\n" );
60
- }
61
- break ;
62
-
63
- case NORMAL_PRIORITY_CLASS :
64
- ret = SetPriorityClass (GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
65
- if (ret ) {
66
- ModelicaFormatMessage ("ProcessPriority set to normal.\n" );
67
- }
68
- break ;
69
-
70
- case HIGH_PRIORITY_CLASS :
71
- ret = SetPriorityClass (GetCurrentProcess (), HIGH_PRIORITY_CLASS );
72
- if (ret ) {
73
- ModelicaFormatMessage ("ProcessPriority set to high.\n" );
74
- }
75
- break ;
76
-
77
- case REALTIME_PRIORITY_CLASS :
78
- ret = SetPriorityClass (GetCurrentProcess (), REALTIME_PRIORITY_CLASS );
79
- if (ret ) {
80
- ModelicaFormatMessage ("ProcessPriority set to realtime.\n" );
81
- }
82
- break ;
46
+ DWORD currentPrio = GetPriorityClass (GetCurrentProcess ());
47
+ if (currentPrio != prio -> lastPrio ) {
48
+ BOOL ret = 1 ;
49
+ ModelicaFormatMessage ("setting...\n" );
50
+ switch (prio -> lastPrio ) {
51
+ case IDLE_PRIORITY_CLASS :
52
+ ret = SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS );
53
+ if (ret ) {
54
+ ModelicaFormatMessage ("ProcessPriority set to idle.\n" );
55
+ }
56
+ break ;
57
+
58
+ case BELOW_NORMAL_PRIORITY_CLASS :
59
+ ret = SetPriorityClass (GetCurrentProcess (), BELOW_NORMAL_PRIORITY_CLASS );
60
+ if (ret ) {
61
+ ModelicaFormatMessage ("ProcessPriority set to below normal.\n" );
62
+ }
63
+ break ;
64
+
65
+ case HIGH_PRIORITY_CLASS :
66
+ ret = SetPriorityClass (GetCurrentProcess (), HIGH_PRIORITY_CLASS );
67
+ if (ret ) {
68
+ ModelicaFormatMessage ("ProcessPriority set to high.\n" );
69
+ }
70
+ break ;
71
+
72
+ case REALTIME_PRIORITY_CLASS :
73
+ ret = SetPriorityClass (GetCurrentProcess (), REALTIME_PRIORITY_CLASS );
74
+ if (ret ) {
75
+ ModelicaFormatMessage ("ProcessPriority set to realtime.\n" );
76
+ }
77
+ break ;
78
+
79
+ default :
80
+ ret = SetPriorityClass (GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
81
+ if (ret ) {
82
+ ModelicaFormatMessage ("ProcessPriority set to normal.\n" );
83
+ }
84
+ break ;
85
+ }
83
86
84
- default :
85
- ret = SetPriorityClass ( GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
86
- if (ret ) {
87
- ModelicaFormatMessage ("ProcessPriority set to normal. \n" );
87
+ if ( ret == 0 ) {
88
+ DWORD dw = GetLastError ( );
89
+ if (dw ) {
90
+ ModelicaFormatMessage ("LastError: %d \n" , dw );
88
91
}
89
- break ;
90
- }
91
-
92
- if (ret == 0 ) {
93
- DWORD dw = GetLastError ();
94
- if (dw ) {
95
- ModelicaFormatMessage ("LastError: %d\n" , dw );
96
92
}
97
93
}
98
94
@@ -101,48 +97,56 @@ DllExport void MDD_ProcessPriorityDestructor(void* prioObj) {
101
97
}
102
98
103
99
DllExport void MDD_setPriority (void * dummyPrioObj , int priority ) {
104
- BOOL ret = 0 ;
105
- ModelicaFormatMessage ( "setting...\n" );
100
+ BOOL ret = 1 ;
101
+ DWORD currentPrio = GetPriorityClass ( GetCurrentProcess () );
106
102
switch (priority ) {
107
103
case -2 :
108
- ret = SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS );
109
- if (ret ) {
110
- ModelicaFormatMessage ("ProcessPriority set to idle.\n" );
104
+ if (currentPrio != IDLE_PRIORITY_CLASS ) {
105
+ ModelicaFormatMessage ("setting...\n" );
106
+ ret = SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS );
107
+ if (ret ) {
108
+ ModelicaFormatMessage ("ProcessPriority set to idle.\n" );
109
+ }
111
110
}
112
111
break ;
113
112
114
113
case -1 :
115
- ret = SetPriorityClass (GetCurrentProcess (), BELOW_NORMAL_PRIORITY_CLASS );
116
- if (ret ) {
117
- ModelicaFormatMessage ("ProcessPriority set to below normal.\n" );
118
- }
119
- break ;
120
-
121
- case 0 :
122
- ret = SetPriorityClass (GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
123
- if (ret ) {
124
- ModelicaFormatMessage ("ProcessPriority set to normal.\n" );
114
+ if (currentPrio != BELOW_NORMAL_PRIORITY_CLASS ) {
115
+ ModelicaFormatMessage ("setting...\n" );
116
+ ret = SetPriorityClass (GetCurrentProcess (), BELOW_NORMAL_PRIORITY_CLASS );
117
+ if (ret ) {
118
+ ModelicaFormatMessage ("ProcessPriority set to below normal.\n" );
119
+ }
125
120
}
126
121
break ;
127
122
128
123
case 1 :
129
- ret = SetPriorityClass (GetCurrentProcess (), HIGH_PRIORITY_CLASS );
130
- if (ret ) {
131
- ModelicaFormatMessage ("ProcessPriority set to high.\n" );
124
+ if (currentPrio != HIGH_PRIORITY_CLASS ) {
125
+ ModelicaFormatMessage ("setting...\n" );
126
+ ret = SetPriorityClass (GetCurrentProcess (), HIGH_PRIORITY_CLASS );
127
+ if (ret ) {
128
+ ModelicaFormatMessage ("ProcessPriority set to high.\n" );
129
+ }
132
130
}
133
131
break ;
134
132
135
133
case 2 :
136
- ret = SetPriorityClass (GetCurrentProcess (), REALTIME_PRIORITY_CLASS );
137
- if (ret ) {
138
- ModelicaFormatMessage ("ProcessPriority set to realtime.\n" );
134
+ if (currentPrio != REALTIME_PRIORITY_CLASS ) {
135
+ ModelicaFormatMessage ("setting...\n" );
136
+ ret = SetPriorityClass (GetCurrentProcess (), REALTIME_PRIORITY_CLASS );
137
+ if (ret ) {
138
+ ModelicaFormatMessage ("ProcessPriority set to realtime.\n" );
139
+ }
139
140
}
140
141
break ;
141
142
142
143
default :
143
- ret = SetPriorityClass (GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
144
- if (ret ) {
145
- ModelicaFormatMessage ("ProcessPriority set to normal.\n" );
144
+ if (currentPrio != NORMAL_PRIORITY_CLASS ) {
145
+ ModelicaFormatMessage ("setting...\n" );
146
+ ret = SetPriorityClass (GetCurrentProcess (), NORMAL_PRIORITY_CLASS );
147
+ if (ret ) {
148
+ ModelicaFormatMessage ("ProcessPriority set to normal.\n" );
149
+ }
146
150
}
147
151
break ;
148
152
}
@@ -330,6 +334,7 @@ DllExport void MDD_ProcessPriorityDestructor(void* prioObj) {
330
334
*
331
335
* Function maps directly on windows API. For linux a mapping was chosen that seemed
332
336
* to be reasonable.
337
+ * @param[in] Process priority external object (dummy)
333
338
* @param[in] priority range: (-2: idle, -1: below normal, 0: normal, 1: high, 2: realtime)
334
339
*/
335
340
void MDD_setPriority (void * dummyPrioObj , int priority ) {
0 commit comments