Ticket #366: fork_completion_callback.diff
File fork_completion_callback.diff, 3.8 KB (added by , 7 years ago) |
---|
-
include/InnoTekLIBC/fork.h
60 60 /** The callback is only called in the parent context. */ 61 61 __LIBC_FORK_CTX_PARENT = 1, 62 62 /** The callback is called in both parent and child contexts. */ 63 __LIBC_FORK_CTX_BOTH = 2 63 __LIBC_FORK_CTX_BOTH = 2, 64 /** The mask for the calling context values. */ 65 __LIBC_FORK_CTX_MASK = 0xf, 66 /** Flag for pfnCompletionCallback to add a callback to the end of the 67 * list so that it will be called last. */ 68 __LIBC_FORK_CTX_FLAGS_LAST = 0x1000 64 69 } __LIBC_FORKCTX; 65 70 66 71 /** … … 379 384 * a non zero rc argument indicates failure. 380 385 * @param pvArg Argument to pass to pfnCallback as 3rd argument. 381 386 * @param enmContext __LIBC_FORK_CTX_CHILD, __LIBC_FORK_CTX_PARENT, or 382 * __LIBC_FORK_CTX_BOTH. 387 * __LIBC_FORK_CTX_BOTH. May be ORed with 388 * __LIBC_FORK_CTX_FLAGS_LAST to add the callback to 389 * the end of the list so that it will be called after 390 * all other registered callbacks. 383 391 * 384 392 * @remark Use with care, the memory used to remember these is taken from the 385 393 * fork buffer. -
src/lib/sys/libcfork.c
2199 2199 * a non zero rc argument indicates failure. 2200 2200 * @param pvArg Argument to pass to pfnCallback as 3rd argument. 2201 2201 * @param enmContext __LIBC_FORK_CTX_CHILD, __LIBC_FORK_CTX_PARENT, or 2202 * __LIBC_FORK_CTX_BOTH. 2202 * __LIBC_FORK_CTX_BOTH. May be ORed with 2203 * __LIBC_FORK_CTX_FLAGS_LAST to add the callback to 2204 * the end of the list so that it will be called after 2205 * all other registered callbacks. 2203 2206 * 2204 2207 * @remark Use with care, the memory used to remember these is taken from the 2205 2208 * fork buffer. … … 2219 2222 LIBCLOG_RETURN_INT(rc); 2220 2223 } 2221 2224 2225 int fLast = enmContext & __LIBC_FORK_CTX_FLAGS_LAST; 2226 enmContext &= __LIBC_FORK_CTX_MASK; 2227 2222 2228 /* 2223 2229 * Add it to the completion callbacks. 2224 2230 * These are eating of the buffer from the end of it. … … 2227 2233 pForkHandle->cbBufLeft -= sizeof(__LIBC_FORKCOMPLETIONCALLBACK); 2228 2234 pForkHandle->cCompletionCallbacks++; 2229 2235 pForkHandle->papfnCompletionCallbacks--; 2230 pForkHandle->papfnCompletionCallbacks->pfnCallback = pfnCallback; 2231 pForkHandle->papfnCompletionCallbacks->enmContext = enmContext; 2232 pForkHandle->papfnCompletionCallbacks->pvArg = pvArg; 2236 if (fLast) 2237 { 2238 /* Add to the tail of the list to have it executed last */ 2239 unsigned cCallbacks = pForkHandle->cCompletionCallbacks - 1; 2240 memmove(pForkHandle->papfnCompletionCallbacks, pForkHandle->papfnCompletionCallbacks + 1, 2241 sizeof(__LIBC_FORKCOMPLETIONCALLBACK) * cCallbacks); 2242 pForkHandle->papfnCompletionCallbacks[cCallbacks].pfnCallback = pfnCallback; 2243 pForkHandle->papfnCompletionCallbacks[cCallbacks].enmContext = enmContext; 2244 pForkHandle->papfnCompletionCallbacks[cCallbacks].pvArg = pvArg; 2245 } 2246 else 2247 { 2248 /* Add to the head of the list to have it executed first */ 2249 pForkHandle->papfnCompletionCallbacks->pfnCallback = pfnCallback; 2250 pForkHandle->papfnCompletionCallbacks->enmContext = enmContext; 2251 pForkHandle->papfnCompletionCallbacks->pvArg = pvArg; 2252 } 2233 2253 2234 2254 LIBCLOG_RETURN_INT(0); 2235 2255 }