Merge change 22651 into eclair

* changes:
  Implement java interface for RS shutdown and fix shutdown deadlock with the command fifo.
This commit is contained in:
Android (Google) Code Review
2009-08-25 14:49:55 -07:00
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

View File

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

View File

@@ -25,6 +25,16 @@ LocklessCommandFifo::LocklessCommandFifo()
LocklessCommandFifo::~LocklessCommandFifo()
{
if (!mInShutdown) {
shutdown();
}
free(mBuffer);
}
void LocklessCommandFifo::shutdown()
{
mInShutdown = true;
mSignalToWorker.set();
}
bool LocklessCommandFifo::init(uint32_t sizeInBytes)
@@ -42,6 +52,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes)
return false;
}
mInShutdown = false;
mSize = sizeInBytes;
mPut = mBuffer;
mGet = mBuffer;
@@ -50,7 +61,7 @@ bool LocklessCommandFifo::init(uint32_t sizeInBytes)
return true;
}
uint32_t LocklessCommandFifo::getFreeSpace() const
uint32_t LocklessCommandFifo::getFreeSpace() const
{
int32_t freeSpace = 0;
//dumpState("getFreeSpace");
@@ -115,7 +126,7 @@ const void * LocklessCommandFifo::get(uint32_t *command, uint32_t *bytesData)
{
while(1) {
//dumpState("get");
while(isEmpty()) {
while(isEmpty() && !mInShutdown) {
mSignalToControl.set();
mSignalToWorker.wait();
}
@@ -126,7 +137,7 @@ const void * LocklessCommandFifo::get(uint32_t *command, uint32_t *bytesData)
// non-zero command is valid
return mGet+4;
}
// zero command means reset to beginning.
mGet = mBuffer;
}
@@ -161,7 +172,7 @@ void LocklessCommandFifo::makeSpace(uint32_t bytes)
while(getFreeSpace() < bytes) {
sleep(1);
}
}
void LocklessCommandFifo::dumpState(const char *s) const

View File

@@ -25,13 +25,14 @@ namespace android {
// A simple FIFO to be used as a producer / consumer between two
// threads. One is writer and one is reader. The common cases
// will not require locking. It is not threadsafe for multiple
// will not require locking. It is not threadsafe for multiple
// readers or writers by design.
class LocklessCommandFifo
class LocklessCommandFifo
{
public:
bool init(uint32_t size);
void shutdown();
LocklessCommandFifo();
~LocklessCommandFifo();
@@ -59,6 +60,7 @@ protected:
uint8_t * mBuffer;
uint8_t * mEnd;
uint8_t mSize;
bool mInShutdown;
Signal mSignalToWorker;
Signal mSignalToControl;

View File

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

View File

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