Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

c++ - Is there anything wrong with passing "this" as an argument to ISR registration?

I am writing a firmware for an esp32 in C++ and I found it to be awesome to pass an object reference as parameter when registering an ISR because I can simply delegate the work from the ISR to the specific object (a resource in this case), managing the resource properties and functionality directly from the class. However, I'm not exactly sure what to look out for when using this technique.

  1. Is there anything inherently wrong with it?
  2. If not, what should one be aware of when doing it?
question from:https://stackoverflow.com/questions/65843029/is-there-anything-wrong-with-passing-this-as-an-argument-to-isr-registration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Is there anything wrong with passing “this” as an argument to ISR registration?

No.

Is there anything inherently wrong with it?

No.

If not, what should one be aware of when doing it?

Object lifetime. Compiler optimization. Resource sharing. Locking. Atomic access. Specific hardware semantics. Additionally, esp32 is a two core platform. The list could go on and there are many books about programming on esp32, about programming in parallel environments and sharing resources between main part of code and interrupt routines. One should be aware of all such programming related topics and also about good code conventions, naming and C++ language.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...