home *** CD-ROM | disk | FTP | other *** search
- Path: comma.rhein.de!yaps!arno
- From: arno@yaps.rhein.de (Arno Eigenwillig)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: AmiTCP and threads
- Message-ID: <GfVmy*4rg@yaps.rhein.de>
- Date: Sun, 07 Apr 1996 14:36:26 +0200
- References: <9604061820.AA00093@entire.demon.co.uk>
- Organization: Yet Another Private Site in Meckenheim, Germany
- X-Copyright: This article may not be distributed on a CD-ROM
- or in printed form without prior written consent of the author.
- X-Newsreader: Arn V 1.04
-
- In article <9604061820.AA00093@entire.demon.co.uk>, Mike Gooder writes:
-
- > each time this function is
- > started as a thread it needs it's own SocketBase.
- > Is there a way of doing this
-
- If you have a decent compiler, there is.
-
- The classic way to store a library base is to put it into a global
- variable of a predefined name. When an OS function is called, actually
- the amiga.lib stub function of the same name is called, copies the
- base from the global variable into A6, moves the parameters from the
- stack (classic C method of passing them) into the correct registers,
- and calls the actual function.
-
- Obviously, this does not work if a part of your code needs another
- library base. Instead, you will have to use a smarter way (which
- additionally is faster, because it saves the stub routine overhead).
- For SAS/C, DICE and probably others, it is called "pragmas", GCC has
- AFAIK another method to yield similar results.
-
- The "pragma" method of calling a library function consists of
- #including <pragmas/*_pragmas.h> files which contain special #pragma
- directives that tell the compiler how to generate in-line code for
- library calls. The library base is still fetched from a variable with
- the aforementioned predefined name, but this variable need not be
- global. With SAS/C, it can even be a #define!
-
- So what you can do is this:
-
- #include <clib/foo_protos.h>
- #include <pragmas/foo_pragmas.h>
-
- struct FooBase *FooBase;
-
- int main(void) {
-
- if (FooBase = OpenLibrary("foo.library", 42)) {
- FooFunction(1, 2, 3);
- /* ... */
- }
-
- void daughter_task_code(void) {
- struct FooBase *FooBase;
-
- if (FooBase = OpenLibrary("foo.library", 42)) {
- FooFunction(1, 2, 3);
- /* ... */
- }
-
- The global "FooBase" will be used throughout your program, only the
- daughter_task_code() will use its special local FooBase opened from
- within its own task. (One might argue that overlapping scopes of
- variable names are dangerous, though.)
-
- Obviously, things get tricky when daughter_task_code() calls other
- functions which in turn need FooBase. If they are only called by
- daughter_task_code() and daughter_task_code() is spawned only once
- (which does not seem to be the case for you), one could ponder to move
- all daughter task functions into a separate file and declare a static
- FooBase at file scope there. Otherwise, the library base has to be
- passed as an argument to the relevant functions.
-
- -- __
- __/// Arno Eigenwillig /\ <arno@yaps.rhein.de> \/ PGP key available.
- \XX/ V+49-2225-5870 /\ <Arnooo @ #amigager> \/ MIME 8bit welcome.
-