VMS/VMS_Implementations/VMS_impls/VMS__MC_shared_impl

view VMS__WL.c @ 248:da08f9717024

Moved VMS_defs__turn_on_and_off.h outside of VMS repo, into project repo
author Sean Halle <seanhalle@yahoo.com>
date Sat, 21 Jul 2012 15:20:40 -0700
parents f1267bc7b342
children f5b110414453
line source
1 /*
2 * Copyright 2010 OpenSourceStewardshipFoundation
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 "VMS.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 VMS implementation
23 */
27 /*For this implementation of VMS, it may not make much sense to have the
28 * system of requests for creating a new processor done this way.. but over
29 * the scope of single-master, multi-master, mult-tasking, OS-implementing,
30 * distributed-memory, and so on, this gives VMS implementation a chance to
31 * do stuff before suspend, in the SlaveVP, and in the Master before the plugin
32 * is called, as well as in the lang-lib before this is called, and in the
33 * plugin. So, this gives both VMS and language implementations a chance to
34 * intercept at various points and do order-dependent stuff.
35 *Having a standard VMSNewPrReqData struc allows the language to create and
36 * free the struc, while VMS knows how to get the newSlv if it wants it, and
37 * it lets the lang have lang-specific data related to creation transported
38 * to the plugin.
39 */
40 void
41 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv )
42 { VMSReqst req;
44 req.reqType = createReq;
45 req.semReqData = semReqData;
46 req.nextReqst = reqstingSlv->requests;
47 reqstingSlv->requests = &req;
49 VMS_int__suspend_slaveVP_and_send_req( reqstingSlv );
50 }
53 /*
54 *This adds a request to dissipate, then suspends the processor so that the
55 * request handler will receive the request. The request handler is what
56 * does the work of freeing memory and removing the processor from the
57 * semantic environment's data structures.
58 *The request handler also is what figures out when to shutdown the VMS
59 * system -- which causes all the core controller threads to die, and returns from
60 * the call that started up VMS to perform the work.
61 *
62 *This form is a bit misleading to understand if one is trying to figure out
63 * how VMS works -- it looks like a normal function call, but inside it
64 * sends a request to the request handler and suspends the processor, which
65 * jumps out of the VMS_WL__dissipate_slaveVP function, and out of all nestings
66 * above it, transferring the work of dissipating to the request handler,
67 * which then does the actual work -- causing the processor that animated
68 * the call of this function to disappear and the "hanging" state of this
69 * function to just poof into thin air -- the virtual processor's trace
70 * never returns from this call, but instead the virtual processor's trace
71 * gets suspended in this call and all the virt processor's state disap-
72 * pears -- making that suspend the last thing in the Slv's trace.
73 */
74 void
75 VMS_WL__send_dissipate_req( SlaveVP *slaveToDissipate )
76 { VMSReqst req;
78 req.reqType = dissipate;
79 req.nextReqst = slaveToDissipate->requests;
80 slaveToDissipate->requests = &req;
82 VMS_int__suspend_slaveVP_and_send_req( slaveToDissipate );
83 }
87 /*This call's name indicates that request is malloc'd -- so req handler
88 * has to free any extra requests tacked on before a send, using this.
89 *
90 * This inserts the semantic-layer's request data into standard VMS carrier
91 * request data-struct that is mallocd. The sem request doesn't need to
92 * be malloc'd if this is called inside the same call chain before the
93 * send of the last request is called.
94 *
95 *The request handler has to call VMS_int__free_VMSReq for any of these
96 */
97 inline void
98 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData,
99 SlaveVP *callingSlv )
100 { VMSReqst *req;
102 req = VMS_int__malloc( sizeof(VMSReqst) );
103 req->reqType = semantic;
104 req->semReqData = semReqData;
105 req->nextReqst = callingSlv->requests;
106 callingSlv->requests = req;
107 }
109 /*This inserts the semantic-layer's request data into standard VMS carrier
110 * request data-struct is allocated on stack of this call & ptr to it sent
111 * to plugin
112 *Then it does suspend, to cause request to be sent.
113 */
114 inline void
115 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv )
116 { VMSReqst req;
118 req.reqType = semantic;
119 req.semReqData = semReqData;
120 req.nextReqst = callingSlv->requests;
121 callingSlv->requests = &req;
123 VMS_int__suspend_slaveVP_and_send_req( callingSlv );
124 }
127 /*May 2012 Not sure what this is.. looks like old idea for VMS semantic
128 * request
129 */
130 inline void
131 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv )
132 { VMSReqst req;
134 req.reqType = VMSSemantic;
135 req.semReqData = semReqData;
136 req.nextReqst = callingSlv->requests; //gab any other preceeding
137 callingSlv->requests = &req;
139 VMS_int__suspend_slaveVP_and_send_req( callingSlv );
140 }
142 /*May 2012
143 *To throw exception from wrapper lib or application, first turn
144 * it into a request, then send the request
145 */
146 void
147 VMS_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData )
148 { VMSReqst req;
149 VMSSemReq semReq;
151 req.reqType = VMSSemantic;
152 req.semReqData = &semReq;
153 req.nextReqst = reqstSlv->requests; //gab any other preceeding
154 reqstSlv->requests = &req;
156 semReq.msgStr = msgStr;
157 semReq.exceptionData = excpData;
159 VMS_int__suspend_slaveVP_and_send_req( reqstSlv );
160 }