Skip to content

Commit

Permalink
Work on Execution (#375)
Browse files Browse the repository at this point in the history
The CLR Interpreter runs on it's own OS thread (then jumping from one nanoFramework thread to the next) it leaves no time slot for other OS threads to execute on OSes that relly on cooperative execution (menaning that a thread has to relinquish execution control to the OS so other threads can run). Because of this, on nF thread switching, there is a call to NANOCLR_RELINQUISHEXECUTIONCONTROL to allow this to happen on OSes that require that. ChibiOS is one of those when it's running on cooperative mode.

Signed-off-by: José Simões <jose.simoes@eclo.solutions>
  • Loading branch information
josesimoes authored Jun 30, 2017
1 parent 6d55e16 commit 675e79e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,9 @@ HRESULT CLR_RT_ExecutionEngine::ScheduleThreads( int maxContextSwitch )
UpdateTime();

(void)ProcessTimer();

// relinquish execution to OS
NANOCLR_RELINQUISHEXECUTIONCONTROL();
}

NANOCLR_SET_AND_LEAVE(CLR_S_QUANTUM_EXPIRED);
Expand Down
4 changes: 4 additions & 0 deletions src/HAL/Include/nanoHAL_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ typedef struct HAL_SYSTEM_CONFIG

extern HAL_SYSTEM_CONFIG HalSystemConfig;

// declaration of call to function that relinquishes execution control to OS
// this has to be provided at target level
void NANOCLR_RELINQUISHEXECUTIONCONTROL();

#endif // _NANOHAL_V2_H_
3 changes: 3 additions & 0 deletions targets/CMSIS-OS/ChibiOS/Include/targetHAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <target_board.h>

// call to CMSIS osDelay to allow other threads to run
#define NANOCLR_RELINQUISHEXECUTIONCONTROL() osDelay(1);

#if !defined(BUILD_RTM)

// FIXME IMPLEMENT
Expand Down
3 changes: 3 additions & 0 deletions targets/os/win32/Include/targetHAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// #include <nanoHAL_Time.h>
// #include <nanoHAL_Power.h>

// empty implementation for WIN32
#define NANOCLR_RELINQUISHEXECUTIONCONTROL()

#if defined(_WIN32)
#define NANOCLR_STOP() ::DebugBreak()
#pragma warning( error : 4706 ) // error C4706: assignment within conditional expression
Expand Down

0 comments on commit 675e79e

Please sign in to comment.