home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7020 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  79 lines

  1. Path: comma.rhein.de!yaps!arno
  2. From: arno@yaps.rhein.de (Arno Eigenwillig)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: AmiTCP and threads
  5. Message-ID: <GfVmy*4rg@yaps.rhein.de>
  6. Date: Sun, 07 Apr 1996 14:36:26 +0200
  7. References: <9604061820.AA00093@entire.demon.co.uk>
  8. Organization: Yet Another Private Site in Meckenheim, Germany
  9. X-Copyright: This article may not be distributed on a CD-ROM
  10.  or in printed form without prior written consent of the author.
  11. X-Newsreader: Arn V 1.04
  12.  
  13. In article <9604061820.AA00093@entire.demon.co.uk>, Mike Gooder writes:
  14.  
  15. > each time this function is
  16. > started as a thread it needs it's own SocketBase.
  17. > Is there a way of doing this
  18.  
  19. If you have a decent compiler, there is.
  20.  
  21. The classic way to store a library base is to put it into a global
  22. variable of a predefined name. When an OS function is called, actually
  23. the amiga.lib stub function of the same name is called, copies the
  24. base from the global variable into A6, moves the parameters from the
  25. stack (classic C method of passing them) into the correct registers,
  26. and calls the actual function.
  27.  
  28. Obviously, this does not work if a part of your code needs another
  29. library base. Instead, you will have to use a smarter way (which
  30. additionally is faster, because it saves the stub routine overhead).
  31. For SAS/C, DICE and probably others, it is called "pragmas", GCC has
  32. AFAIK another method to yield similar results.
  33.  
  34. The "pragma" method of calling a library function consists of
  35. #including <pragmas/*_pragmas.h> files which contain special #pragma
  36. directives that tell the compiler how to generate in-line code for
  37. library calls. The library base is still fetched from a variable with
  38. the aforementioned predefined name, but this variable need not be
  39. global. With SAS/C, it can even be a #define!
  40.  
  41. So what you can do is this:
  42.  
  43. #include <clib/foo_protos.h>
  44. #include <pragmas/foo_pragmas.h>
  45.  
  46. struct FooBase *FooBase;
  47.  
  48. int main(void) {
  49.  
  50.     if (FooBase = OpenLibrary("foo.library", 42)) {
  51.         FooFunction(1, 2, 3);
  52.     /* ... */
  53. }
  54.  
  55. void daughter_task_code(void) {
  56.     struct FooBase *FooBase;
  57.  
  58.     if (FooBase = OpenLibrary("foo.library", 42)) {
  59.         FooFunction(1, 2, 3);
  60.     /* ... */
  61. }
  62.  
  63. The global "FooBase" will be used throughout your program, only the
  64. daughter_task_code() will use its special local FooBase opened from
  65. within its own task. (One might argue that overlapping scopes of
  66. variable names are dangerous, though.)
  67.  
  68. Obviously, things get tricky when daughter_task_code() calls other
  69. functions which in turn need FooBase. If they are only called by
  70. daughter_task_code() and daughter_task_code() is spawned only once
  71. (which does not seem to be the case for you), one could ponder to move
  72. all daughter task functions into a separate file and declare a static
  73. FooBase at file scope there. Otherwise, the library base has to be
  74. passed as an argument to the relevant functions.
  75.  
  76. -- __
  77. __/// Arno Eigenwillig /\ <arno@yaps.rhein.de> \/ PGP key available.
  78. \XX/   V+49-2225-5870  /\ <Arnooo @ #amigager> \/ MIME 8bit welcome.
  79.