mirror of
https://github.com/jberthold/packman.git
synced 2024-09-11 13:45:24 +03:00
Pack.c should now be thread-safe for unpacking and packing, as its functions pass around an explicitly allocated state. changes should eventually go back into the RTS code (but we need to see the performance first). The PAP case has not been rewritten yet, it should be revised to pack the bitmap instead of tagging the packed stack elements.
55 lines
1.4 KiB
Plaintext
55 lines
1.4 KiB
Plaintext
#include <Cmm.h>
|
|
#include "Errors.h"
|
|
|
|
STRING(debugval, "debugval %d")
|
|
|
|
stg_tryPack (gcptr original, gcptr buffer)
|
|
{
|
|
// args: closure (graph root to serialize)
|
|
// buffer (MutableByteArray to pack into)
|
|
W_ errCode;
|
|
W_ size;
|
|
|
|
MAYBE_GC_PP(stg_tryPack, original, buffer);
|
|
|
|
// assign something to keep cmm reg.allocator happy
|
|
errCode = P_SUCCESS;
|
|
|
|
// call packing function (without giving the TSO, no blocking)
|
|
(size) = ccall pmtryPackToBuffer(original "ptr", buffer "ptr");
|
|
// small values indicate failure (size biased with P_ERRCODEMAX,
|
|
// see Errors.h and Pack.c
|
|
// NB seems Cmm always compares unsigned (wanted to use negative values here)
|
|
if (size < P_ERRCODEMAX ) {
|
|
errCode = size;
|
|
size = 0;
|
|
} else {
|
|
size = size - P_ERRCODEMAX;
|
|
}
|
|
|
|
return (errCode, size);
|
|
}
|
|
|
|
stg_unpack (gcptr buff)
|
|
{
|
|
// args: R1 ByteArray# containing a serialized subgraph
|
|
W_ new;
|
|
W_ errCode;
|
|
|
|
// assign something to keep cmm reg.allocator happy
|
|
new = ghczmprim_GHCziTypes_False_closure;
|
|
errCode = P_SUCCESS;
|
|
|
|
MAYBE_GC_P(stg_unpack, buff);
|
|
|
|
// call packing function
|
|
("ptr" new) = ccall pmUnpackGraphWrapper(buff "ptr", MyCapability() "ptr");
|
|
|
|
if (new <= P_ERRCODEMAX) {
|
|
errCode = new;
|
|
new = ghczmprim_GHCziTypes_False_closure;
|
|
}
|
|
|
|
return (errCode, new);
|
|
}
|