VxWorks多任务通信--管道
来源:互联网 发布:软件工程项目有哪些 编辑:程序博客网 时间:2024/05/22 04:27
pipeServer.c
/* includes */#include "vxWorks.h"#include "taskLib.h"#include "stdio.h"#include "ioLib.h"#include "pipeDrv.h"typedef struct { VOIDFUNCPTR routine; int arg; } MSG_REQUEST; /* message structure */#define TASK_PRI 254 /* tServers task's priority */#define TASK_STACK_SIZE 5000 /* tServer task's stack size */#define PIPE_NAME "/pipe/server" /* name of the pipe device */#define NUM_MSGS 10 /* max number of messages in the pipe */LOCAL int pipeFd; /* File descriptor for the pipe device */LOCAL void pipeServer (); /* server task *//*********************************************************************** * serverStart -- Initializes a server task to execute functons * at a low priority. Uses pipes as the communication * mechanism. * * RETURNS: OK or ERROR on failure. */STATUS serverStart () { if (pipeDevCreate (PIPE_NAME, NUM_MSGS, sizeof (MSG_REQUEST)) == ERROR) { perror ("Error in creating pipe"); /* print error if pipe is already * created, but do not return */ } /* Open the pipe */ if ((pipeFd = open (PIPE_NAME, UPDATE, 0)) == ERROR) { perror ("Error in opening pipe device"); return (ERROR); } /* Spawn the server task */ if (taskSpawn ("tServer", TASK_PRI, 0, TASK_STACK_SIZE, (FUNCPTR) pipeServer, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == ERROR) { perror ("Error in spawning tServer task"); close (pipeFd); return (ERROR); } return (OK); }/************************************************************** * serverSend -- Sends a request to the server to execute a * function at the server's priority. * * RETURNS: OK or ERROR on failure. */STATUS serverSend ( VOIDFUNCPTR routine, /* name of the routine to execute */ int arg /* argument of the routine */ ) { MSG_REQUEST msgRequest; int status; /* Initialize the message structure */ msgRequest.routine = routine; msgRequest.arg = arg; /* Send the message and return the results */ status = write (pipeFd, (char *)&msgRequest, sizeof (MSG_REQUEST)); return ((status == sizeof (MSG_REQUEST)) ? OK : ERROR); }/************************************************************************* * pipeServer -- Server task which reads from a pipe and executes * the function passed in the MSG_REQUEST data structure. * */LOCAL void pipeServer () { MSG_REQUEST msgRequest; while (read (pipeFd, (char *)&msgRequest, sizeof (MSG_REQUEST)) > 0) (*msgRequest.routine) (msgRequest.arg); }
阅读全文
0 0
- VxWorks多任务通信--管道
- 【VxWorks系列】任务间同步与通信之管道
- VxWorks的多任务通信机制
- vxworks任务间通信
- vxworks中任务间的通信支持信号量、消息队列、管道、信号、事件、共享内存等
- vxworks中任务间的通信支持信号量、消息队列、管道、信号、事件、共享内存等
- vxworks中任务间的通信支持信号量、消息队列、管道、信号、事件
- vxworks中任务间的通信支持信号量、消息队列、管道、信号、事件、共享内存等
- VxWorks任务间通信机制
- Vxworks任务间的通信
- 【转载】VxWorks的多任务通信机制(作者:陈军科)
- vxWorks多任务编程
- VxWorks进程通信0 -- 任务管理
- Linux下多任务间通信和同步-管道
- vxworks---多任务(1)
- java多线程之任务间管道通信
- java多线程 任务间管道通信
- 基于嵌入式操作系统VxWorks的多任务并发程序设计(4)――任务间通信A
- IP--划分子网
- FPGA源同步输入时序约束(三)
- 学习遇到的python 2.X和python 3.x的区别总结
- caffe中bn层与scale层
- FreeCodeCamp备查簿(3:#91-#131)
- VxWorks多任务通信--管道
- 学习LCA 基于rmq的lca 代码注释
- 【Linux应用开发】之守护进程
- 遇到问题---MongoDB---配置多数据源报错expected single matching bean but found 2
- JVM之几种垃圾收集器简单介绍
- SQLException: Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...'
- hdu4135 容斥
- hdu4965---Fast Matrix Calculation(矩阵)
- HDU6118 度度熊的交易计划 【费用流】