2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "JackMMCSS.h"
21 #include "JackError.h"
28 avSetMmThreadCharacteristics
JackMMCSS::ffMMCSSFun1
= NULL
;
29 avSetMmThreadPriority
JackMMCSS::ffMMCSSFun2
= NULL
;
30 avRevertMmThreadCharacteristics
JackMMCSS::ffMMCSSFun3
= NULL
;
31 JACK_HANDLE
JackMMCSS::fAvrtDll
;
33 std::map
<jack_native_thread_t
, HANDLE
> JackMMCSS::fHandleTable
;
35 JackMMCSS::JackMMCSS()
37 fAvrtDll
= LoadJackModule("avrt.dll");
39 if (fAvrtDll
!= NULL
) {
40 ffMMCSSFun1
= (avSetMmThreadCharacteristics
)GetJackProc(fAvrtDll
, "AvSetMmThreadCharacteristicsA");
41 ffMMCSSFun2
= (avSetMmThreadPriority
)GetJackProc(fAvrtDll
, "AvSetMmThreadPriority");
42 ffMMCSSFun3
= (avRevertMmThreadCharacteristics
)GetJackProc(fAvrtDll
, "AvRevertMmThreadCharacteristics");
46 JackMMCSS::~JackMMCSS()
49 int JackMMCSS::MMCSSAcquireRealTime(jack_native_thread_t thread
)
51 if (fHandleTable
.find(thread
) != fHandleTable
.end()) {
57 HANDLE task
= ffMMCSSFun1("Pro Audio", &dummy
);
59 jack_error("AvSetMmThreadCharacteristics error : %d", GetLastError());
60 } else if (ffMMCSSFun2(task
, AVRT_PRIORITY_CRITICAL
)) {
61 fHandleTable
[thread
] = task
;
62 jack_log("AvSetMmThreadPriority success");
65 jack_error("AvSetMmThreadPriority error : %d", GetLastError());
72 int JackMMCSS::MMCSSDropRealTime(jack_native_thread_t thread
)
74 if (fHandleTable
.find(thread
) != fHandleTable
.end()) {
75 HANDLE task
= fHandleTable
[thread
];
76 if (ffMMCSSFun3(task
) == 0) {
77 jack_error("AvRevertMmThreadCharacteristics error : %d", GetLastError());
79 jack_log("AvRevertMmThreadCharacteristics success");