home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / alib / createtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.4 KB  |  117 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: createtask.c,v 1.2 1997/01/27 00:16:35 ldp Exp $
  4.  
  5.     Desc: Create a new Amiga task
  6.     Lang: english
  7. */
  8. #include <exec/memory.h>
  9. #include <exec/execbase.h>
  10. #include <proto/exec.h>
  11.  
  12. struct newMemList
  13. {
  14.   struct Node      nml_Node;
  15.   UWORD       nml_NumEntries;
  16.   struct MemEntry nml_ME[2];
  17. };
  18.  
  19. const struct newMemList MemTemplate =
  20. {
  21.     { 0, },
  22.     2,
  23.     {
  24.     { { MEMF_CLEAR|MEMF_PUBLIC }, sizeof(struct Task) },
  25.     { { MEMF_CLEAR           }, 0           }
  26.     }
  27. };
  28.  
  29.  
  30. /*****************************************************************************
  31.  
  32.     NAME */
  33. #include <exec/tasks.h>
  34. #include <proto/alib.h>
  35.  
  36.     struct Task * CreateTask (
  37.  
  38. /*  SYNOPSIS */
  39.     STRPTR name,
  40.     LONG   pri,
  41.     APTR   initpc,
  42.     ULONG  stacksize)
  43.  
  44. /*  FUNCTION
  45.     Create a new task.
  46.  
  47.     INPUTS
  48.     name - Name of the task. The string is not copied. Note that
  49.         task names' need not be unique.
  50.     pri - The initial priority of the task (normally 0)
  51.     initpc - The address of the first instruction of the
  52.         task. In most cases, this is the address of a
  53.         function.
  54.     stacksize - The size of the stack for the task. Always
  55.         keep in mind that the size of the stack must include
  56.         the amount of stack which is needed by the routines
  57.         called by the task.
  58.  
  59.     RESULT
  60.     A pointer to the new task or NULL on failure.
  61.  
  62.     NOTES
  63.  
  64.     EXAMPLE
  65.  
  66.     BUGS
  67.  
  68.     SEE ALSO
  69.  
  70.     INTERNALS
  71.  
  72.     HISTORY
  73.  
  74. ******************************************************************************/
  75. {
  76.     struct Task     * newtask,
  77.             * task2;
  78.     struct newMemList nml;
  79.     struct MemList  * ml;
  80.  
  81.     nml = MemTemplate;
  82.  
  83.     stacksize = AROS_ALIGN(stacksize);
  84.     nml.nml_ME[1].me_Length = stacksize;
  85.  
  86.     ml = AllocEntry ((struct MemList *)&nml);
  87.  
  88.     if (!((IPTR)ml & (0x80ul<<(sizeof(APTR)-1)*8)) )
  89.     {
  90.     newtask = ml->ml_ME[0].me_Addr;
  91.  
  92.     newtask->tc_Node.ln_Type = NT_TASK;
  93.     newtask->tc_Node.ln_Pri  = pri;
  94.     newtask->tc_Node.ln_Name = name;
  95.  
  96.     newtask->tc_SPReg   = (APTR)((ULONG)ml->ml_ME[1].me_Addr + stacksize);
  97.     newtask->tc_SPLower = ml->ml_ME[1].me_Addr;
  98.     newtask->tc_SPUpper = newtask->tc_SPReg;
  99.  
  100.     NewList (&newtask->tc_MemEntry);
  101.     AddHead (&newtask->tc_MemEntry, (struct Node *)ml);
  102.  
  103.     task2 = (struct Task *)AddTask (newtask, initpc, 0);
  104.  
  105.     if (SysBase->LibNode.lib_Version>36 && !task2)
  106.     {
  107.         FreeEntry (ml);
  108.         newtask = NULL;
  109.     }
  110.     }
  111.     else
  112.     newtask=NULL;
  113.  
  114.     return newtask;
  115. } /* CreateTask */
  116.  
  117.