Merge "delete of shared LocApiBase::mMsgTask may cause issues"
This commit is contained in:
commit
5ee0b62e8c
3 changed files with 16 additions and 8 deletions
|
@ -148,7 +148,8 @@ struct LocCloseMsg : public LocMsg {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MsgTask* LocApiBase::mMsgTask;
|
MsgTask* LocApiBase::mMsgTask = nullptr;
|
||||||
|
volatile int32_t LocApiBase::mMsgTaskRefCount = 0;
|
||||||
|
|
||||||
LocApiBase::LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
|
LocApiBase::LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
|
||||||
ContextBase* context) :
|
ContextBase* context) :
|
||||||
|
@ -157,6 +158,7 @@ LocApiBase::LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
|
||||||
{
|
{
|
||||||
memset(mLocAdapters, 0, sizeof(mLocAdapters));
|
memset(mLocAdapters, 0, sizeof(mLocAdapters));
|
||||||
|
|
||||||
|
android_atomic_inc(&mMsgTaskRefCount);
|
||||||
if (nullptr == mMsgTask) {
|
if (nullptr == mMsgTask) {
|
||||||
mMsgTask = new MsgTask("LocApiMsgTask", false);
|
mMsgTask = new MsgTask("LocApiMsgTask", false);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +232,7 @@ void LocApiBase::addAdapter(LocAdapterBase* adapter)
|
||||||
for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) {
|
for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) {
|
||||||
if (mLocAdapters[i] == NULL) {
|
if (mLocAdapters[i] == NULL) {
|
||||||
mLocAdapters[i] = adapter;
|
mLocAdapters[i] = adapter;
|
||||||
mMsgTask->sendMsg(new LocOpenMsg(this, adapter));
|
sendMsg(new LocOpenMsg(this, adapter));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,10 +265,10 @@ void LocApiBase::removeAdapter(LocAdapterBase* adapter)
|
||||||
|
|
||||||
// if we have an empty list of adapters
|
// if we have an empty list of adapters
|
||||||
if (0 == i) {
|
if (0 == i) {
|
||||||
mMsgTask->sendMsg(new LocCloseMsg(this));
|
sendMsg(new LocCloseMsg(this));
|
||||||
} else {
|
} else {
|
||||||
// else we need to remove the bit
|
// else we need to remove the bit
|
||||||
mMsgTask->sendMsg(new LocOpenMsg(this));
|
sendMsg(new LocOpenMsg(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +276,7 @@ void LocApiBase::removeAdapter(LocAdapterBase* adapter)
|
||||||
|
|
||||||
void LocApiBase::updateEvtMask()
|
void LocApiBase::updateEvtMask()
|
||||||
{
|
{
|
||||||
mMsgTask->sendMsg(new LocOpenMsg(this));
|
sendMsg(new LocOpenMsg(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocApiBase::updateNmeaMask(uint32_t mask)
|
void LocApiBase::updateNmeaMask(uint32_t mask)
|
||||||
|
@ -298,7 +300,7 @@ void LocApiBase::updateNmeaMask(uint32_t mask)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mMsgTask->sendMsg(new LocSetNmeaMsg(this, mask));
|
sendMsg(new LocSetNmeaMsg(this, mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocApiBase::handleEngineUpEvent()
|
void LocApiBase::handleEngineUpEvent()
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <gps_extended.h>
|
#include <gps_extended.h>
|
||||||
#include <LocationAPI.h>
|
#include <LocationAPI.h>
|
||||||
#include <MsgTask.h>
|
#include <MsgTask.h>
|
||||||
|
#include <LocSharedLock.h>
|
||||||
#include <log_util.h>
|
#include <log_util.h>
|
||||||
|
|
||||||
namespace loc_core {
|
namespace loc_core {
|
||||||
|
@ -107,6 +108,7 @@ class LocApiBase {
|
||||||
friend struct LocKillMsg;
|
friend struct LocKillMsg;
|
||||||
friend class ContextBase;
|
friend class ContextBase;
|
||||||
static MsgTask* mMsgTask;
|
static MsgTask* mMsgTask;
|
||||||
|
static volatile int32_t mMsgTaskRefCount;
|
||||||
LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
|
LocAdapterBase* mLocAdapters[MAX_ADAPTERS];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -121,7 +123,8 @@ protected:
|
||||||
LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
|
LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
|
||||||
ContextBase* context = NULL);
|
ContextBase* context = NULL);
|
||||||
inline virtual ~LocApiBase() {
|
inline virtual ~LocApiBase() {
|
||||||
if (nullptr != mMsgTask) {
|
android_atomic_dec(&mMsgTaskRefCount);
|
||||||
|
if (nullptr != mMsgTask && 0 == mMsgTaskRefCount) {
|
||||||
mMsgTask->destroy();
|
mMsgTask->destroy();
|
||||||
mMsgTask = nullptr;
|
mMsgTask = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +135,9 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void sendMsg(const LocMsg* msg) const {
|
inline void sendMsg(const LocMsg* msg) const {
|
||||||
mMsgTask->sendMsg(msg);
|
if (nullptr != mMsgTask) {
|
||||||
|
mMsgTask->sendMsg(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inline void destroy() {
|
inline void destroy() {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -29,6 +29,7 @@ libgps_utils_la_h_sources = \
|
||||||
gps_extended.h \
|
gps_extended.h \
|
||||||
loc_gps.h \
|
loc_gps.h \
|
||||||
log_util.h \
|
log_util.h \
|
||||||
|
LocSharedLock.h \
|
||||||
LocUnorderedSetMap.h
|
LocUnorderedSetMap.h
|
||||||
|
|
||||||
libgps_utils_la_c_sources = \
|
libgps_utils_la_c_sources = \
|
||||||
|
|
Loading…
Reference in a new issue