399 void AMMNodeBase::SignalActivities() |
399 void AMMNodeBase::SignalActivities() |
400 { |
400 { |
401 TBool awoke = ETrue; |
401 TBool awoke = ETrue; |
402 TInt c = iActivities.Count(); |
402 TInt c = iActivities.Count(); |
403 TNodeNullContext context(*this); |
403 TNodeNullContext context(*this); |
|
404 |
404 //Clean up.. |
405 //Clean up.. |
405 while (awoke && c > 0) |
406 while (awoke) |
406 { |
407 { |
407 awoke = EFalse; |
408 awoke = EFalse; |
408 for (TInt i = c - 1 ; i>=0 ; --i) |
409 for (TInt i = iActivities.Count() - 1 ; i>=0 ; --i) |
409 { |
410 { |
410 //Signal to waiting activities if: |
411 //Signal to waiting activities if: |
411 //1) an event was received (& the state has potentialy changed as a result) |
412 //1) an event was received (& the state has potentialy changed as a result) |
412 //- remember that an activity does not have to get idle as a result of processing an event which changes the state!!!! |
413 //- remember that an activity does not have to get idle as a result of processing an event which changes the state!!!! |
413 //2) another waiting activity awoke == reacted to the signal (& the state has potentialy changed as a result) |
414 //2) another waiting activity awoke == reacted to the signal (& the state has potentialy changed as a result) |
414 //If any signalled activity reacted, the state could change and all other activities need to be signalled again. |
415 //If any signalled activity reacted, the state could change and all other activities need to be signalled again. |
415 context.iNodeActivity = iActivities[i]; |
416 context.iNodeActivity = iActivities[i]; |
416 awoke |= context.iNodeActivity->Signal(context); |
417 awoke |= context.iNodeActivity->Signal(context); |
417 if(context.iNodeActivity->IsIdle()) |
418 } |
418 { |
419 } |
419 iActivities.Remove(i); |
420 |
420 context.iNodeActivity->Destroy(); |
421 for (TInt i = iActivities.Count() - 1 ; i>=0 ; --i) |
421 context.iNodeActivity = NULL; |
422 { |
422 // NOTE: if "aContext.iNodeActivity" is the destroy activity, then deleting |
423 context.iNodeActivity = iActivities[i]; |
423 // it will destroy the node (i.e. "this") as well, so don't put anything after this line ! |
424 if(context.iNodeActivity->IsIdle()) |
424 if (c == 1) |
425 { |
425 { |
426 iActivities.Remove(i); |
426 // c == 1 means that we've just removed the last activity (also means i will be zero) |
427 context.iNodeActivity->Destroy(); |
427 // i == 0 means that this round of signalling parked activities has been completed |
428 context.iNodeActivity = NULL; |
428 // This is effectively safeguarding the access to iActivities which may or may not be |
429 } |
429 // there (based on the note above). The destroy activity will always be placed at the |
|
430 // head of the list, and will therefore be the last to get processed. |
|
431 return; |
|
432 } |
|
433 } |
|
434 } |
|
435 c = iActivities.Count(); |
|
436 } |
430 } |
437 } |
431 } |
438 |
432 |
439 EXPORT_C void AMMNodeBase::AbortActivitiesOriginatedBy(TNodeContextBase& aContext, const TNodeId& aCommsId, TBool aIsNodeBeingDestroyed) |
433 EXPORT_C void AMMNodeBase::AbortActivitiesOriginatedBy(TNodeContextBase& aContext, const TNodeId& aCommsId, TBool aIsNodeBeingDestroyed) |
440 { |
434 { |