[ros-kernel] mmTaskCreate
Mike Nordell
tamlin at algonet.se
Mon Dec 1 03:04:49 CET 2003
Filip Navara wrote:
> Ok, the correct implemention would look like this (warning, not tested!):
Close, but not quite there yet.
- The pointer-to-EVENT-handle can be NULL, in case no event is created.
- The thread HANDLE should be closed after thread successfully created.
- If an EVENT is created, it should be signalled once the user-provided
function has been called, meaning an extra "thunk" function must be put
inbetween - meaning some extra mem must be allocated to provide storage for
EVENT and pfn, later free'd by this "thunk" function.
I believe a more correct (pseudi-ish, and completely without error-checking)
impl. would be something like:
struct foo_t { HANDLE hEvent; DWORD dwInst; pfn_t pfn; };
mmThunk(foo_t* pFoo)
{
HANDLE hEvent = pFoo->hEvent;
DWORD dwInst = pFoo->dwInst;
pfn_t pfn = pFoo->pfn;
free pFoo;
retval = pfn(dwInst);
if (hEvent) { SetEvent(hEvent); }
return retval;
}
mmTaskCreate(LPTASKCALLBACK lpfn, HANDLE *lph, DWORD dwInst)
{
foo_t* pFoo = allocate foo_t (zero-filled)
pFoo->dwInst = dwInst;
pFoo->pfn = pfn;
if (lph) { pFoo->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); }
HANDLE hThread = CreateThread(&mmThunk, pFoo);
if (lph) { *lph = pFoo->hEvent; }
CloseHandle(hThread);
}
/Mike
More information about the Ros-kernel
mailing list