//===================================================== file = smpl_ex3.c ===== //= Demonstration of SMPL schedule(), preempt(), and release() = //============================================================================= //= Notes: This program is a simple does program... does nothing useful = //= Uses printf() to show program flow. = //=---------------------------------------------------------------------------= //= Build: Standard SMPL build = //=---------------------------------------------------------------------------= //= History: KJC (02/17/05) - Genesis = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include "smpl.h" // Needed for SMPL //----- Constants ------------------------------------------------------------- #define THRESH 3 // Threshold for priority //===== Main program ========================================================== void main(void) { int cust_id; // Customer id int cust_priority; // Customer priority int event; // Event (1 = preempt, 2 = release) int server; // Handle for server facility real x; // Temporary real value // Initialize SMPL subsystem smpl(0, "Test Program"); // Initialize server facility (single server) server = facility("server", 1); // Schedule some requests for the facility schedule(1, 1.0, cust_id = 1); schedule(1, 2.0, cust_id = 2); schedule(1, 3.0, cust_id = 3); schedule(1, 4.0, cust_id = 4); // Loop forever while (1) { // "Cause" the next event on the event list cause(&event,&cust_id); printf("TOP time = %4.2f event = %d cust_id = %d \n", time(), event, cust_id); // Process the event switch(event) { case 1: // *** Prempt Server printf("1 time = %4.2f \n", time()); if (cust_id < THRESH) cust_priority = 0; else cust_priority = 1; if (preempt(server, cust_id, cust_priority) == 0) { schedule(2, x = 10.0, cust_id); printf("1a time = %4.2f sched(2) = %4.2f\n", time(), time() + x); } break; case 2: // *** Release server release(server, cust_id); printf("2 time = %4.2f \n", time()); break; default: // *** If not case 1 or 2 printf("DEFAULT - No more events... time to exit() \n"); break; } } }