am cf207b63: Merge change 22651 into eclair

Merge commit 'cf207b632500d18c9053aa01ea9a1d8ae2d92612' into eclair-plus-aosp

* commit 'cf207b632500d18c9053aa01ea9a1d8ae2d92612':
  Implement java interface for RS shutdown and fix shutdown deadlock with the command fifo.
This commit is contained in:
Jason Sams
2009-08-25 14:52:04 -07:00
committed by Android Git Automerger
6 changed files with 37 additions and 6 deletions

View File

@@ -206,6 +206,13 @@ public class RenderScript {
} }
} }
public void destroy() {
nContextDestroy(mContext);
mContext = 0;
nDeviceDestroy(mDev);
mDev = 0;
}
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// Triangle Mesh // Triangle Mesh

View File

@@ -243,11 +243,13 @@ void * Context::threadProc(void *vrsc)
} }
} }
LOGV("RS Thread exiting");
glClearColor(0,0,0,0); glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
eglTerminate(rsc->mEGL.mDisplay); eglTerminate(rsc->mEGL.mDisplay);
rsc->objDestroyOOBRun(); rsc->objDestroyOOBRun();
LOGV("RS Thread exited");
return NULL; return NULL;
} }
@@ -298,9 +300,11 @@ Context::Context(Device *dev, Surface *sur, bool useDepth)
Context::~Context() Context::~Context()
{ {
LOGV("Context::~Context");
mExit = true; mExit = true;
void *res; void *res;
mIO.shutdown();
int status = pthread_join(mThreadId, &res); int status = pthread_join(mThreadId, &res);
objDestroyOOBRun(); objDestroyOOBRun();

View File

@@ -25,6 +25,16 @@ LocklessCommandFifo::LocklessCommandFifo()
LocklessCommandFifo::~LocklessCommandFifo() LocklessCommandFifo::~LocklessCommandFifo()
{ {
if (!mInShutdown) {
shutdown();
}
free(mBuffer);
}
void LocklessCommandFifo::shutdown()
{
mInShutdown = true;
mSignalToWorker.set();
} }
bool LocklessCommandFifo::init(uint32_t sizeInBytes) bool LocklessCommandFifo::init(uint32_t sizeInBytes)
@@ -42,6 +52,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes)
return false; return false;
} }
mInShutdown = false;
mSize = sizeInBytes; mSize = sizeInBytes;
mPut = mBuffer; mPut = mBuffer;
mGet = mBuffer; mGet = mBuffer;
@@ -115,7 +126,7 @@ const void * LocklessCommandFifo::get(uint32_t *command, uint32_t *bytesData)
{ {
while(1) { while(1) {
//dumpState("get"); //dumpState("get");
while(isEmpty()) { while(isEmpty() && !mInShutdown) {
mSignalToControl.set(); mSignalToControl.set();
mSignalToWorker.wait(); mSignalToWorker.wait();
} }

View File

@@ -32,6 +32,7 @@ class LocklessCommandFifo
{ {
public: public:
bool init(uint32_t size); bool init(uint32_t size);
void shutdown();
LocklessCommandFifo(); LocklessCommandFifo();
~LocklessCommandFifo(); ~LocklessCommandFifo();
@@ -59,6 +60,7 @@ protected:
uint8_t * mBuffer; uint8_t * mBuffer;
uint8_t * mEnd; uint8_t * mEnd;
uint8_t mSize; uint8_t mSize;
bool mInShutdown;
Signal mSignalToWorker; Signal mSignalToWorker;
Signal mSignalToControl; Signal mSignalToControl;

View File

@@ -30,6 +30,11 @@ ThreadIO::~ThreadIO()
{ {
} }
void ThreadIO::shutdown()
{
mToCore.shutdown();
}
bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand) bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand)
{ {
bool ret = false; bool ret = false;

View File

@@ -31,6 +31,8 @@ public:
ThreadIO(); ThreadIO();
~ThreadIO(); ~ThreadIO();
void shutdown();
// Plays back commands from the client. // Plays back commands from the client.
// Returns true if any commands were processed. // Returns true if any commands were processed.
bool playCoreCommands(Context *con, bool waitForCommand); bool playCoreCommands(Context *con, bool waitForCommand);