summaryrefslogtreecommitdiff
path: root/utils/LocThread.cpp
diff options
context:
space:
mode:
authorKevin Tang <zhikait@codeaurora.org>2015-09-11 19:40:25 -0700
committerVamana Murthi <vthuniki@codeaurora.org>2015-11-12 13:06:32 +0530
commit2f74f91ac103afe7d92f594c6c57049e1829c773 (patch)
tree968c55b1019b865cf3b670f02ca6ca083c05c0fd /utils/LocThread.cpp
parentf533181bd69fd32a8a49f4138efbe702f5cdc077 (diff)
downloadgps-2f74f91ac103afe7d92f594c6c57049e1829c773.tar.gz
Crash fix with MsgTask API change
Removed tCreate and tAssociate from MsgTask. LocThread now can optionally take a tCreate method. Associator is replaced with *firstMsg* option to MsgTask, which is a more generic option, that can associate or do other set up job at the create of a MsgTask. The current MsgTask doesn't use tCreate, which exposes a slight time window for Location HAL when its MsgTask is NOT associated to DVM heap but a message delivery to DVM could be attempted during this time. Change-Id: Iafd5b91b693baacb9b7064463f8c44f74026f54c CRs-Fixed: 902350
Diffstat (limited to 'utils/LocThread.cpp')
-rw-r--r--utils/LocThread.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/utils/LocThread.cpp b/utils/LocThread.cpp
index ec1e071..19bf101 100644
--- a/utils/LocThread.cpp
+++ b/utils/LocThread.cpp
@@ -37,12 +37,12 @@ class LocThreadDelegate {
pthread_mutex_t mMutex;
int mRefCount;
~LocThreadDelegate();
- LocThreadDelegate(const char* threadName,
+ LocThreadDelegate(LocThread::tCreate creator, const char* threadName,
LocRunnable* runnable, bool joinable);
void destroy();
public:
- static LocThreadDelegate* create(const char* threadName,
- LocRunnable* runnable, bool joinable);
+ static LocThreadDelegate* create(LocThread::tCreate creator,
+ const char* threadName, LocRunnable* runnable, bool joinable);
void stop();
// bye() is for the parent thread to go away. if joinable,
// parent must stop the spawned thread, join, and then
@@ -62,19 +62,28 @@ public:
// However, upon pthread_create failure, the data members
// must be set to indicate failure, e.g. mRunnable, and
// threashold approprietly for destroy(), e.g. mRefCount.
-LocThreadDelegate::LocThreadDelegate(const char* threadName,
- LocRunnable* runnable, bool joinable) :
- mRunnable(runnable), mJoinable(joinable),
+LocThreadDelegate::LocThreadDelegate(LocThread::tCreate creator,
+ const char* threadName, LocRunnable* runnable, bool joinable) :
+ mRunnable(runnable), mJoinable(joinable), mThandle(NULL),
mMutex(PTHREAD_MUTEX_INITIALIZER), mRefCount(2) {
+
+ // set up thread name, if nothing is passed in
+ if (!threadName) {
+ threadName = "LocThread";
+ }
+
// create the thread here, then if successful
// and a name is given, we set the thread name
- if (!pthread_create(&mThandle, NULL, threadMain, this)) {
+ if (creator) {
+ mThandle = creator(threadName, threadMain, this);
+ } else if (pthread_create(&mThandle, NULL, threadMain, this)) {
+ // pthread_create() failed
+ mThandle = NULL;
+ }
+
+ if (mThandle) {
// set thread name
char lname[16];
- const char* defaultName = "LocThread";
- if (!threadName) {
- threadName = defaultName;
- }
int len = sizeof(lname) - 1;
memcpy(lname, threadName, len);
lname[len] = 0;
@@ -99,11 +108,11 @@ LocThreadDelegate::~LocThreadDelegate() {
}
// factory method so that we could return NULL upon failure
-LocThreadDelegate* LocThreadDelegate::create(const char* threadName,
- LocRunnable* runnable, bool joinable) {
+LocThreadDelegate* LocThreadDelegate::create(LocThread::tCreate creator,
+ const char* threadName, LocRunnable* runnable, bool joinable) {
LocThreadDelegate* thread = NULL;
if (runnable) {
- thread = new LocThreadDelegate(threadName, runnable, joinable);
+ thread = new LocThreadDelegate(creator, threadName, runnable, joinable);
if (thread && !thread->isRunning()) {
thread->destroy();
thread = NULL;
@@ -199,11 +208,14 @@ LocThread::~LocThread() {
}
}
-bool LocThread::start(const char* threadName, LocRunnable* runnable, bool joinable) {
- mThread = LocThreadDelegate::create(threadName, runnable, joinable);
-
- // true only if thread is created successfully
- return (NULL != mThread);
+bool LocThread::start(tCreate creator, const char* threadName, LocRunnable* runnable, bool joinable) {
+ bool success = false;
+ if (!mThread) {
+ mThread = LocThreadDelegate::create(creator, threadName, runnable, joinable);
+ // true only if thread is created successfully
+ success = (NULL != mThread);
+ }
+ return success;
}
void LocThread::stop() {