Tag: 实时

如何限制C / POSIX中函数的执行时间?

与此问题类似,我想在C中限制函数的执行时间 – 最好是微秒精度。我想C ++exception可用于实现类似于此 Python解决方案的结果。 虽然它并不理想,但这种方法在普通C中完全不可用。 那么,我想知道如何在Posix系统上的C中经过一定的时间间隔后中断函数的执行? 对于相对简单的情况,一些愚蠢的业务工作得很好,但这增加了与问题解决方案正交的大量代码。 假设我有这样的函数: void boil(egg *e) { while (true) do_boil(e); } 我想在鸡蛋上运行煮沸*,每50μs打断一次,检查一下这样做: egg *e = init_egg(); while (true) { preempt_in(50, (void) (*boil), 1, e); /* Now boil(e) is executed for 50μs, then control flow is returned to the statement prior to the call to preempt_in. */ if (e->cooked_val > […]

将pthread作为输入并暂停的函数

我正在尝试从POSIX中的ExpressLogic移植实时Thread_Metric,以便为我的论文对Linux,Xenomai和RTAI的PREEMPT_RT补丁进行基准测试。 它们提供了具有以下function的C源文件,您必须实现这些function才能使基准测试工作: void tm_initialize(void (*test_initialization_function)(void)); int tm_thread_create(int thread_id, int priority, void (*entry_function)(void)); int tm_thread_resume(int thread_id); int tm_thread_suspend(int thread_id); void tm_thread_relinquish(void); void tm_thread_sleep(int seconds); int tm_queue_create(int queue_id); int tm_queue_send(int queue_id, unsigned long *message_ptr); int tm_queue_receive(int queue_id, unsigned long *message_ptr); int tm_semaphore_create(int semaphore_id); int tm_semaphore_get(int semaphore_id); int tm_semaphore_put(int semaphore_id); int tm_memory_pool_create(int pool_id); int tm_memory_pool_allocate(int pool_id, unsigned char […]

具有实时优先级的pthreads

我需要管理具有不同优先级的线程池,因此我编写了以下线程启动过程: static int startup(thrd_t *thrd, thrd_sync_t *sync, int prio) { pthread_attr_t attr; int err; struct sched_param param = { .sched_priority = prio }; assert(pthread_attr_init(&attr) == 0); assert(pthread_attr_setschedpolicy(&attr, SCHED_FIFO) == 0); assert(pthread_attr_setschedparam(&attr, &param) == 0); err = pthread_create(&thrd->handler, &attr, thread_routine, (void *)thrd); pthread_attr_destroy(&attr); return err; } 原则上,不应允许非特权用户执行此代码:pthread_create()调用应返回EPERM,因为运行具有高优先级的线程具有安全隐患。 出乎意料的是,它适用于普通用户,但它根本不尊重给定的优先级。 我尝试通过删除pthread_attr_t并在创建线程后设置调度属性来修改代码: static int startup(thrd_t *thrd, thrd_sync_t *sync, int […]

实时进行FFT

我想实时地对音频信号进行FFT,这意味着当人在麦克风中讲话时。 我将获取数据(我使用portaudio执行此操作,如果使用wavein会更容易,我会乐意使用它 – 如果您可以告诉我如何)。 接下来我使用的是FFTW库 – 我知道如何执行1D,2D(实数和复数)FFT,但我不太清楚如何做到这一点,因为我必须进行3D FFT以获得频率,幅度(这将决定颜色渐变)和时间。 或者它只是一个2D FFT,我得到幅度和频率?

使用NDK在Android中进行实时图像处理

使用Android(2.3.3)手机,我可以使用相机通过onPreviewFrame(byte[] data, Camera camera)方法检索预览,以获取YUV图像。 对于某些图像处理,我需要将此数据转换为RGB图像并在设备上显示。 使用基本的java / android方法,运行速度低于5 fps …… 现在,使用NDK,我想加快速度。 问题是:如何将YUV数组转换为C中的RGB数组? 有没有办法在本机代码中显示它(也许使用OpenGL?)? 实时应该是可能的(Qualcomm AR演示向我们展示了这一点)。 我无法使用setTargetDisplay并在其上添加叠加层! 我知道Java,最近开始使用Android SDK并且没有C的经验

在C ++中vtable查找的性能损失

我正在评估将一个实时软件从C /汇编语言重写为C ++ /汇编语言(由于与代码问题无关的原因,在汇编时绝对需要这样做)。 中断带有3 kHz频率,对于每个中断,大约200个不同的事情将按顺序完成。 处理器以300 MHz运行,为我们提供100,000个周期来完成这项工作。 这已在C中用函数指针数组求解: // Each function does a different thing, all take one parameter being a pointer // to a struct, each struct also being different. void (*todolist[200])(void *parameters); // Array of pointers to structs containing each function’s parameters. void *paramlist[200]; void realtime(void) { int i; for (i = […]

睡觉一段确切的时间

我对睡眠function的理解是它遵循“至少语义”,即睡眠(5)将保证线程hibernate5秒,但是根据其他因素,它可能会保持阻塞超过5秒。 有没有办法在指定的时间段内睡觉(没有忙碌的等待)。