Skip to content

Commit

Permalink
Consider GC free zone when making appData callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Oct 30, 2023
1 parent 34c6673 commit ad245e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions project/include/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ extern bool RpiHardwareDecodeJPeg(I420Callback inCallback, void *inUserData, con

struct IAppDataCallback
{
virtual void beginCallbacks() = 0;
virtual void onAppData(int marker, const uint8 *inBytes,int inLen ) = 0;
virtual void endCallbacks() = 0;
};


Expand Down
23 changes: 21 additions & 2 deletions project/src/common/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4136,8 +4136,9 @@ TEXT_PROP_GET_IDX_PRIME(line_offset,LineOffset,int);
struct ValueAppDataCallback : public IAppDataCallback
{
value cbValue;
bool unblocked;

ValueAppDataCallback(value inValue) : cbValue(inValue) { }
ValueAppDataCallback(value inValue) : cbValue(inValue), unblocked(false) { }

IAppDataCallback *get()
{
Expand All @@ -4146,13 +4147,31 @@ struct ValueAppDataCallback : public IAppDataCallback
return this;
}

void beginCallbacks()
{
unblocked = gc_try_unblocking();
}

void onAppData(int marker, const uint8 *inBytes,int inLen )
{
ByteArray byteArray(inLen);
uint8 *bytes = byteArray.Bytes();
if (bytes)
memcpy(bytes, inBytes, inLen);
val_call2( cbValue, alloc_int(marker), byteArray.mValue );
try
{
val_call2( cbValue, alloc_int(marker), byteArray.mValue );
}
catch(...)
{
// Ignore?
}
}

void endCallbacks()
{
if (unblocked)
gc_enter_blocking();
}

};
Expand Down
11 changes: 8 additions & 3 deletions project/src/common/SurfaceIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,15 @@ static Surface *TryJPEG(FILE *inFile,const uint8 *inData, int inDataLen, IAppDat
if (onAppData)
{
jpeg_saved_marker_ptr marker = cinfo.marker_list;
while(marker)
if (marker)
{
onAppData->onAppData(marker->marker, marker->data, marker->data_length);
marker = marker->next;
onAppData->beginCallbacks();
while(marker)
{
onAppData->onAppData(marker->marker, marker->data, marker->data_length);
marker = marker->next;
}
onAppData->endCallbacks();
}
}

Expand Down

0 comments on commit ad245e9

Please sign in to comment.