embassy icon indicating copy to clipboard operation
embassy copied to clipboard

SyncExecutor::poll / set_alarm_callback

Open gobftald opened this issue 1 year ago • 4 comments

Can you help me to understand why that set_alarm_callback need to call in every poll? May be I'm wrong but I think all args of set_alarm_callback are fixed value.

  • alarm is allocated when SyncExecutor was created
  • alarm_callback is a fixed callback routine
  • ctx is always the 'untyped' pointer of the SyncExecutor instance.

I cannot find any method in SyncExecutor implementation for manipulation of those values (alarm and alarm_callback).

It seems that this call is redundant and wastes time.

It would be helpful if you give me some hints why this is necessary.

gobftald avatar Feb 22 '24 18:02 gobftald

It can't be done earlier in new because the user might move the executor, which will invalidate the ctx pointer. Only by the time poll is called we know the executor won't move anymore, thanks to taking &'static self.

Dirbaio avatar Feb 22 '24 18:02 Dirbaio

Clear. Thank you for your quick response. I'm using embassy on 'single core' chip. So in my customised version I can/will put it into 'new'.

gobftald avatar Feb 22 '24 23:02 gobftald

You can't put it into new, the executor moves when you return it, and the user might move it further. It has nothing to do with single/multi-core.

Dirbaio avatar Feb 22 '24 23:02 Dirbaio

I went through the #[main] attribute macro. You are right (of course). Thanks for taking the time to help novices.

gobftald avatar Feb 22 '24 23:02 gobftald

I'm considering this resolved, reopen if not

lulf avatar Mar 21 '24 07:03 lulf