home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKTSUB.C < prev    next >
C/C++ Source or Header  |  1990-10-12  |  3KB  |  147 lines

  1. /*
  2.    --- Version 2.2 90-10-12 10:34 ---
  3.  
  4.    TSKTSUB.C - CTask - Timer/watch helper routines.
  5.  
  6.    CTask - a Multitasking Kernel for C
  7.  
  8.    Public Domain Software written by
  9.       Thomas Wagner
  10.       Ferrari electronic Gmbh
  11.       Beusselstrasse 27
  12.       D-1000 Berlin 21
  13.       Germany
  14.  
  15.    No rights reserved.
  16.  
  17.    This file is new with 2.1. The timer related helper functions were moved
  18.    from tsktimer to this module.
  19. */
  20.  
  21. #include "tsk.h"
  22. #include "tsklocal.h"
  23.  
  24. #include <stdarg.h>
  25.  
  26. /*
  27.    tsk_setup_telem
  28.       Initializes a timeout/watch element.
  29. */
  30.  
  31. tlinkptr Localfunc tsk_setup_telem (tlinkptr elem, byte kind, 
  32.                                     farptr strucp, byte struckind, 
  33.                                     dword upar)
  34. {
  35. #if (GROUPS)
  36.    CRITICAL;
  37. #endif
  38.  
  39.    if (struckind <= TKIND_TASK || struckind > TKIND_COUNTER)
  40.       return LNULL;
  41.  
  42. #if (TSK_DYNAMIC)
  43.    if (elem == LNULL)
  44.       {
  45.       if ((elem = tsk_palloc (sizeof (tlink))) == LNULL)
  46.          return LNULL;
  47.       elem->flags = TFLAG_TEMP;
  48.       }
  49.    else
  50.       elem->flags = 0;
  51. #else
  52.    elem->flags = 0;
  53. #endif
  54.  
  55.    elem->link.next = LNULL;
  56.    elem->link.kind = kind;
  57.    elem->struckind = struckind;
  58.    elem->strucp = strucp;
  59.    elem->user_parm = upar;
  60. #if (GROUPS)
  61.    C_ENTER;
  62.    tsk_putqueue (&GLOBDATA current_task->group->telem_list, (queptr)&elem->chain);
  63.    C_LEAVE;
  64. #endif
  65.    return elem;
  66. }
  67.  
  68.  
  69. /*
  70.    enable_watch
  71.       Enables a watch entry by enqueueing it into the watch queue.
  72. */
  73.  
  74. void Globalfunc enable_watch (tlinkptr elem)
  75. {
  76.    CRITICAL;
  77.  
  78.    CHECK_TELPTR (elem, TYP_WATCH, "Enable Watch");
  79.  
  80.    if (elem->link.next)
  81.       return;
  82.    C_ENTER;
  83.    tsk_putqueue (&GLOBDATA watch_queue, &elem->link);
  84.    C_LEAVE;
  85. }
  86.  
  87.  
  88. /*
  89.    disable_watch
  90.       Disables a watch entry by removing it from the watch queue.
  91. */
  92.  
  93. #if (CHECKING)
  94. void Globalfunc disable_hwatch (tlinkptr elem, byte typ)
  95. #else
  96. void Globalfunc disable_watch (tlinkptr elem)
  97. #endif
  98. {
  99.    CRITICAL;
  100.  
  101.    CHECK_TELPTR (elem, typ, "Disable Watch/Hotkey");
  102.  
  103.    C_ENTER;
  104.    if (elem->flags & TFLAG_BUSY)
  105.       elem->flags |= TFLAG_UNQUEUE;
  106.    else
  107.       tsk_dequeue (&elem->link);
  108.    C_LEAVE;
  109. }
  110.  
  111.  
  112. /*
  113.    delete_watch
  114.       Deletes a watch element.
  115. */
  116.  
  117. #if (CHECKING)
  118. void Globalfunc delete_hwatch (tlinkptr elem, byte typ)
  119. #else
  120. void Globalfunc delete_watch (tlinkptr elem)
  121. #endif
  122. {
  123.    CRITICAL;
  124.  
  125.    CHECK_TELPTR (elem, typ, "Delete Watch/Hotkey");
  126.  
  127.    C_ENTER;
  128.    if (elem->flags & TFLAG_BUSY)
  129.       {
  130.       elem->flags |= TFLAG_REMOVE;
  131.       C_LEAVE;
  132.       return;
  133.       }
  134.  
  135.    tsk_dequeue (&elem->link);
  136. #if (GROUPS)
  137.    tsk_dequeue ((queptr)&elem->chain);
  138. #endif
  139.    C_LEAVE;
  140.  
  141. #if (TSK_DYNAMIC)
  142.    if (elem->flags & TFLAG_TEMP)
  143.       tsk_pfree (elem);
  144. #endif
  145. }
  146.  
  147.