VMS/VMS_Implementations/VMS_impls/VMS__MC_shared_impl

view PR__WL.c @ 286:b02b34681414

VReo V2 -- saves checker and doer fn with the port, where triggered
author Sean Halle <seanhalle@yahoo.com>
date Wed, 10 Jul 2013 14:49:04 -0700
parents 72ffdb11ad8e
children c63b498d0a00
line source
1 /*
2 * Copyright 2010 OpenSourceResearchInstitute
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <malloc.h>
11 #include <inttypes.h>
12 #include <sys/time.h>
14 #include "PR.h"
17 /* MEANING OF WL PI SS int
18 * These indicate which places the function is safe to use. They stand for:
19 * WL: Wrapper Library
20 * PI: Plugin
21 * SS: Startup and Shutdown
22 * int: internal to the PR implementation
23 */
27 /*As of Feb 2013, doesn't use magic number -- only one ID shared across all
28 * langlets
29 */
30 inline
31 int32 *
32 PR__give_ID_from_slave( SlaveVP *animSlv, int32 magicNumber )
33 {
34 return animSlv->ID;
35 }
37 inline
38 int32 *
39 PR__give_ID_from_lang_meta_task( void *_task )
40 { PRMetaTask *task;
41 task = PR_int__give_prolog_of_lang_meta_task(_task);
42 return task->ID;
43 }
45 SlaveVP *
46 PR__give_owner_of_ID( int32 *taskID, SlaveVP *animSlv )
47 {
48 implement_me();
49 //metaTask = lookup( taskID );
50 //return metaTask->slaveAssignedTo;
51 }
53 /*For this implementation of PR, it may not make much sense to have the
54 * system of requests for creating a new processor done this way.. but over
55 * the scope of single-master, multi-master, mult-tasking, OS-implementing,
56 * distributed-memory, and so on, this gives PR implementation a chance to
57 * do stuff before suspend, in the SlaveVP, and in the Master before the plugin
58 * is called, as well as in the lang-lib before this is called, and in the
59 * plugin. So, this gives both PR and language implementations a chance to
60 * intercept at various points and do order-dependent stuff.
61 *Having a standard PRNewPrReqData struc allows the language to create and
62 * free the struc, while PR knows how to get the newSlv if it wants it, and
63 * it lets the lang have lang-specific data related to creation transported
64 * to the plugin.
65 */
66 void
67 PR_WL__send_create_slaveVP_req( void *langReq, int32 *ID, CreateHandler handler,
68 SlaveVP *reqstingSlv, int32 magicNum )
69 { PRReqst req;
71 req.reqType = SlvCreate;
72 req.ID = ID;
73 req.langMagicNumber = magicNum;
74 req.langReq = langReq;
75 req.createHdlr = handler;
76 reqstingSlv->request = &req;
78 PR_WL__suspend_slaveVP_and_send_req( reqstingSlv );
79 }
82 /*
83 *This adds a request to dissipate, then suspends the processor so that the
84 * request handler will receive the request. The request handler is what
85 * does the work of freeing memory and removing the processor from the
86 * language environment's data structures.
87 *The request handler also is what figures out when to shutdown the PR
88 * system -- which causes all the core controller threads to die, and returns from
89 * the call that started up PR to perform the work.
90 *
91 *This form is a bit misleading to understand if one is trying to figure out
92 * how PR works -- it looks like a normal function call, but inside it
93 * sends a request to the request handler and suspends the processor, which
94 * jumps out of the PR_WL__dissipate_slaveVP function, and out of all nestings
95 * above it, transferring the work of dissipating to the request handler,
96 * which then does the actual work -- causing the processor that animated
97 * the call of this function to disappear and the "hanging" state of this
98 * function to just poof into thin air -- the virtual processor's trace
99 * never returns from this call, but instead the virtual processor's trace
100 * gets suspended in this call and all the virt processor's state disap-
101 * pears -- making that suspend the last thing in the Slv's trace.
102 */
103 void
104 PR_WL__send_end_slave_req( void *langReq, RequestHandler handler,
105 SlaveVP *slaveToDissipate, int32 magicNum )
106 { PRReqst req;
108 req.reqType = SlvDissipate;
109 req.langMagicNumber = magicNum;
110 req.handler = handler;
111 // req.nextReqst = slaveToDissipate->request;
112 slaveToDissipate->request = &req;
114 PR_WL__suspend_slaveVP_and_send_req( slaveToDissipate );
115 }
117 inline
118 void
119 PR_WL__send_create_task_req( BirthFn fn, void *initData, void *langReq,
120 int32 *taskID, CreateHandler handler, SlaveVP *animSlv, int32 magicNumber)
121 { PRReqst req;
123 req.reqType = TaskCreate;
124 req.topLevelFn = fn;
125 req.initData = initData;
126 req.ID = taskID;
127 req.langReq = langReq;
128 req.createHdlr = handler;
129 req.langMagicNumber = magicNumber;
130 animSlv->request = &req;
132 PR_WL__suspend_slaveVP_and_send_req( animSlv );
133 }
135 inline
136 void
137 PR_WL__send_end_task_request( void *langReq, RequestHandler handler,
138 SlaveVP *animSlv, int32 magicNum )
139 { PRReqst req;
141 req.reqType = TaskEnd;
142 req.langReq = langReq;
143 req.handler = handler;
144 req.langMagicNumber = magicNum;
145 animSlv->request = &req;
147 PR_WL__suspend_slaveVP_and_send_req( animSlv );
148 }
151 /*This call's name indicates that request is malloc'd -- so req handler
152 * has to free any extra requests tacked on before a send, using this.
153 *
154 * This inserts the semantic-layer's request data into standard PR carrier
155 * request data-struct that is mallocd. The lang request doesn't need to
156 * be malloc'd if this is called inside the same call chain before the
157 * send of the last request is called.
158 *
159 *The request handler has to call PR_int__free_PRReq for any of these
160 */
161 inline void
162 PR_WL__add_lang_request_in_mallocd_PRReqst( void *langReqData,
163 SlaveVP *callingSlv )
164 { PRReqst *req;
165 //WARNING: not updated.. may be buggy
166 req = PR_int__malloc( sizeof(PRReqst) );
167 req->reqType = Language;
168 req->langReq = langReqData;
169 req->nextReqst = callingSlv->request;
170 callingSlv->request = req;
171 }
173 inline
174 int32 *
175 PR_WL__create_taskID_of_size( int32 numInts )
176 { int32 *taskID;
178 taskID = PR_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
179 taskID[0] = numInts;
180 return taskID;
181 }
183 /*This inserts the semantic-layer's request data into standard PR carrier.
184 * PR Request data-struct is allocated on stack of this call & ptr to it sent
185 * to plugin
186 *Then it does suspend, to cause request to be sent.
187 */
188 inline
189 void
190 PR_WL__send_lang_request( void *langReqData, RequestHandler handler,
191 SlaveVP *callingSlv, int32 magicNum )
192 { PRReqst req;
194 req.reqType = Language;
195 req.langMagicNumber = magicNum;
196 req.langReq = langReqData;
197 req.handler = handler;
198 req.nextReqst = callingSlv->request;
199 callingSlv->request = &req;
201 PR_WL__suspend_slaveVP_and_send_req( callingSlv );
202 }
204 inline
205 void
206 PR_WL__send_lang_shutdown_request( SlaveVP *callingSlv, int32 magicNum )
207 { PRReqst req;
209 req.reqType = LangShutdown;
210 req.langMagicNumber = magicNum;
211 req.nextReqst = NULL;
212 callingSlv->request = &req;
214 PR_WL__suspend_slaveVP_and_send_req( callingSlv );
215 }
218 /*This sends a PRLang request -- for probe, exception, and so on..
219 *
220 */
221 inline void
222 PR_WL__send_service_request( void *langReqData, SlaveVP *callingSlv )
223 { PRReqst req;
225 req.reqType = Service;
226 req.langMagicNumber = PRServ_MAGIC_NUMBER;
227 req.langReq = langReqData;
228 req.nextReqst = callingSlv->request; //grab any other preceeding
229 callingSlv->request = &req;
231 PR_WL__suspend_slaveVP_and_send_req( callingSlv );
232 }
234 /*May 2012
235 *To throw exception from wrapper lib or application, first turn
236 * it into a request, then send the request
237 */
238 void
239 PR_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData )
240 { PRReqst req;
241 PRServiceReq langReq;
242 printf("exception");
243 req.reqType = Language;
244 req.langReq = &langReq;
245 req.nextReqst = reqstSlv->request; //gab any other preceeding
246 reqstSlv->request = &req;
248 langReq.msgStr = msgStr;
249 langReq.exceptionData = excpData;
251 PR_WL__suspend_slaveVP_and_send_req( reqstSlv );
252 }