Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!elroy.jpl.nasa.gov!abcfd20.larc.nasa.gov!amiga-request From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator) Newsgroups: comp.sources.amiga Subject: v90i284: odin.library 2.7 - linda-like interprocess communications library, Part01/02 Message-ID: Date: 14 Oct 90 19:18:13 GMT Reply-To: "Peter \rb{k" Lines: 1795 Approved: tadguy@uunet.UU.NET (Tad Guy) X-Mail-Submissions-To: amiga@uunet.uu.net X-Post-Discussions-To: comp.sys.amiga Submitted-by: "Peter \rb{k" Posting-number: Volume 90, Issue 284 Archive-name: libraries/odinlib-2.7/part01 [ uuencoded library enclosed. one source module and two text files had to be uuencoded because of 8-bit characters and escape seqs ...tad ] This is release two of odin.library, containing Linda-like IPC- features for the Amiga. A few bugs in release one has been eliminated. Several features have been added, eg. It's now possible to wait for an envelope with a timeout, so you wont be blocked forever. Also you can now request that envelopes be posted to a specified messageport, so your task can be signalled when the envelope arrives. The documentation has been polished up too! And the examples are better and more extensive. #!/bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'Makefile' <<'END_OF_FILE' X# X# Aztec-makefile X# X XCCFLAGS = XLINKOBJS = odinglue.o XLIBS = -lc XTMPDIR = RAM: X X.c.o: X copy $*.c $(TMPDIR) X cc $(CCFLAGS) -o $(TMPDIR)$@ $(TMPDIR)$*.c X Xall: odindemo1 odintest philosophers tasks draw X Xodindemo1: odindemo1.o odinglue.o X ln -o $(TMPDIR)$@ $(TMPDIR)$@.o $(LINKOBJS) $(LIBS) X copy $(TMPDIR)$@ $@ X Xodinglue.o: odinglue.asm X as odinglue X Xodintest: odintest.o odinglue.o X ln -o $(TMPDIR)$@ $(TMPDIR)$@.o $(LINKOBJS) $(LIBS) X copy $(TMPDIR)$@ $@ X Xphilosophers: philosophers.o odinglue.o X ln -o $(TMPDIR)$@ $(TMPDIR)$@.o $(LINKOBJS) $(LIBS) X copy $(TMPDIR)$@ $@ X Xtasks: tasks.o X ln -o $(TMPDIR)$@ $(TMPDIR)$@.o $(LIBS) X copy $(TMPDIR)$@ $@ X Xdraw: draw.o odinglue.o X ln -o $(TMPDIR)$@ $(TMPDIR)$@.o $(LINKOBJS) $(LIBS) X copy $(TMPDIR)$@ $@ END_OF_FILE if test 747 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'draw.c.uu' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'draw.c.uu'\" else echo shar: Extracting \"'draw.c.uu'\" \(16726 characters\) sed "s/^X//" >'draw.c.uu' <<'END_OF_FILE' Xbegin 666 draw.c XM+RHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJG XM*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH*("!D2!0971E0H@($1R87=S(&QI;F5S(&EN(&UU;'1I<&QE('=I;F1O=W,*("!#;VUP:6QE` XM7!E&5C+W1A2@I+"IS=')C870H*3L* XM;65N=2T^5VED=&@@/2`Q,"IS=')L96XH;65N=71I=&QE*3L*"6UE;G4M/DAE# XM:6=H="`](#$P*FYU;2LU.PH);65N=2T^1FQA9W,@/2!-14Y514Y!0DQ%1#L*A XM"6UE;G4M/DUE;G5.86UE(#T@*$)95$4@*BEM96YU=&ET;&4["@D*"69O XM960@8GD@365N=2`J+PIV;VED(&1EPH)PH)"49R965-96TH:71E;2T^K XM271E;49I;&PL*&QO;F'0I*3L*"0EN% XM97AT7VET96T@/2!I=&5M+3Y.97AT271E;3L*"0E&PH)16YV96QO<&4@93L*"6EN="!TJ XM>7!E.PD)"2\J('=H870@='EP92!O9B!A8W1I;VX@=&\@=&%K92`J+PH)6YA;64["2\J(&YA;64@;V8@96YV96QO<&4@=&AA="!I#$L>3$I"G-T#$@*ST@-#L)"0DO*B!D4 XM;VXG="!W2`K/2`Q,#L@L XM>3$@*ST@,3`["@E-;W9E*')P+"AL;VYG*7@L*&QO;F2D["@E$PH)55=/4D0)>"QY.PH)"`K/2`R*2!["@D)"6QI;F4H"PP+'"QH*3L*E XM"0D):68H96YV(#T@*'-TPH)"0EL:6YE*')P+'2PP+&@M>2D["@D)"6EF*&5N" XM=B`]("AS=')U8W0@1')A=T5N=B`J*5!O;&Q.86UE9$5N=F5L;W!E*&5N=FYA$ XM;64I*2!R971U"`](#`[('@@/"!W.R!X("L]R XM(#(I('L*"0D);&EN92AR<"QX+#`L>"QH*3L*"0D):68H96YV(#T@*'-TPH)"0EL7 XM:6YE*')P+#`L>2QW+'DI.PH)"0EI9BAE;G8@/2`H7!E)W,@*B\*(V1E9FEN92!$4D%715)?1 XM4D5325I%1"`Q"2\J('-E;G0@=VAE;B!N97<@ XM16YV("IE;G8["@H);7ER<"`](&1R87=E;G8M/G=I;F1O=RT^4E!OPH)"65N=B`](&1RO XM87=?<&%T=&5R;BAM>7)P+'7!E*2!["@D)"6-A6YA;64I.PH)"0D)1&ES<&]S945N=F5L;W!E*&5N=BD[' XM"@D)"0DO*B!W86ET(&9O XM:&4@<&%R86US+B!F XM8W!Y*"9D5LP72PB9%)E<&QY(BDI.PH*"4-2*'!R:6YT9B@B7 XM8VUD.B`E3H@)7-<;B(L8VUD;F%M92QD2D[*0H*/ XM"2\J(&EN:70@<&%R=',@;V8@3F5W5VEN9&]W+7-T XM+DUA>%=I9'1H(#T@-C0P.PH)=W`M/FYW+DUI;DAE:6=H="`](#,P.R!W<"T^H XM;G2!W:6YD;W<@*B\*"7=PA XM+3YC;60@/2!-05-415)?1$E%.PD)+RH@<')E<&%R92!F;W(@979T+B!F86EL. XM=7)E("HO"@EW:6X@/2!/<&5N5VEN9&]W*"9W<"T^;GF5O9BAS=')U8W0@1')A=T5N=BDI.PH)=&4M/F4N95]P6YA;64@/2`F9')A=V5R7!E(#T@1%)!5T527U)%4TE:140["@D)"0EDV XM92T^=VEN9&]W(#T@=VEN.PH)"0D)3W5T*&1E*3L*"0D)"6)R96%K.PH)"0EC? XM87-E(%)%1E)%4TA724Y$3UF5O9BAS=')U8W0@5VEN9&]W4&%C:RDI.PH)"0D)"0EI9BAA& XM92D@>PH)"0D)"0D)864M/F-M9"`]($U!4U1%4E]34$%73CL*"0D)"0D)"6%E2 XM+3YW:6YD;W<@/2!W:6X["@D)"0D)"0E/=70H864I.PH)"0D)"0E]"@D)"0D)0 XM"6)R96%K.PH)"0D)"6-A"`J+PH)"0D)"0EA8W1I=F4@/2!&04Q313L*"0D)"0D)8G)E86L["@D)"0D)' XM9&5F875L=#H*"0D)"0D)8G)E86L["@D)"0E]"@D)"0EBPH)$)A2@B4D%-.F]D:6XN;&EB2(L9 XM,$PI*2D@9V]T;R!D;U]E>&ET.PH):68H(2A'9GA"87-E(#T@3W!E;DQI8G)A# XM2(L,$PI*2D@9V]T;R!D;U]E>&ET.PH*"4EN:71396UA<&AO&ET.PH)?0H*"2\J(&-R96%T92!P87)A;65T97)S('1O('=IQ XM;F1O=VUA;F%G97(@*B\*"7=P(#T@*'-TPH)"6%R9W,@/2`HPH)"0EC87-E($U!4U1%4E]34$%73CH*"0D)"2\J(&-R96%T" XM92!P87)A;65T97)S('1O('=I;F1O=VUA;F%G97(@*B\*"0D)"7=P(#T@*'-TI XM2@F;F%M6 XM95MR=6YN:6YG75LP72PBPH)"0EI9BAM96YU*2!D97-T'odin.h' <<'END_OF_FILE' X/* odin.h */ X/* headerfile for odin.library. V2.7 2-Sep-90 */ X X#ifndef ODIN_H X#define ODIN_H 1 X X#ifndef EXEC_NODES_H X#include "exec/nodes.h" X#endif X#ifndef EXEC_LISTS_H X#include "exec/lists.h" X#endif X#ifndef EXEC_PORTS_H X#include "exec/ports.h" X#endif X#ifndef EXEC_SEMAPHORES_H X#include "exec/semaphores.h" X#endif X#ifndef EXEC_LIBRARIES_H X#include "exec/libraries.h" X#endif X#ifndef EXEC_TASKS_H X#include "exec/tasks.h" X#endif X#ifndef LIBRARIES_DOSEXTENS_H X#include "libraries/dosextens.h" X#endif X X#define ODINNAME "odin.library" X Xstruct OdinBase { X struct Library odin_LibNode; X BPTR odin_SegList; X UBYTE odin_Flags; X /* You MUST ObtainSemaphore() this before using X * the WaitList! X */ X struct SignalSemaphore odin_Sem; /* signal semaphore */ X struct MinList odin_WaitList; X}; X X#define odin_Sizeof sizeof(struct OdinBase) X X/* prefix for envelopes */ X Xtypedef struct _Env { X struct MinNode e_link; /* first a link for use in e-space */ X STRPTR e_name; /* the name of this envelope */ X ULONG e_len; /* bytelength of whole envelope */ X struct _Env * (*e_copyfunc)();/* opt. C-function for copying */ X struct _Env * (*e_proc)(); /* C-func. to call in Eval() */ X} Envelope; X X#define e_sizeof (ULONG)sizeof(Envelope) X X/* wait-structure used in WaitList. Used internally */ X Xstruct WaitStruct { X struct MinNode ow_link; X Envelope *ow_envelope; X struct Task *ow_waittask; X UBYTE ow_sigbit; X BYTE ow_type; X}; X X#define ow_replyport ow_waittask X#define ow_sizeof (ULONG)sizeof(struct WaitStruct) X X/* ow_types (used internally) */ X X#define RD_REQUEST 0 X#define IN_REQUEST 1 X#define ASYNCIN_REQUEST 2 X#define ASYNCRD_REQUEST 3 X X/* the et parameter to Eval() */ X X#define EVAL_PROCESS (long)0 X#define EVAL_TASK (long)1 X X/* the struct put to a MsgPort by AsyncIn/Rd */ X Xstruct EnvMsg { X struct Message em_msg; X Envelope *em_env; /* ptr to the returned envelope */ X}; X X#ifndef ANSI X/* function returntypes */ X#define NoCopyFunc 0L Xextern Envelope *In(),*Rd(),*Rdp(),*Inp(); Xextern void Out(); Xextern BOOL CopyOut(); Xextern struct Task *Eval(); Xextern struct Task *StartTask(); Xextern struct Process *StartProcess(); Xextern Envelope *AwaitNamedEnvelope(); Xextern Envelope *PollNamedEnvelope(); Xextern BOOL OutEmptyEnvelope(); Xextern Envelope *CreateEnvelope(),*InitEnvelope(); Xextern void DisposeEnvelope(); X/* version 2 additions */ Xextern Envelope *TimedIn(), *TimedRd(); Xextern void AsyncIn(), AsyncRd(); Xextern Envelope *AwaitTimed(); Xextern void AsyncRequest(); Xextern char *UniqueName(); X X#else X/* ANSI function-prototypes, worked with PDC 3.33 */ X#define NoCopyFunc (Envelope *(*cf)())0L Xextern Envelope *In(Envelope *); Xextern Envelope *Rd(Envelope *); Xextern Envelope *Rdp(Envelope *); Xextern Envelope *Inp(Envelope *); Xextern void Out(Envelope *); Xextern BOOL CopyOut(Envelope *); Xextern struct Task *Eval(Envelope *,long,ULONG,long); Xextern struct Task *StartTask(void(),char *,long,long); Xextern struct Process *StartProcess(void(),char *,long,long); Xextern Envelope *AwaitNamedEnvelope(char *); Xextern Envelope *PollNamedEnvelope(char *); Xextern BOOL OutEmptyEnvelope(char *); Xextern Envelope *CreateEnvelope(char *,ULONG); Xextern Envelope *InitEnvelope(Envelope *,char *,ULONG,Envelope *(*copyfunc)()); Xextern void DisposeEnvelope(Envelope *); X/* version 2 additions */ Xextern Envelope *TimedIn(Envelope *,ULONG,ULONG); Xextern Envelope *TimedRd(Envelope *,ULONG,ULONG); Xextern void AsyncIn(Envelope *,struct MsgPort *); Xextern void AsyncRd(Envelope *,struct MsgPort *); Xextern Envelope *AwaitTimed(char *,ULONG,ULONG); Xextern void AsyncRequest(char *,struct MsgPort *); Xextern char *UniqueName(char *); X#endif /* ANSI */ X X#endif /* ODIN_H */ END_OF_FILE if test 3659 -ne `wc -c <'odin.h'`; then echo shar: \"'odin.h'\" unpacked with wrong size! fi # end of 'odin.h' fi if test -f 'odin.i' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'odin.i'\" else echo shar: Extracting \"'odin.i'\" \(1282 characters\) sed "s/^X//" >'odin.i' <<'END_OF_FILE' X;odin2.i X;includefile for odin.library. X;using semaphore instead of spacemanager X;Last updated 27-aug-90 X;Version = 2.3 X X IFND ODIN_I XODIN_I EQU 1 X XodinNAME MACRO X DC.B 'odin.library',0 X CNOP 0,2 X ENDM X X STRUCTURE odin,LIB_SIZE X APTR odin_SegList X UBYTE odin_Flags X UBYTE odin_pad X ;------------------------------------------------ X ;- You must ObtainSemaphore() this before using X ;- WaitList! X ;------------------------------------------------ X STRUCT odin_Sem,SS_SIZE ;signal semaphore X STRUCT odin_WaitList,MLH_SIZE X LABEL odin_Sizeof X X;--- prefix for envelopes X X STRUCTURE Envelope,MLN_SIZE ;first a link for use in e-space X APTR e_name ;ptr to ASCIIZ string X ULONG e_len ;bytelength of contents X APTR e_copyfunc ;opt. C-function for copying X APTR e_proc ;C-function to call in Eval X LABEL e_sizeof X X;--- wait-structure used in WaitList X X STRUCTURE WaitStruct,MLN_SIZE X APTR ow_envelope X APTR ow_waittask X UBYTE ow_sigbit X BYTE ow_type X LABEL ow_sizeof X Xow_replyport EQU ow_waittask X X;--- ow_types X XRD_REQUEST EQU 0 XIN_REQUEST EQU 1 XASYNCIN_REQUEST EQU 2 XASYNCRD_REQUEST EQU 3 X X;--- the et parameter to Eval() X XEVAL_PROCESS EQU 0 XEVAL_TASK EQU 1 X X;--- the struct put to a MsgPort by AsyncIn/AsyncRd X X STRUCTURE EnvMsg,MN_SIZE X APTR em_env; X LABEL em_sizeof X X ENDC !ODIN_I END_OF_FILE if test 1282 -ne `wc -c <'odin.i'`; then echo shar: \"'odin.i'\" unpacked with wrong size! fi # end of 'odin.i' fi if test -f 'odin.uu' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'odin.uu'\" else echo shar: Extracting \"'odin.uu'\" \(5666 characters\) sed "s/^X//" >'odin.uu' <<'END_OF_FILE' Xbegin 666 odin.library XM```#\P`````````$``````````,```-2````%0````\```#D```#Z0```U)P+ XM"DYU2OP````$```-2(`""0`````>````+````$IO9&EN+FQI8G)A2`R+C<@*#(@4V5P(#DP*0T*`````&(```!:````Q@```/(`P XM``%T```!@@```90```'<```'*````>````=8```%1```!C@```'P```"A@``9 XM`S8```=N```$=```!+(```3J```&V```!O8```<4```'E```")8```FP```*[ XM1```"NH```L0```+0O_____@```,"0#````*````'N````X&`-```!0``M``C XM`!8`!\```!@````L`````"\-*D`CP`````0K2``B0_D`````<`!.KOW8(\``C XM````9@HN/(`#@`=.KO^40>T`*$ZN_=)![0!6((A8D$*H``0A2``(0?D````() XM,#P`/R"(6)!"J``$(4@`"$'H``Q1R/_N0?D```,(3J[]TD'Y```#AD*00J@`D XM!!#\`#`@#2I?3G4(K@`#`"92;@`@(`Y.=7``4VX`(&8(""X``P`F80).=4CG< XM(`8J3BQX``1*;0`@9PH([0`#`"9P`&`H)"T`(B)-3J[_!")Y`````$ZN_F)PL XM`")-,"T`$)+`T&T`$DZN_RX@`DS?8`1.=7``3G4C2``((T``#"-*`!`@"4YU8 XM2.<`)BI.)$DL>``$0>T`*$ZN_T`*$ZN_<8@; XM"DS?9`!.=4_O_^XO2@`(+VX!%``,'WP``0`1T`5D'H3 XM``0@*``$(4D`!"*((T``!"!`((E![0`H3J[]QA(O`!!P``/`3J[^PG``$"\`< XM$$ZN_K`@+P`(3^\`$F"82.<`)BI.)$DL>``$0>T`*$ZN_T`*$ZN_<82+P`0<`'CJ$ZN_L)P`!`O`!!.KOZP("\`T XM"$_O`!),WV0`3G5(YP`^*DXD22QX``1![0`H3J[]S")J``AA``A@($DB2D'H: XM``0@*``$(4D`!"*((T``!"!`((E'[0!6)E-*DV<``/`@:P`((&@`"")J``BSY XMR&<*$!BP&6;B2@!F]B)+*$DF42!1(FD`!"*((4D`!$*4$"P`$0P```%F'BE*L XM``@@"F$`"%(2+``0<`'CJ")L``Q.KOZ\8```F@P```!F,$CG`#X@2B)L``A,< XM[WP``!1A``@T3-]\`"E```@2+``0<`'CJ")L``Q.KOZ\8`#_<`P```)F)&$`6 XM"1(O`"`*80`']B!L``PB7R-``!1.KOZ2(DQP$DZN_RY@.$CG`#X@2B)L``A,8 XM[WP``!1A``?:3-]\`"\`80`(U")`(&P`#"-?`!1.KOZ2(DQP$DZN_RY@`/\.V XM0>T`*$ZN_<9,WWP`3G4O"B1)(FH`"$'Z`!1*@F8&3J[_RF`$3J[_T"1?3G4OI XM"DAZ``@O*@`43G58CR)`2H!G"BQY````!$[N_[A.=4CG`"8J3B1)+'@`!$'MW XM`"A.KOW,($IA``<$2H!G%F$`!S@D0$'M`"A.KOW&(`I,WV0`3G5P`&#J2.<`( XM)BI.)$DL>``$0>T`*$ZN_T`*$ZN_<9P`$S?9`!.=2!`B XM(DI,WV0`80`&^$CG``8L>``$*GD````$0>T`*"I`3J[]QB`-3-]@`$YU2.?`' XMPBQX``1!^0```PA.KOW,3-]#`TCY?_\```,X2."9)*``F`2QX( XM``1!^0```!HA0P`43J[_(@B``!]F``":(\````.`)$`D*@`0)&H`&!5\``$`T XM"!5$``DE2P`*)4(`.M2#)4(`/E6")4(`-D'J`$H@B%B00J@`!"%(``@1?``*P XM``QP_TZN_K83P````S9K/"/N`10```-\,_P``0```X0B2BA*1?D`````E\M.& XMKO[F$CD```,V<`'CJ$ZN_L)P`!`Y```#-DZN_K!@#"!Y```#@$ZN_QR9S$'YH XM```#"$ZN_<8@#$S?7!Q.=4CGP,(L>``$0?D```,(3J[]S$S?0P-(^7__```#R XM.$CG/`(CR````W@H`2H))``L>``$`@BQX``0B/``!% XM``%.KO\Z(D!*@&<.3-]!`97*3J[_W"1?3G5,WT$!<`!@]"`)9Q`@*0`,+PXL/ XM>``$3J[_+BQ?3G4O"2!I``@@*0`,3J[_XB)?2H!G$"!)(D!A``22(D!.KO^X' XM<`%.=4CG,"8D`"8!*DXD22QX``1![0`H3J[]S"!*80`$'DJ`9Q9A``12)`!!\ XM[0`H3J[]QB`"3-]D#$YU3^__[B]*``@O;@$4``P??``!`!%P_TZN_K8?0``0Y XM(D]![0!60>@`!"`H``0A20`$(H@C0``$($`@B4'M`"A.KOW&80`$+B1)L_P`Z XM````9W`E0@`@)4,`)#5\``D`'$ZN_C(2+P`0<``#P"0`(&H`#A(H``\#P$ZNT XM_L+`@F8F0J\`"$'M`"A.KOW,2I=G#B)/(%$B:0`$(H@A20`$0>T`*$ZN_<8BX XM2F$`!"YP`!`O`!!.KOZP("\`"$_O`!)@`/\\+WS_____``A@N$CG,"8D`"8!? XM*DXD22QX``1![0`H3J[]S"!*80`#'$J`9RP@0")*3-]D#&$``UA(YP`&*GD`J XM```$+'@`!"I`0>T`*$ZN_<8@#4S?8`!.=4_O_^XO2@`(+VX!%``,'WP````1\ XMT`5D'H``0@*``$(4D`!"*((T``!"!`((E![0`H3J[]3 XMQF$``Q8D2;/\`````&=R)4(`("5#`"0U?``)`!Q.KOXR$B\`$'```\`D`"!J\ XM``X2*``/`\!.KO["P()F)D*O``A![0`H3J[]S")/2I%G#"!1(FD`!"*((4D`+ XM!$'M`"A.KOW&(DIA``,6<``0+P`03J[^L"`O``A/[P`23-]D#$YU+WS_____4 XM``A@MDCG`#XJ3B9()$DL>``$0>T`*$ZN_T`5D'H``0@*``$(4D`!"*((T``!"!`((E@1 XMMB\'+CP``0``3J[_E"X?8*9(YP`^*DXF2"1)+'@`!$'M`"A.KOW,($IA``%PX XM2H!G.B\`80`"MBA`(!](YP`^($`B2DSO?```%&$``9Q,WWP`*4``%"!+(DQ.G XMKOZ20>T`*$ZN_<9,WWP`3G5P$B(\``$``4ZN_SHB0$J`9RHC2@`((TL`#!-\/ XM``,`$4'M`%9!Z``$("@`!"%)``0BB"-```0@0"")8+8O!RX\``$``$ZN_Y0N- XM'V"F+PI/[__H(D](Y\````$+PA!^0```PA.KOW,(%]*&&;\4XA#^0```X80$68$$#P`,%(`+ XM#```.F8&$OP`06`:#```6V8&$OP`86`.#```>V8&$OP`,$H!#^0```X80U XMV6;\0?D```,(3J[]QDS?00`@"$YU<`!R`!(99P30`6#X`D``/\#\``Q#^0``\ XM``C3P$YU2.<`,"1((FH`"&'6L^D`"&``$80``BB1`2H!GX XM2G`H(CP``0`!3J[_.DJ`9S8O`")`0?D````,<`%R`$ZN_D1*@&88(E\3?``%S XM``@C2@`.,WP`*``23-]$`$YU(E]P*$ZN_RXB2F%HD\E,WT0`3G6S_`````!FX XM`DYU+PXL>``$+PE.KOX@(E=.KOX^(E(```7J```&````!A````8<```&*```!D(```92```&% XM7```!G(```9\```&@@``!I````:J```&N@``!L0```C*```+3@``"V````N6E XM```+H```"\8````````#\@```^D````5+'@`!$IY```#A&0```X!!Z``$("@`!"%)``0BB"-```0@0"")+SD```-X$CD```,V<`'CJ")Y[ XM```#?$ZN_KQ,^7__```#.$YU```#[`````8````#````!@```!8````R````\ XM.````$(```!.`````````_(```/J````#V1O'odin_lib.fd' <<'END_OF_FILE' X*---- odin_lib.fd X*---- version.revision = 2.7 X##base _OdinBase X##bias 30 X##public X*---- basic functions XCreateEnvelope(name,size)(A0,D0) XInitEnvelope(envelope,name,len,copyfunc)(A1,A0,D0,A2) XDisposeEnvelope(envelope)(A1) X*---- creation of tasks/processes from procedures XStartTask(procedure,name,pri,stacksize)(A0/A1,D0/D1) XStartProcess(procedure,name,pri,stacksize)(A0/A1,D0/D1) X*---- Linda-like functions XIn(envelope)(A1) XRd(envelope)(A1) XOut(envelope)(A1) XCopyOut(envelope)(A1) XEval(envelope,pri,stacksize,et)(A1,D0/D1/D2) XInp(envelope)(A1) XRdp(envelope)(A1) X*---- ease-of-use functions XAwaitNamedEnvelope(name)(A0) XPollNamedEnvelope(name)(A0) XOutEmptyEnvelope(name)(A0) X*---- version 2 additions XTimedIn(env,secs,micros)(A1,D0/D1) XTimedRd(env,secs,micros)(A1,D0/D1) XAsyncIn(env,port)(A1,A0) XAsyncRd(env,port)(A1,A0) XAwaitTimed(name,secs,micros)(A0,D0/D1) XAsyncRequest(name,port)(A0,D0) XUniqueName(buffer)(A0) X##end END_OF_FILE if test 921 -ne `wc -c <'odin_lib.fd'`; then echo shar: \"'odin_lib.fd'\" unpacked with wrong size! fi # end of 'odin_lib.fd' fi if test -f 'odindemo1.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'odindemo1.c'\" else echo shar: Extracting \"'odindemo1.c'\" \(3331 characters\) sed "s/^X//" >'odindemo1.c' <<'END_OF_FILE' X/***********************************************/ X/* odindemo1.c */ X/* demo of odin.library */ X/* starts 2 new processes and sends envelopes */ X/* back and forth. */ X/* Created 7-Jul-90 by Peter Oerbaek */ X/* This code is in the public domain. */ X/* Link with odinglue.o */ X/***********************************************/ X X/********************************************************************** X A lot of checking is ommited in the code to make it smaller and X easier to read. X**********************************************************************/ X X#include "exec/types.h" X#include "exec/semaphores.h" X#include "stdio.h" X#include "odin.h" X Xstruct OdinBase *OpenLibrary(); Xstruct OdinBase *OdinBase; /* global base pointer */ X Xtypedef struct { X Envelope env; /* envelope-prefix used by odin routines */ X int num; /* package number */ X int stop; /* flag to stop consumers */ X} Pack; X X#define p_sizeof (long)sizeof(Pack) X Xtypedef struct { X Envelope e; /* envelope-prefix */ X char *windowname; /* name of windowfile to open */ X} StartEnv; X X#define se_sizeof (long)sizeof(StartEnv) X X/*** for use around C routines that are not re-entrant ***/ X Xstruct SignalSemaphore ss; X#define CRIT_REG(s) ObtainSemaphore(&ss); { s } ReleaseSemaphore(&ss); X X/**** the body for the processes ************/ X XEnvelope *processbody(se) XStartEnv *se; X{ X FILE *f; X int i,stop; X Pack *p; X X CRIT_REG(f = fopen(se->windowname,"w");) X CRIT_REG(fprintf(f,"Hello world\n");) X do { X p = (Pack *)AwaitNamedEnvelope("a packet"); X stop = p->stop; X CRIT_REG(fprintf(f,"Packet #%d received.\n",p->num);) X DisposeEnvelope(p); X } while(stop == 0); X CRIT_REG(fprintf(f,"Bye, bye...\n");) X Delay(100L); X CRIT_REG(fclose(f);) X return (Envelope *)se; X} X Xmain() X{ X StartEnv *env; X Pack *pack; X int i; X X printf("opening library\n"); X if(!(OdinBase = OpenLibrary("ram:odin.library",0L))) { X printf("Couldn't open odin.library\n"); X exit(20); X } X X /* set up semaphore */ X InitSemaphore(&ss); X X /* Ought to do an AddSemaphore() here, but that doesn't work X * in my ROM (KS 33.180) X */ X X printf("creating new processes\n"); X /* start first process */ X env = (StartEnv *)CreateEnvelope("newprocess1",se_sizeof); X env->e.e_proc = processbody; X env->windowname = "CON:10/10/300/100/Proc1"; X Eval(env,1L,4000L,EVAL_PROCESS); X X /* start next process */ X env = (StartEnv *)CreateEnvelope("newprocess2",se_sizeof); X env->e.e_proc = processbody; X env->windowname = "CON:310/20/300/100/Proc2"; X Eval(env,0L,4000L,EVAL_PROCESS); X X /* send some packages */ X for(i = 0; i < 10; i++) { X pack = (Pack *)CreateEnvelope("a packet",p_sizeof); X pack->num = i; X pack->stop = 0; X Out(pack); X CRIT_REG(printf("packet #%d sent.\n",i);) X } X X /* send the stop-packages */ X CRIT_REG(printf("sending stop-packets.\n");) X pack = (Pack *)CreateEnvelope("a packet",p_sizeof); X pack->stop = 1; X Out(pack); X X pack = (Pack *)CreateEnvelope("a packet",p_sizeof); X pack->stop = 1; X Out(pack); X X CRIT_REG(printf("waiting for process1 to terminate\n");) X DisposeEnvelope(AwaitNamedEnvelope("newprocess1")); X CRIT_REG(printf("waiting for process2 to terminate\n");) X DisposeEnvelope(AwaitNamedEnvelope("newprocess2")); X X printf("closing\n"); X CloseLibrary(OdinBase); X} X END_OF_FILE if test 3331 -ne `wc -c <'odindemo1.c'`; then echo shar: \"'odindemo1.c'\" unpacked with wrong size! fi # end of 'odindemo1.c' fi if test -f 'odinglue.asm' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'odinglue.asm'\" else echo shar: Extracting \"'odinglue.asm'\" \(4169 characters\) sed "s/^X//" >'odinglue.asm' <<'END_OF_FILE' X;odinglue.asm X;Created 4-Jul-90 by Peter Oerbaek X;Last updated 2-Sep-90 by Peter Oerbaek X;This is in the public domain. X;C-interface gluecode for odin.library V2.7 X;Assemble with 'as' for Aztec-C 3.40a or later X;Assemble with Assem/A68K for Lattice / DICE / PDC X;Assembles OK as is with A68K 2.6!!!! X X;public macro ;de-comment this for use with Assem X; XDEF \1 X; endm X X__CreateEnvelope equ -30 X__InitEnvelope equ -36 X__DisposeEnvelope equ -42 X__StartTask equ -48 X__StartProcess equ -54 X__In equ -60 X__Rd equ -66 X__Out equ -72 X__CopyOut equ -78 X__Eval equ -84 X__Inp equ -90 X__Rdp equ -96 X__AwaitNamedEnvelope equ -102 X__PollNamedEnvelope equ -108 X__OutEmptyEnvelope equ -114 X X;--- Version 2 additions X__TimedIn equ -120 X__TimedRd equ -126 X__AsyncIn equ -132 X__AsyncRd equ -138 X__AwaitTimed equ -144 X__AsyncRequest equ -150 X__UniqueName equ -156 X X public _OdinBase ;for use with Manx 'as' X; XREF _OdinBase ;for use with Assem X X_InitEnvelope: X movem.l a2/a6,-(sp) ;a6,a2,pc,env,name,len,copyfunc X move.l 12(sp),a1 X move.l 16(sp),a0 X move.l 20(sp),d0 X move.l 24(sp),a2 X move.l _OdinBase,a6 X jsr __InitEnvelope(a6) X movem.l (sp)+,a2/a6 X rts X public _InitEnvelope X X_In: X moveq.l #__In,d1 X bra.s simplecall X public _In X X_Out: X moveq.l #__Out,d1 X bra.s simplecall X public _Out X X_CopyOut: X moveq.l #__CopyOut,d1 X; bra.s simplecall X public _CopyOut X Xsimplecall: ;call with only parameter in A1 X move.l a6,-(sp) ;a6,pc,env X move.l 8(sp),a1 X move.l _OdinBase,a6 X jsr 0(a6,d1.l) X move.l (sp)+,a6 X rts X X_Rd: X moveq.l #__Rd,d1 X bra.s simplecall X public _Rd X X X_Inp: X moveq.l #__Inp,d1 X bra.s simplecall X public _Inp X X_Rdp: X moveq.l #__Rdp,d1 X bra.s simplecall X public _Rdp X X_Eval: X movem.l d2/a6,-(sp) ;a6,d2,pc,a1,d0,d1,d2 X move.l 12(sp),a1 X movem.l 16(sp),d0-d2 X move.l _OdinBase,a6 X jsr __Eval(a6) X movem.l (sp)+,d2/a6 X rts X public _Eval X X_StartTask: X move.l a6,-(sp) ;a6,pc,proc,name,pri,stack X movem.l 8(sp),a0/a1 X movem.l 16(sp),d0/d1 X move.l _OdinBase,a6 X jsr __StartTask(a6) X move.l (sp)+,a6 X rts X public _StartTask X X_StartProcess: X move.l a6,-(sp) X movem.l 8(sp),a0/a1 X movem.l 16(sp),d0/d1 X move.l _OdinBase,a6 X jsr __StartProcess(a6) X move.l (sp)+,a6 X rts X public _StartProcess X X_AwaitNamedEnvelope: X move.l a6,-(sp) X move.l 8(sp),a0 X move.l _OdinBase,a6 X jsr __AwaitNamedEnvelope(a6) X move.l (sp)+,a6 X rts X public _AwaitNamedEnvelope X X_PollNamedEnvelope: X move.l a6,-(sp) X move.l 8(sp),a0 X move.l _OdinBase,a6 X jsr __PollNamedEnvelope(a6) X move.l (sp)+,a6 X rts X public _PollNamedEnvelope X X_OutEmptyEnvelope: X move.l a6,-(sp) X move.l 8(sp),a0 X move.l _OdinBase,a6 X jsr __OutEmptyEnvelope(a6) X move.l (sp)+,a6 X rts X public _OutEmptyEnvelope X X_CreateEnvelope: X move.l a6,-(sp) ;a6,pc,name,size X move.l 8(sp),a0 X move.l 12(sp),d0 X move.l _OdinBase,a6 X jsr __CreateEnvelope(a6) X move.l (sp)+,a6 X rts X public _CreateEnvelope X X_DisposeEnvelope: X move.l a6,-(sp) X move.l 8(sp),a1 X move.l _OdinBase,a6 X jsr __DisposeEnvelope(a6) X move.l (sp)+,a6 X rts X public _DisposeEnvelope X X;--- version 2 additions X X_TimedIn: X move.l a6,-(sp) ;a6,pc,env,secs,micros X move.l 8(sp),a1 X movem.l 12(sp),d0-d1 X move.l _OdinBase,a6 X jsr __TimedIn(a6) X move.l (sp)+,a6 X rts X public _TimedIn X X_TimedRd: X move.l a6,-(sp) ;a6,pc,env,secs,micros X move.l 8(sp),a1 X movem.l 12(sp),d0-d1 X move.l _OdinBase,a6 X jsr __TimedRd(a6) X move.l (sp)+,a6 X rts X public _TimedRd X X_AsyncIn: X move.l a6,-(sp) ;a6,pc,env,port X move.l 8(sp),a1 X move.l 12(sp),a0 X move.l _OdinBase,a6 X jsr __AsyncIn(a6) X move.l (sp)+,a6 X rts X public _AsyncIn X X_AsyncRd: X move.l a6,-(sp) ;a6,pc,env,port X move.l 8(sp),a1 X move.l 12(sp),a0 X move.l _OdinBase,a6 X jsr __AsyncRd(a6) X move.l (sp)+,a6 X rts X public _AsyncRd X X_AwaitTimed: X move.l a6,-(sp) ;a6,pc,name,secs,micros X move.l 8(sp),a0 X movem.l 12(sp),d0/d1 X move.l _OdinBase,a6 X jsr __AwaitTimed(a6) X move.l (sp)+,a6 X rts X public _AwaitTimed X X_AsyncRequest: X move.l a6,-(sp) ;a6,pc,name,port X move.l 8(sp),a0 X move.l 12(sp),d0 X move.l _OdinBase,a6 X jsr __AsyncRequest(a6) X move.l (sp)+,a6 X rts X public _AsyncRequest X X_UniqueName: X move.l a6,-(sp) ;a6,pc,buffer X move.l 8(sp),a0 X move.l _OdinBase,a6 X jsr __UniqueName(a6) X move.l (sp)+,a6 X rts X public _UniqueName X X end X END_OF_FILE if test 4169 -ne `wc -c <'odinglue.asm'`; then echo shar: \"'odinglue.asm'\" unpacked with wrong size! fi # end of 'odinglue.asm' fi if test -f 'odintest.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'odintest.c'\" else echo shar: Extracting \"'odintest.c'\" \(6800 characters\) sed "s/^X//" >'odintest.c' <<'END_OF_FILE' X/*********************************************************** X* odintest.c * X* Created 12-Jul-90 by Peter Oerbaek * X* This is supposed to be a complete test-suite of the * X* functions in odin.library * X* Modified 13-Jul-90 for ANSI compatibility * X* Modified 23-Aug-90 for testing of version 2 * X************************************************************/ X X#include "exec/types.h" X#include "exec/tasks.h" X#include "exec/semaphores.h" X#include "exec/execbase.h" X#include "odin.h" X#include "stdio.h" X Xvoid *OpenLibrary(); Xstruct Task *FindTask(); Xstruct Message *GetMsg(); Xvoid WaitPort(),FreeMem(),DeletePort(); Xstruct MsgPort *CreatePort(); X Xstruct OdinBase *OdinBase; Xstruct SignalSemaphore ss; X#define CR(s) ObtainSemaphore(&ss); { s } ReleaseSemaphore(&ss); X#define debug(str) CR(printf(str);) X XEnvelope e1,e2,e3,e4; X Xstruct MsgPort *mp; Xstruct EnvMsg *msg; X XEnvelope *my_copyfunc(src,tar) XEnvelope *src,*tar; X{ X int i; X register char *a,*b; X X a = (char *)src; b = (char *)tar; X for(i = 0; i < e_sizeof; i++) { X *a++ = *b++; X } X X return tar; X} X XEnvelope *process1(e) XEnvelope *e; X{ X struct Task *tsk; X Envelope *env; X X debug("process1 started\n"); X CR(printf("lenght = %ld\n",e->e_len);) X X tsk = FindTask(NULL); X X CR(printf("stacksize = %d\n",(int)(tsk->tc_SPUpper - tsk->tc_SPLower));) X CR(printf("pri = %d\n",(int)tsk->tc_Node.ln_Pri);) X CR(printf("taskname=%s\n",tsk->tc_Node.ln_Name);) X X debug("creating envelope\n"); X env = CreateEnvelope("Env2",e_sizeof); X if(env == NULL) { debug("create returned NULL\n"); return e; } X X debug("envelope created\n"); X X Delay(100L); X debug("copyouting\n"); X CopyOut(env); X X Delay(199L); X debug("copy outing with copyfunc\n"); X env->e_copyfunc = my_copyfunc; X CopyOut(env); X X debug("normal out\n"); X Out(env); X X debug("wait for V3\n"); X while(!(env = PollNamedEnvelope("V3"))) { X debug("waiting with poll.\n"); X } X X debug("got V3 dispose\n"); X DisposeEnvelope(env); X X debug("wait for V4 and dispose\n"); X DisposeEnvelope(AwaitNamedEnvelope("V4")); X X debug("wait for task1\n"); X DisposeEnvelope(AwaitNamedEnvelope("V5")); X debug("shake hands\n"); X (void)OutEmptyEnvelope("R1"); X X (void)OutEmptyEnvelope("envelope3"); X X Delay(200L); X (void)OutEmptyEnvelope("envelope4"); X debug("2 envelopes outed\n"); X X (void)OutEmptyEnvelope("te1"); X Delay(300L); X (void)OutEmptyEnvelope("te2"); X X debug("te1 and te2 outed\n"); X X (void)AwaitTimed("never",10L,0L); X debug("awaittaimed timed out after 10 secs\n"); X X return e; X} X Xvoid task1() X{ X (void)OutEmptyEnvelope("V5"); /* shake hands with process */ X DisposeEnvelope(AwaitNamedEnvelope("R1")); X} X Xmain() X{ X Envelope *ptr; X struct Task *tsk; X char buffer[30]; X int i; X X if(!(OdinBase = (struct OdinBase *)OpenLibrary("RAM:odin.library",0L))) X { X printf("couldn't find odin.library.\n"); X exit(20); X } X X mp = CreatePort("testport",0L); X X InitSemaphore(&ss); X X debug("begin\n"); X X debug("test InitEnvelope():\n"); X ptr = InitEnvelope(&e1,"Test",e_sizeof,NoCopyFunc); X debug("init envelope finished\n"); X if(ptr == &e1) { X debug("returnvalue ok.\n"); X if(strcmp(ptr->e_name,"Test") == 0) { X debug("name inited ok\n"); X } else { X debug("name wrong\n"); X } X if(ptr->e_len == e_sizeof && ptr->e_copyfunc == NULL) { X debug("inited ok\n"); X } else { X debug("wrong init\n"); X } X } else { X debug("returned wrong value.\n"); X } X X X debug("test Eval():\n"); X e1.e_proc = process1; X (void)Eval(&e1,(long)0,(ULONG)8000,EVAL_PROCESS); X debug("eval finished\n"); X X debug("test rdp\n"); X (void)InitEnvelope(&e2,"Env2",e_sizeof,NoCopyFunc); X while(!(ptr = Rdp(&e2))) { debug("waiting in rdp\n"); } X if(ptr == &e2) { X debug("rdp returned ok\n"); X } else { X debug("rdp returned wrong\n"); X } X CR(printf("name returned by rdp: %s\n",e2.e_name);) X X debug("test rd\n"); X (void)InitEnvelope(&e2,"Env2",e_sizeof,NoCopyFunc); X ptr = Rd(&e2); X if(ptr == &e2) { X debug("rd returned ok\n"); X } else { X debug("rd returned wrong\n"); X } X CR(printf("name returned by rd: %s\n",ptr->e_name);) X X debug("test In()\n"); X (void)InitEnvelope(&e2,"Env2",e_sizeof,NoCopyFunc); X ptr = In(&e2); X if(ptr != &e2) { X debug("in returned ok\n"); X } else { X debug("in returned wrong\n"); X } X CR(printf("name returned by in: %s\n",ptr->e_name);) X DisposeEnvelope(ptr); X X debug("test AwaitNamedEnvelope()\n"); X ptr = AwaitNamedEnvelope("Env2"); X CR(printf("name returned by Await..: %s\n",ptr->e_name);) X DisposeEnvelope(ptr); X X debug("test rdp with copyfunc\n"); X (void)InitEnvelope(&e2,"Env2",e_sizeof,NoCopyFunc); X while(!(ptr = Rdp(&e2))) { debug("waiting in rdp2\n"); } X if(ptr == &e2) { X debug("rdp2 returned ok\n"); X } else { X debug("rdp2 returned wrong\n"); X } X CR(printf("name returned by rdp2: %s\n",e2.e_name);) X X debug("rd with copyfunc\n"); X (void)InitEnvelope(&e2,"Env2",e_sizeof,NoCopyFunc); X ptr = Rd(&e2); X if(ptr == &e2) { X debug("rd2 returned ok\n"); X } else { X debug("rd2 returned wrong\n"); X } X CR(printf("name returned by rd2: %s\n",e2.e_name);) X X DisposeEnvelope(AwaitNamedEnvelope("Env2")); X X Delay(100L); X Out(CreateEnvelope("V3",e_sizeof)); X X (void)OutEmptyEnvelope("V4"); X X tsk = StartTask(task1,"Task1",0L,4000L); X if(tsk == NULL) { debug("couldn't start task\n"); } X debug("task started\n"); X X /*** version 2 additions ***/ X X (void)InitEnvelope(&e3,"envelope3",e_sizeof,NoCopyFunc); X X /* wait max 5 secs */ X ptr = TimedRd(&e3,5L,0L); X if(ptr == &e3) { X debug("timedrd returned ok\n"); X CR(printf("name returned by TimedRd: %s\n",ptr->e_name);) X } else { X debug("timedrd timed out\n"); X } X X debug("ready for timedin\n"); X ptr = TimedIn(&e3,3L,0L); X if(ptr != 0L) { X debug("timedin returned ok\n"); X CR(printf("name returned by TimedIn: %s\n",ptr->e_name);) X DisposeEnvelope(ptr); X } else { X debug("timedin timed out\n"); X } X X (void)InitEnvelope(&e4,"envelope4",e_sizeof,NoCopyFunc); X AsyncIn(&e4,mp); X X debug("returned from asyncin, waiting\n"); X X WaitPort(mp); X msg = (struct EnvMsg *)GetMsg(mp); X debug("got message\n"); X DisposeEnvelope(msg->em_env); X debug("disposed of envelope\n"); X FreeMem(msg,(long)sizeof(struct EnvMsg)); X debug("freed message\n"); X X ptr = AwaitTimed("te1",1L,0L); X if(ptr != 0L) { X debug("te1 arrived\n"); X DisposeEnvelope(ptr); X } else { X debug("te1 didn't arrive in time\n"); X } X X AsyncRequest("te2",mp); X debug("waiting for te2\n"); X X WaitPort(mp); msg = (struct EnvMsg *)GetMsg(mp); X DisposeEnvelope(msg->em_env); FreeMem(msg,(long)sizeof(struct EnvMsg)); X X /* generate some unique names */ X for(i = 1; i < 200; i++) { X (void)strcpy(buffer,"prefix"); X CR(printf("%s\n",UniqueName(buffer));) X } X X debug("wait for process to die\n"); X (void)AwaitNamedEnvelope("Test"); X debug("exiting\n"); X X DeletePort(mp); X CloseLibrary(OdinBase); X} X END_OF_FILE if test 6800 -ne `wc -c <'odintest.c'`; then echo shar: \"'odintest.c'\" unpacked with wrong size! fi # end of 'odintest.c' fi if test -f 'philosophers.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'philosophers.c'\" else echo shar: Extracting \"'philosophers.c'\" \(3995 characters\) sed "s/^X//" >'philosophers.c' <<'END_OF_FILE' X/*****************************************************************/ X/* philosophers.c */ X/* demo of some of the features of odin.library 2.5 */ X/* Created 6-Jun-90 */ X/* Last modified 27-Aug-90 */ X/* Link with odinglue.o */ X/*****************************************************************/ X X#include "exec/types.h" X#include "exec/semaphores.h" X#include "stdio.h" X#include "odin.h" X Xstruct Library *OpenLibrary(); X X#define PHILONUM 4 /* number of philosophers */ X Xstruct OdinBase *OdinBase; /* the global baseptr */ X X/* structure of allocation-envelope */ Xstruct Forks { X Envelope e; X BOOL inuse[PHILONUM]; X}; X X/* argument for the philosopher processes */ Xstruct PEnv { X Envelope e; X int num; X}; X Xstruct Forks *the_forks; Xstruct SignalSemaphore xx; X X/* protect C-functions that are not re-entrant */ X#define CR(s) ObtainSemaphore(&xx); { s } ReleaseSemaphore(&xx); X#define USE(n) (copy_forks->inuse[n])?printf("%d ",n):printf(" ") X Xchar s[PHILONUM][20]; /* holds the names */ X X/* make name with single-digit suffix */ Xchar *philoname(str,name,num) Xchar *str,*name; Xint num; X{ X register char *s2; X X s2 = str; X while(*name) *s2++ = *name++; X *s2++ = num + '0'; X *s2 = 0; X return str; X} X X/* the body of the new processes, must be re-entrant */ Xstruct PEnv *philosopher(env) Xstruct PEnv *env; X{ X int i,me; X struct Forks *f; X FILE *win; X X me = env->num; X X /* open monitorwindow */ X switch(me) { X case 0: CR(win = fopen("CON:10/10/200/80/Philo0","w");) X break; X case 1: CR(win = fopen("CON:220/10/200/80/Philo1","w");) X break; X case 2: CR(win = fopen("CON:10/115/200/80/Philo2","w");) X break; X case 3: CR(win = fopen("CON:220/115/200/80/Philo3","w");) X break; X default: X break; X } X X /* let each philosopher eat 20 times */ X for(i = 0; i < 20; i++) { X f = (struct Forks *)AwaitNamedEnvelope("Forkalloc"); X while (f->inuse[me] || f->inuse[(me+1) % PHILONUM]) { X Out(f); X f = (struct Forks *)AwaitNamedEnvelope("Forkalloc"); X } X X /* no one used the forks, now sit on them */ X f->inuse[me] = TRUE; X f->inuse[(me+1) % PHILONUM] = TRUE; X X /* allow others to look at me eating */ X Out(f); X X /* eat */ X CR(fprintf(win,"philosopher #%d eating\n",me);) X X /* release the forks */ X f = (struct Forks *)AwaitNamedEnvelope("Forkalloc"); X f->inuse[me] = FALSE; X f->inuse[(me+1) % PHILONUM] = FALSE; X Out(f); X } X CR(fclose(win);) X return(env); X} X Xmain() X{ X int i; X struct PEnv *env; X struct Forks *copy_forks; X X /* set up semaphore to protect C library routines that are */ X /* not re-entrant */ X X InitSemaphore(&xx); X X /* open odin.library */ X OdinBase = (struct OdinBase *)OpenLibrary("RAM:odin.library",0L); X if(OdinBase == NULL) { X printf("Error: Couldn't open odin.library\n"); X exit(10); X } X X /* now create a few philosopher-processes */ X for(i = 0; i < PHILONUM; i++) { X env = (struct PEnv *)CreateEnvelope( X philoname(&s[i][0],"phil#",i), X (ULONG)sizeof(struct PEnv)); X env->e.e_proc = philosopher; X env->num = i; X (void)Eval(env,0L,8000L,EVAL_PROCESS); X } X X /* init the allocation envelope */ X the_forks = (struct Forks *)CreateEnvelope("Forkalloc", X (ULONG)sizeof(struct Forks)); X X for(i = 0; i < PHILONUM; i++) the_forks->inuse[i] = FALSE; X X Out(the_forks); X X copy_forks = (struct Forks *)CreateEnvelope("Forkalloc", X (ULONG)sizeof(struct Forks)); X while((env = (struct PEnv *)PollNamedEnvelope(&s[0][0])) == NULL) { X Rd(copy_forks); X CR( printf("Forks in use: "); X USE(0); X USE(1); X USE(2); X USE(3); X printf("\n"); X ) X } X X DisposeEnvelope(copy_forks); X DisposeEnvelope(env); X X /* now wait for other philosophers to die */ X for(i = 1; i < PHILONUM; i++) { X DisposeEnvelope(AwaitNamedEnvelope(&s[i][0])); X } X X /* get rid of allocation-envelope, wait at most 10 secs */ X DisposeEnvelope(AwaitTimed("Forkalloc",10L,0L)); X CloseLibrary(OdinBase); X} END_OF_FILE if test 3995 -ne `wc -c <'philosophers.c'`; then echo shar: \"'philosophers.c'\" unpacked with wrong size! fi # end of 'philosophers.c' fi if test -f 'readme.uu' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'readme.uu'\" else echo shar: Extracting \"'readme.uu'\" \(4849 characters\) sed "s/^X//" >'readme.uu' <<'END_OF_FILE' Xbegin 666 readme XM4D5!1$U%(&9O2!#;W!Y3W5T*"D@86YD($]U=$5M, XM<'1Y16YV96QO<&4H*2D@:&%V92!C:&%N9V5D"G)E='5R;G1Y<&4L('-O(&ET: XM)W,@;F]W('!O'1E;F1E# XM9"!W:71H('!H:6QO6YA;6EC86QL>2!C86X@8W)E; XM871E(&]R(&1E2P@22!W;W5L9"!L:6ME('1O('1H86YK('1H: XM92!C&ES=#H*"B`@($=/348L, XM($UE=&%38V]P92`H5&AE($1E8G5G9V5R*2!A;F0@038X2PH*+2TM+2TM+2TM. XM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TMI XM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0I214%$344@9F]R(&]D:6XN;&EB2!6,2XQ,2P@,3,M2G5L+3DP+"!296QE87-E(#$*"B`@($]D:6XN;&EB2!P2!I0ID:7-T2!B:6YAG1E8R`G87,G(&%N9"!!-CA+(#(N-@H@("`@("`@("`@("`@("!!2!T;R!B92!I;B!204TZ("HJ*@H*\ XM;V1I;G1E0H*;V1I;F1E;6\Q+F,@("`@4VEM<&QE(&1E;6\*"F1R876]UU XM(&%R92!S;R!L=6-K>2!T;R!H879E(&]N92X*"@I);G1E XM("`@("`@("!P;V5`9&%I;6DN9&L@("`@("`@("`@("AO;&0@861D'tasks.c' <<'END_OF_FILE' X/**************************************************************** X* tasks.c Version 1.0 X* Created 25-aug-90 X* Lists tasks/processes currently running X****************************************************************/ X X#include "exec/types.h" X#include "exec/execbase.h" X#include "stdio.h" X Xstruct MyMem { X char name[80]; X int pri; X ULONG addr; X}; X Xstruct MyMem mem[80]; /* holds max 80 tasks */ X Xextern struct ExecBase *SysBase; X Xvoid main() X{ X struct Task *ptr; X int numtasks; X UWORD *tmp; X ULONG *tmp2; X X numtasks = 0; X X printf("Pri\tTask\tName\n"); X X Forbid(); X ptr = (struct Task *)(SysBase->TaskReady.lh_Head); X while(ptr->tc_Node.ln_Succ != NULL) { X mem[numtasks].pri = (int)ptr->tc_Node.ln_Pri; X mem[numtasks].addr = (ULONG)ptr; X X if(ptr->tc_Node.ln_Name != NULL) { X strcpy(mem[numtasks].name,ptr->tc_Node.ln_Name); X } else { X strcpy(mem[numtasks].name,""); X } X numtasks++; X ptr = (struct Task *)ptr->tc_Node.ln_Succ; X } X ptr = (struct Task *)(SysBase->TaskWait.lh_Head); X while(ptr->tc_Node.ln_Succ != NULL) { X mem[numtasks].pri = (int)ptr->tc_Node.ln_Pri; X mem[numtasks].addr = (ULONG)ptr; X X if(ptr->tc_Node.ln_Name != NULL) { X strcpy(mem[numtasks].name,ptr->tc_Node.ln_Name); X } else { X strcpy(mem[numtasks].name,""); X } X numtasks++; X ptr = (struct Task *)ptr->tc_Node.ln_Succ; X } X Permit(); X X while(--numtasks >= 0) { X printf("%3d",mem[numtasks].pri); X printf("\t%6lx\t%s\n",mem[numtasks].addr,mem[numtasks].name); X } X} X END_OF_FILE if test 1477 -ne `wc -c <'tasks.c'`; then echo shar: \"'tasks.c'\" unpacked with wrong size! fi # end of 'tasks.c' fi echo shar: End of archive 1 \(of 2\). cp /dev/null ark1isdone MISSING="" for I in 1 2 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked both archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mail submissions (sources or binaries) to . Mail comments to the moderator at . Post requests for sources, and general discussion to comp.sys.amiga.