home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / gcc / libnixV0_8.lha / gnu / libnix-sources.lha / sources / amiga / misc / DoTimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  1.5 KB  |  57 lines

  1. #include <exec/memory.h>
  2. #include <devices/timer.h>
  3. #include <clib/alib_protos.h>
  4. #ifdef __GNUC__
  5. #include <inline/exec.h>
  6. #else
  7. #include <clib/exec_protos.h>
  8. #endif
  9.  
  10. struct PortIO
  11. {
  12.   struct timerequest treq;
  13.   struct MsgPort port;
  14. };
  15.  
  16. extern inline void NewList(struct List *list)
  17. {
  18.    LONG *p;
  19.  
  20.    list->lh_TailPred=(struct Node*)list;
  21.    ((LONG *)list)++;
  22.    p=(LONG *)list; *--p=(LONG)list;
  23. }
  24.  
  25. LONG DoTimer(struct timeval *time, long unit, long command)
  26. {
  27.   struct PortIO *portio;
  28.   long ret=-1;
  29.  
  30.   if ((portio=(struct PortIO *)AllocMem(sizeof(struct PortIO),MEMF_CLEAR|MEMF_PUBLIC)))
  31.   {
  32.     portio->port.mp_Node.ln_Type=NT_MSGPORT;
  33.     if ((BYTE)(portio->port.mp_SigBit=AllocSignal(-1))<0)
  34.     {
  35.       portio->port.mp_SigTask=FindTask(NULL);
  36.       NewList(&portio->port.mp_MsgList);
  37.  
  38.       portio->treq.tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  39.       portio->treq.tr_node.io_Message.mn_ReplyPort=&portio->port;
  40.       if (!(OpenDevice(TIMERNAME,unit,(struct IORequest *)&portio->treq,0)))
  41.       {
  42.         portio->treq.tr_node.io_Command=command;
  43.         portio->treq.tr_time.tv_secs=time->tv_secs;
  44.         portio->treq.tr_time.tv_micro=time->tv_micro;
  45.         DoIO((struct IORequest *)&portio->treq);
  46.         time->tv_secs=portio->treq.tr_time.tv_secs;
  47.         time->tv_micro=portio->treq.tr_time.tv_micro;
  48.         CloseDevice((struct IORequest *)&portio->treq);
  49.         ret=0;
  50.       }
  51.       FreeSignal(portio->port.mp_SigBit);
  52.     }
  53.     FreeMem(portio,sizeof(struct PortIO));
  54.   }
  55.   return ret;
  56. }
  57.