is strstr_P() a reentrant function??

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everybody.

 

I need to find a string inside another string in a ISR. Anybody know if the strstr() or strstr_P() function is reentrant?

 

Thank you very much.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd expect them to be, but so far as I know,

C makes no promises in that regard.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Should not ever call generic lib routines nor do lengthy string work in an ISR. Flag and mark for non-ISR to work on the shared data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't see it using any static memory buffers or anything similar; it should be safe...

http://svn.savannah.nongnu.org/v...

http://svn.savannah.nongnu.org/v...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Probably not on mega AVR devices with >64K flash because the RAMPZ register could become altered.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will consider it is thread safe if it does not use any static memory buffers or anything similar.

 

Thank you very much. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One could also just plunk an equivalent source into the ISR and remove doubts about a particular toolchain implementation.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely westfw's (2nd) link in post #4 is unequivocal? That is the Asm source of strstr_P. As you can see there is no local state information held in it. It does pretty much exactly what you would expect it to be doing: a sliding compare using LD X+ for the RAm and (E)LPM Z+ for the flash with everything held locally in registers.

 

EDIT: but is this an "OS" you are talking about or just the simple possibility of an ISR() calling strstr_P while a foreground task was already inside it? If the latter are you sure you want to be doing strstr_P's in an ISR anyway?

Last Edited: Wed. Jun 1, 2016 - 10:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not have any "OS". I have a ISR calling strstr_P() while a foreground main task occasionally could be inside it. If it in not sure, I can program an equivalent function.

 

Anybody can ensure that asm code use any global variable? I do not have knowledge about that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Probably not on mega AVR devices with >64K flash because the RAMPZ register could become altered.

Good point.   I don't think that any of the _P functions mess with RAMPZ, though.  (Which makes using PROGMEM on an Arduino MEGA rather annoying; all the libraries and etc use the _P functions or otherwise assume that flash in the the first 64kwords.
https://github.com/arduino/Ardui... )