65,208
社区成员
发帖
与我相关
我的任务
分享
#include <jni.h>
#include <cutils/log.h>
#include <utils/threads.h>
#include <utils/RefBase.h>
namespace android {
//------------------------------------------------
class WorkerInterface : public virtual RefBase {
protected:
WorkerInterface() { }
virtual ~WorkerInterface() { }
public:
virtual void loopOnce() = 0;
};
//------------------------------------------------
//------------------------------------------------
// Worker class which will do the job in the Thread
class Worker : public WorkerInterface {
public:
Worker();
virtual ~Worker();
virtual void loopOnce();
};
// Implement of the Worker class
Worker::Worker() {
}
Worker::~Worker() {
}
void Worker::loopOnce() {
ALOGE("+++++++++++++++++++++++++++++Worker::loopOnce");
}
//------------------------------------------------
//------------------------------------------------
// Worker thread class which construct the thread
class WorkerThread: public Thread {
public:
WorkerThread();
virtual bool threadLoop();
private:
sp<WorkerInterface> mWorker;
};
// Implement of the WorkerThread class
WorkerThread::WorkerThread() : Thread(false) {
mWorker = new Worker();
}
bool WorkerThread::threadLoop() {
ALOGD("------------------threadLoop");
// *******************======>下面就是罪恶的报错的地方: Fatal signal 11 (SIGSEGV)
mWorker->loopOnce();
return true;
}
//------------------------------------------------
//------------------------------------------------
JNIEXPORT jint JNICALL Java_me_autotouch_autotouch_Kernel_nativeReadyToRecord(JNIEnv *env, jobject obj) {
sp<WorkerThread> thread = new WorkerThread();
thread->run("WorkerThread", PRIORITY_URGENT_DISPLAY);
while(1);
ALOGD("jni calling end");
return 0;
}
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return JNI_VERSION_1_4;
}
//------------------------------------------------