在单线程环境异步调用 - 在Windows上安装定时器/时钟ISR [英] Install timer/clock ISR on Windows - Asynchronous call in a single threaded environment

查看:213
本文介绍了在单线程环境异步调用 - 在Windows上安装定时器/时钟ISR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我炼制一些code模拟其在x86 Windows系统中的场景切换调度。该程序编译在Windows XP(编辑:可能不是Windows 7中),与一些古老的用Borland C编译器,被移植到被MSVC编译

I'm refining some code which simulated a context-switching scheduler on x86 Windows systems. The program compiles on Windows XP ( probably not Windows 7) with some ancient Borland C compiler, and is being ported to being MSVC compilable.

在一个点上,code安装通过这些功能不可用在中断服务程序 DOS.H

At one point, the code installs ISRs through these unavailable functions in dos.h:

void (*)() getvect(int)
void setvect(int, void (*)());

具体来说,code安装一个(循环)定时器中断的ISR。电话是:

Specifically, the code installs an ISR for a (cyclic) timer interrupt. The calls are:

tick_isr_old = getvect(0x08);
setvect(0xF2, tick_isr_old);
setvect(0x08, (void interrupt (*)(void)) tick_isr);
setvect(0xF1, (void interrupt (*)(void)) context_switch_isr);

有没有人有任何想法将设置这些中断服务程序的合理方法(可能使用Windows API?)。更糟糕的是,该功能是用汇编语言实现的(他们需要执行毕竟上下文切换...)。是否有至少其中断向量整数常数(0×08,0xF2,的0xf1)指任何文档?谷歌并没有真正拿出的东西,我可以一起工作。

Does anyone have any idea what would be a reasonable way to set those ISRs (with the Windows API maybe?). To make things worse, the functions are implemented in assembly language (they need to perform a context switch after all...). Is there at least any documentation which interrupt vectors the integer constants (0x08, 0xF2, 0xF1) refer to? Google didn't really come up with something I could work with.

更新:既然是显然不可能得到这些DOS调用工作在Windows 7中,我需要一种方法来异步调用在一般单线程环境功能

UPDATE: Since it is apparently not possible to get those DOS calls working in Windows 7, I need a way to asynchronously call a function in a generally single threaded environment.

在Linux下,信号()加薪()函数可以做到这一点,但在Windows下它们是仅在这是可能的最起码的方式支撑。有没有一种方法来实现,在Windows下?

Under linux, the signal() and raise() functions can do this, but under Windows they are only supported in the most minimal way that is possible. Is there a way to achieve that under Windows?

推荐答案

您一定会需要更换tick_isr和和context_switch_isr,因为他们正在实施的上下文切换的DOS环境。有没有办法在现有code会做在Windows任何有意义的事,即使你可以理智地执行它。

You'll definitely need to replace tick_isr and and context_switch_isr, since they're implementing context-switching for a DOS environment. There's no way the existing code will do anything meaningful in Windows, even if you could sensibly execute it.

由于在原来的code,上下文切换是preemptive,你很可能只是消除这种逻辑完全和使用Windows线程来代替。 presumably现有code的用于创建和删除上下文的一些例程,而这些可以用相应的Windows API线程函数所取代。

Since, in the original code, the context switches are preemptive, you could probably just eliminate that logic altogether and use Windows threads instead. Presumably the existing code has some routines for creating and removing contexts, and these can be replaced with corresponding Windows API thread functions.

如果您需要确保只有一个线程同时运行,你可以使用的 SetProcessAffinityMask 的进程绑在一个单一的CPU。

If you need to ensure that only one thread is running at a time, you could use SetProcessAffinityMask to tie the process to a single CPU.

另外,你可以使用调试功能 GetThreadContext SetThreadContext 来实现自己的上下文切换。在这种情况下,你将有主程序code一个线程运行的上下文转换器第二个线程。

Alternatively, you could use the debugging functions GetThreadContext and SetThreadContext to implement your own context switching. In this situation you would have one thread for the main program code and a second thread running the context switcher.

这篇关于在单线程环境异步调用 - 在Windows上安装定时器/时钟ISR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆