diff --git a/ports/win32/qf_port.c b/ports/win32/qf_port.c index c4e42110..58b76baa 100644 --- a/ports/win32/qf_port.c +++ b/ports/win32/qf_port.c @@ -5,7 +5,7 @@ * @cond ****************************************************************************** * Last updated for version 6.4.0 -* Last updated on 2019-02-07 +* Last updated on 2019-02-12 * * Q u a n t u m L e a P s * ------------------------ @@ -138,12 +138,11 @@ void QF_setTickRate(uint32_t ticksPerSec, int_t tickPrio) { } /****************************************************************************/ void QF_setWin32Prio(QActive *act, int_t win32Prio) { - if (act->thread == (HANDLE)0) { /* thread not created yet? */ - act->osObject = (void *)win32Prio; /* store the priority for later */ - } - else { - SetThreadPriority(act->thread, win32Prio); - } + HANDLE win32thread = (HANDLE)act->thread; + + /* thread must be already created, see QActive_start_() */ + Q_REQUIRE_ID(700, win32thread != (HANDLE)0); + SetThreadPriority(win32thread, win32Prio); } /* QActive functions =======================================================*/ @@ -152,23 +151,15 @@ void QActive_start_(QActive * const me, uint_fast8_t prio, void *stkSto, uint_fast16_t stkSize, QEvt const *ie) { - int win32Prio; - - Q_REQUIRE_ID(700, ((uint_fast8_t)0 < prio) /* priority must be in range */ + Q_REQUIRE_ID(800, ((uint_fast8_t)0 < prio) /* priority must be in range */ && (prio <= (uint_fast8_t)QF_MAX_ACTIVE) && (stkSto == (void *)0)); /* statck storage must NOT... * ... be provided */ - me->prio = prio; /* set QF priority of this AO before adding it to QF */ QF_add_(me); /* make QF aware of this active object */ QEQueue_init(&me->eQueue, qSto, qLen); - /* save osObject as integer, in case it contains the Win32 priority */ - win32Prio = (me->osObject != (void *)0) - ? (int)me->osObject - : THREAD_PRIORITY_NORMAL; - /* create the Win32 "event" to throttle the AO's event queue */ me->osObject = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -184,12 +175,7 @@ void QActive_start_(QActive * const me, uint_fast8_t prio, * The thread is created with THREAD_PRIORITY_NORMAL */ me->thread = CreateThread(NULL, stkSize, &ao_thread, me, 0, NULL); - Q_ASSERT_ID(730, me->thread != (HANDLE)0); /* must succeed */ - - /* was the thread priority provided? */ - if (win32Prio != 0) { - SetThreadPriority(me->thread, win32Prio); - } + Q_ENSURE_ID(830, me->thread != (HANDLE)0); /* must succeed */ } /****************************************************************************/ diff --git a/ports/win32/qf_port.h b/ports/win32/qf_port.h index 30c55d46..6fdd64f4 100644 --- a/ports/win32/qf_port.h +++ b/ports/win32/qf_port.h @@ -4,14 +4,14 @@ * @ingroup ports * @cond ****************************************************************************** -* Last Updated for Version: 6.3.7 -* Date of the Last Update: 2018-11-17 +* Last Updated for Version: 6.4.0 +* Date of the Last Update: 2019-02-12 * * Q u a n t u m L e a P s * ------------------------ * Modern Embedded Software * -* Copyright (C) 2005-2018 Quantum Leaps, LLC. All rights reserved. +* Copyright (C) 2005-2019 Quantum Leaps. All rights reserved. * * This program is open source software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -74,8 +74,9 @@ void QF_enterCriticalSection_(void); void QF_leaveCriticalSection_(void); -/* set Win32 thread priority; -* can be called either before or after QACTIVE_START(). +/* set Win32 thread priority for an active object; +* see: Microsoft documentation for SetThreadPriority() +* NOTE: must be called *after* QACTIVE_START() */ void QF_setWin32Prio(QActive *act, int_t win32Prio); @@ -103,6 +104,7 @@ int QF_consoleWaitForKey(void); #ifdef _MSC_VER #if (_MSC_VER < 1900) /* before Visual Studio 2015 */ + #define snprintf _snprintf #endif @@ -115,7 +117,7 @@ int QF_consoleWaitForKey(void); #define FOPEN_S(fp_, fName_, mode_) \ if (fopen_s(&fp_, fName_, mode_) != 0) { \ fp_ = (FILE *)0; \ - } else (void)0 + } else ((void)0) #define CTIME_S(buf_, len_, time_) \ ctime_s((char *)buf_, len_, time_)