<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 15, 2018 at 1:19 PM, Sebastian Huber <span dir="ltr"><<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 15/03/18 08:13, Udit agarwal wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Oh yes, i think i misinterpreted your previous suggestion of surrounding the while loop by mutex, it should be the outer while loop. some thing like this?:<br>
while (n > 0) {<br>
        uint32_t random;<br>
        size_t copy;<br>
<br>
        rtems_mutex_lock(&atsam_trng_m<wbr>utex);<br>
</blockquote>
<br></span>
Now you correctly use the mutex to produce 32-bits of random data. Currently the likely user of getrandom() is<br>
<br>
<a href="https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/stdlib/arc4random.c;h=3cccc3ed46a5e9e756d4e216cb7686589eb60993;hb=HEAD#l89" rel="noreferrer" target="_blank">https://sourceware.org/git/git<wbr>web.cgi?p=newlib-cygwin.git;a=<wbr>blob;f=newlib/libc/stdlib/<wbr>arc4random.c;h=3cccc3ed46a5e9e<wbr>756d4e216cb7686589eb60993;hb=<wbr>HEAD#l89</a><br>
<br>
So, you need 12 mutex lock/unlock operations for this. I would protect the while (n > 0) loop with a single mutex lock/unlock.</blockquote><div>Ok,Like this?<br>rtems_mutex_lock(&atsam_trng_mutex);<br>    while (n > 0) {<br>   .........<br>   .........<br>    }<br>rtems_mutex_unlock(&atsam_trng_mutex); <br><br></div><div>Also, will it be ok to keep atsam_trng_mutex even after user has finished using getentropy() i.e when we don't use destroy(&atsam_trng_mutex) at all?<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
-- <br>
Sebastian Huber, embedded brains GmbH<br>
<br>
Address : Dornierstr. 4, D-82178 Puchheim, Germany<br>
Phone   : <a href="tel:%2B49%2089%20189%2047%2041-16" value="+4989189474116" target="_blank">+49 89 189 47 41-16</a><br>
Fax     : <a href="tel:%2B49%2089%20189%2047%2041-09" value="+4989189474109" target="_blank">+49 89 189 47 41-09</a><br>
E-Mail  : <a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brain<wbr>s.de</a><br>
PGP     : Public key available on request.<br>
<br>
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.<br>
<br>
</div></div></blockquote></div><br></div></div>