home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / findtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.5 KB  |  115 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: findtask.c,v 1.7 1997/01/01 03:46:10 ldp Exp $
  4.     $Log: findtask.c,v $
  5.     Revision 1.7  1997/01/01 03:46:10  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.6  1996/12/10 13:51:45  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.5  1996/10/24 15:50:49  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/08/13 13:56:02  digulla
  17.     Replaced AROS_LA by AROS_LHA
  18.     Replaced some AROS_LH*I by AROS_LH*
  19.     Sorted and added includes
  20.  
  21.     Revision 1.3  1996/08/01 17:41:11  digulla
  22.     Added standard header for all files
  23.  
  24.     Desc:
  25.     Lang:
  26. */
  27. #include <exec/execbase.h>
  28. #include <aros/libcall.h>
  29. #include <proto/exec.h>
  30.  
  31. /*****************************************************************************
  32.  
  33.     NAME */
  34.  
  35.     AROS_LH1(struct Task *, FindTask,
  36.  
  37. /*  SYNOPSIS */
  38.     AROS_LHA(STRPTR, name, A1),
  39.  
  40. /*  LOCATION */
  41.     struct ExecBase *, SysBase, 49, Exec)
  42.  
  43. /*  FUNCTION
  44.     Find a task with a given name or get the address of the current task.
  45.     Finding the address of the current task is a very quick function
  46.     call, but finding a special task is a very CPU intensive instruction.
  47.     Note that generally a task may already be gone when this function
  48.     returns.
  49.  
  50.     INPUTS
  51.     name - Pointer to name or NULL for current task.
  52.  
  53.     RESULT
  54.     Address of task structure found.
  55.  
  56.     NOTES
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.  
  68. ******************************************************************************/
  69. {
  70.     AROS_LIBFUNC_INIT
  71.  
  72.     struct Task *ret;
  73.  
  74.     /* Quick return for a quick argument */
  75.     if(name==NULL)
  76.     return SysBase->ThisTask;
  77.  
  78.     /* Always protect task lists with a Disable(). */
  79.     Disable();
  80.  
  81.     /* First look into the ready list. */
  82.     ret=(struct Task *)FindName(&SysBase->TaskReady,name);
  83.     if(ret==NULL)
  84.     {
  85.     /* Then into the waiting list. */
  86.     ret=(struct Task *)FindName(&SysBase->TaskWait,name);
  87.     if(ret==NULL)
  88.     {
  89.         /*
  90.         Finally test the current task. Note that generally
  91.         you know the name of your own task - so it is close
  92.         to nonsense to look for it this way.
  93.         */
  94.         char *s1=SysBase->ThisTask->tc_Node.ln_Name;
  95.         char *s2=name;
  96.  
  97.         /* Check as long as the names are identical. */
  98.         while(*s1++==*s2)
  99.         /* Terminator found? */
  100.         if(!*s2++)
  101.         {
  102.             /* Got it. */
  103.             ret=SysBase->ThisTask;
  104.             break;
  105.         }
  106.     }
  107.     }
  108.  
  109.     /* Return whatever I found. */
  110.     Enable();
  111.     return ret;
  112.     AROS_LIBFUNC_EXIT
  113. } /* FindTask */
  114.  
  115.