modify choreographer.removeCallback,return int instead of void

This commit is contained in:
侯歌 2024-07-31 10:19:15 +08:00
parent 2a26c4dc44
commit 4e4ed2bfe4
2 changed files with 14 additions and 11 deletions

View File

@ -120,12 +120,12 @@ void Choreographer::postCallbackDelayedInternal(int callbackType,void* action, v
}*/
}
void Choreographer::removeCallbacks(int callbackType,const Runnable* action, void* token){
removeCallbacksInternal(callbackType,(void*)action,token);
int Choreographer::removeCallbacks(int callbackType,const Runnable* action, void* token){
return removeCallbacksInternal(callbackType,(void*)action,token);
}
void Choreographer::removeCallbacksInternal(int callbackType,void* action, void* token){
mCallbackQueues[callbackType]->removeCallbacksLocked(action,token);
int Choreographer::removeCallbacksInternal(int callbackType,void* action, void* token){
return mCallbackQueues[callbackType]->removeCallbacksLocked(action,token);
}
void Choreographer::postCallback(int callbackType,const Runnable& action, void* token){
@ -136,8 +136,8 @@ void Choreographer::postCallbackDelayed(int callbackType,const Runnable& action,
postCallbackDelayedInternal(callbackType,(void*)&action, token, delayMillis);
}
void Choreographer::removeFrameCallback(const FrameCallback& callback){
removeCallbacksInternal(CALLBACK_ANIMATION,(void*)&callback,(void*)FRAME_CALLBACK_TOKEN);
int Choreographer::removeFrameCallback(const FrameCallback& callback){
return removeCallbacksInternal(CALLBACK_ANIMATION,(void*)&callback,(void*)FRAME_CALLBACK_TOKEN);
}
void Choreographer::postFrameCallback(const FrameCallback& callback){
@ -305,8 +305,9 @@ void Choreographer::CallbackQueue::addCallbackLocked(long dueTime,void* action,v
entry->next = callback;
}
void Choreographer::CallbackQueue::removeCallbacksLocked(void* action, void* token) {
int Choreographer::CallbackQueue::removeCallbacksLocked(void* action, void* token) {
CallbackRecord* predecessor = nullptr;
int count = 0;
for (CallbackRecord* callback = mHead; callback != nullptr;) {
CallbackRecord* next = callback->next;
if ( ((((long)token) == FRAME_CALLBACK_TOKEN) && (callback->frameCallback==*(FrameCallback*)action) )
@ -317,12 +318,14 @@ void Choreographer::CallbackQueue::removeCallbacksLocked(void* action, void* tok
} else {
mHead = next;
}
count++;
mChoreographer->recycleCallbackLocked(callback);
} else {
predecessor = callback;
}
callback = next;
}
return count;
}
}//endof namespace

View File

@ -35,7 +35,7 @@ private:
bool hasDueCallbacksLocked(long now)const;
CallbackRecord* extractDueCallbacksLocked(long now);
void addCallbackLocked(long dueTime, void* action,void* token);
void removeCallbacksLocked(void* action, void* token);
int removeCallbacksLocked(void* action, void* token);
};
private:
Looper *mLooper;
@ -51,7 +51,7 @@ private:
static float getRefreshRate();
CallbackRecord* obtainCallbackLocked(long dueTime,void* action,void* token);
void recycleCallbackLocked(CallbackRecord* callback);
void removeCallbacksInternal(int callbackType,void* action, void* token);
int removeCallbacksInternal(int callbackType,void* action, void* token);
void postCallbackDelayedInternal(int callbackType,void* action, void* token, long delayMillis);
void scheduleFrameLocked(long);
protected:
@ -70,8 +70,8 @@ public:
nsecs_t getFrameIntervalNanos()const;
void postCallback(int callbackType,const Runnable& action, void* token);
void postCallbackDelayed(int callbackType,const Runnable& action,void*token,long delayMillis);
void removeCallbacks(int callbackType, const Runnable* action,void*token);
void removeFrameCallback(const FrameCallback& callback);
int removeCallbacks(int callbackType, const Runnable* action,void*token);
int removeFrameCallback(const FrameCallback& callback);
void postFrameCallbackDelayed(const FrameCallback& callback, long delayMillis);
void postFrameCallback(const FrameCallback& callback);
};