|
From: <jmk...@us...> - 2003-08-24 09:38:28
|
Update of /cvsroot/emc/rtapi/examples/timertask
In directory sc8-pr-cvs1:/tmp/cvs-serv3121/examples/timertask
Modified Files:
timertask.c
Log Message:
Added module ID, now rtapi_exit() should remove all items allocated by the module. Added a mutex to protect RTAPI internal data from simultaneous access. Basic testing complete, needs more detailed testing.
Index: timertask.c
===================================================================
RCS file: /cvsroot/emc/rtapi/examples/timertask/timertask.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** timertask.c 20 Aug 2003 03:16:21 -0000 1.13
--- timertask.c 24 Aug 2003 09:38:24 -0000 1.14
***************
*** 9,12 ****
--- 9,13 ----
#include "rtapi_app.h" /* rtapi_app_main,exit() */
+ static int module;
static int timer_task; /* the task ID */
static int timer_count = 0; /* the output variable */
***************
*** 38,42 ****
long period;
! if (rtapi_init() != RTAPI_SUCCESS ) {
return -1;
}
--- 39,45 ----
long period;
! module = rtapi_init("TIMERTASK");
! if ( module < 0 ) {
! rtapi_print( "timertask init: rtapi_init returned %d\n", module );
return -1;
}
***************
*** 51,54 ****
--- 54,58 ----
rtapi_print("timertask init: rtapi_clock_set_period failed with %ld\n",
period);
+ rtapi_exit(module);
return -1;
}
***************
*** 58,61 ****
--- 62,66 ----
/* timer period too long */
rtapi_print("timertask init: clock period too long: %ld\n", period );
+ rtapi_exit(module);
return -1;
}
***************
*** 69,77 ****
/* the second arg is an abitrary int that is passed to the timer task
on the first iterration */
! timer_task = rtapi_task_new(timer_code, 0 /* arg */, timer_prio,
TIMER_STACKSIZE, RTAPI_NO_FP );
if ( timer_task < 0 ) {
/* See rtapi.h for the error codes returned */
rtapi_print( "timertask init: rtapi_task_new returned %d\n", timer_task );
return -1;
}
--- 74,83 ----
/* the second arg is an abitrary int that is passed to the timer task
on the first iterration */
! timer_task = rtapi_task_new(timer_code, 0 /* arg */, timer_prio, module,
TIMER_STACKSIZE, RTAPI_NO_FP );
if ( timer_task < 0 ) {
/* See rtapi.h for the error codes returned */
rtapi_print( "timertask init: rtapi_task_new returned %d\n", timer_task );
+ rtapi_exit(module);
return -1;
}
***************
*** 80,83 ****
--- 86,90 ----
if ( retval != RTAPI_SUCCESS ) {
rtapi_print("timertask init: rtapi_task_start returned %d\n", retval );
+ rtapi_exit(module);
return -1;
}
***************
*** 102,106 ****
/* Remove the task from the list */
- /* TESTING - intentionally skip the task_delete */
retval = rtapi_task_delete(timer_task);
if ( retval != RTAPI_SUCCESS ) {
--- 109,112 ----
***************
*** 111,115 ****
rtapi_print("timertask exit: timer count is %d\n", timer_count);
/* Clean up and exit */
! rtapi_exit();
}
--- 117,121 ----
rtapi_print("timertask exit: timer count is %d\n", timer_count);
/* Clean up and exit */
! rtapi_exit(module);
}
|