[ENH][VM] Interpreter>>getThisSession
David T. Lewis
lewis at mail.msen.com
Tue Nov 20 13:24:04 UTC 2001
On Tue, Nov 20, 2001 at 04:26:14AM +0100, Stephan Rudlof wrote:
> David,
>
> I have some remarks and ideas.
>
> From your changeset:
<snip>
> For ensuring that the session identifier is unique among all instances of
> Squeak in a network this is *not* a safe method. But I have to admit: for
> just a *few* instances it should almost always work...
> But imagine a collaboration of thousands of Squeaks...
Yes, I agree. Actually, my change set does not alter the current
method of generating a session ID, it only moves it from FilePlugin
to Interpreter, and puts the actual C code into a macro in the sq.h
file.
> So I´d like to have a sessionID which consists of two parts:
> - a startupSessionID which changes for each startup of the image where it
> belongs to by incrementing it;
> - an imageSessionID which identifies the image used.
>
> Some time ago I´ve implemented the first one by storing it inside the image.
> It is named as sessionID in the attached changeset VM_cachingMissingModules,
> which also contains some other stuff.
This looks like a good approach. Your change set implements sessionID as
a special object, which should work fine. Another approach is to have
a named primitive which answers the session ID as ByteArray of four
elements. You can then think of the "guaranteed unique" session ID as
a ByteArray of arbitrary length, constructed from the four-element
array plus whatever other algorithm you want to use to guarantee uniqueness.
The code for the primitive looks like this:
primitiveGetSession
"Answer the unique session identifier for this Smalltalk instance
running in this OS process. The C integer value is coerced into a
Smalltalk ByteArray to preserve the full range of possible values."
| sessionOop sessionByteArrayPointer size thisSession u idx |
self export: true.
self returnTypeC: 'void'.
self var: 'u' declareC: 'union {int i; unsigned char c[sizeof(unsigned int)];} u'.
self var: 'sessionByteArrayPointer' declareC: 'unsigned char *sessionByteArrayPointer'.
size _ self cCode: 'sizeof(unsigned int)' inSmalltalk: 4.
sessionOop _ interpreterProxy instantiateClass: interpreterProxy classByteArray indexableSize: size.
sessionByteArrayPointer _ interpreterProxy arrayValueOf: sessionOop.
thisSession _ self getThisSessionIdentifier.
self cCode: 'u.i = thisSession'.
self cCode: 'for (idx=0; idx<sizeof(unsigned int); idx++) *(sessionByteArrayPointer + idx) = u.c[idx]'.
interpreterProxy pop: 1; push: sessionOop
getThisSessionIdentifier
^ self cCode: '(extern int) thisSession' inSmalltalk: [nil]
More information about the Squeak-dev
mailing list
|