<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi,</p>
<p>no there's no thread safe API to do what you want. You'd need a
new function<br>
</p>
<p>CPLErrorHandler CPLSetErrorHandlerEx2( CPLErrorHandler
pfnErrorHandlerNew, void* pUserData, void** ppOldUserData )</p>
<p>to do that.</p>
<p>But as you mention threads that might compete to set an error
handler, using CPLSetErrorHandlerEx() is probably not the best
strategy. You'd be better with CPLPushErrorHandler() /
CPLPopErrorHandler() that only affects the current thread.</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 12/09/2021 à 16:03, Rajsekar
Manokaran a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CA+4CNMGZsOaKZi_oVe9K7sKBrUkpWSkciapAG0NdL5j-zpbB2w@mail.gmail.com">
<div dir="ltr">
<div>Hi,</div>
<div><br>
</div>
<div>In the gdal rust bindings (<a
href="https://github.com/georust/gdal" target="_blank"
moz-do-not-send="true">https://github.com/georust/gdal</a>),
we're trying to facilitate the use of CPLSetErrorHandlerEx and
related APIs. While setting a handler, we may pass a heap
allocated data pointer to the second argument, which is then
read via the CPLGetErrorHandlerUserData in the handler and
passed to the user.</div>
<div><br>
</div>
<div>However, while removing or setting another handler, we're
unable to find a race-free method to get the associated user
data of the previous handler. This is needed to properly
deallocate the memory.</div>
<div><br>
</div>
<div>Is there an atomic way to get both the previous handler (as
returned by CPLSetErrorHandler), along with the associated
user data? The issue with making two calls, is that another
thread might make changes in between the two calls.</div>
<div><br>
</div>
<div>We could synchronize in our API, but it still has the same
issue if the user parallely used the C APIs directly or via a
different interface.<br>
</div>
<br>
<div>Relevant PR in rust gdal bindings: <a
href="https://github.com/georust/gdal/pull/215"
target="_blank" moz-do-not-send="true">https://github.com/georust/gdal/pull/215</a></div>
<div><br>
</div>
<div>-</div>
<div>Regards</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>