<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Here is where malloc/calloc/free are handled,<br>in a new, somewhat redundant way, that reduces/eliminates the burden at higher levels:<br><br><br>jbook2:src jay$ pwd<br>/dev2/cm3/m3-libs/m3core/src<br>jbook2:src jay$ edit C/Common/CstdlibC.c<br><br><br>M3WRAP_NO_SWITCHING(void*, Cstdlib__malloc, malloc, (WORD_T a), (a))<br>M3WRAP_NO_SWITCHING(void*, Cstdlib__calloc, calloc, (WORD_T a, WORD_T b), (a, b))<br>M3WRAP_RETURN_VOID_NO_SWITCHING(Cstdlib__free, free, (void* a), (a))<br><br><br>Now, if you have other C code that is calling malloc/free, you<br>still need to disable switching around that.<br><br><br>Perhaps all calls to <*extern*> functions should disable/enableswitching.<br>Perhaps.<br>The real answer is though, make sure pthreads and Win32 threads work,<br>and then don't do much to make user threads faster or easier to maintain.<br><br><br>see m3core/src/m3core.h for definitions of those macros.<br>They should be pretty clear.<br>If not, run the C preprocessor over those files and look at the results.<br><br><br>--<br>The traditional correct thing is to wrap Cstdlib.malloc/Cstdlib.free whereever they are called.<br>But I kept finding this missing, got fed up with it, fixed it at a lower level.<br>Is that bad? Maybe. Maybe not.<br>--<br>I wouldn't argue against wrapping all <*extern*> calls with disable/enableswitching.<br>Given that you have to recompile everything to switch between user threads and kernel threads anyway,<br>the compiler could insert these calls only for user threads, perhaps.<br><br><br> - Jay<br><br>> To: jay.krell@cornell.edu<br>> Date: Mon, 18 Apr 2011 19:27:04 -0700<br>> From: mika@async.caltech.edu<br>> CC: m3devel@elegosoft.com<br>> Subject: Re: [M3devel] malloc/free from Modula-3?<br>> <br>> Jay K writes:<br>> >--_f28739e3-2465-450f-b041-5795980d5bfe_<br>> >Content-Type: text/plain; charset="iso-8859-1"<br>> >Content-Transfer-Encoding: quoted-printable<br>> ><br>> ><br>> >And "yes" you need to disable switching around free=2C the same as malloc. =<br>> >And calloc. And realloc.<br>> >The disable switching *might* be at a lower level than you realize=2C so *m=<br>> >ight* not be missing.<br>> >That is=2C it might be in our C wrappers. I can check later.<br>> >=20<br>> > - Jay<br>> <br>> Well in that case someone should remove the<br>> SchedulerPosix.DisableSwitching (etc) from around the mallocs.<br>> <br>> Or are you telling me that perhaps free() is wrapped but malloc() isn't?<br>> That would be... confusing.<br>> <br>> Mika<br>> <br> </body>
</html>