initHookRegister() make idempotent and MustSucceed
This commit is contained in:

committed by
Andrew Johnson

parent
ee1a49045a
commit
13d6ca598c
@ -21,6 +21,7 @@
|
|||||||
#include "ellLib.h"
|
#include "ellLib.h"
|
||||||
#include "epicsMutex.h"
|
#include "epicsMutex.h"
|
||||||
#include "epicsThread.h"
|
#include "epicsThread.h"
|
||||||
|
#include "cantProceed.h"
|
||||||
|
|
||||||
#include "initHooks.h"
|
#include "initHooks.h"
|
||||||
|
|
||||||
@ -52,19 +53,26 @@ static void initHookInit(void)
|
|||||||
int initHookRegister(initHookFunction func)
|
int initHookRegister(initHookFunction func)
|
||||||
{
|
{
|
||||||
initHookLink *newHook;
|
initHookLink *newHook;
|
||||||
|
ELLNODE *cur;
|
||||||
|
|
||||||
if (!func) return 0;
|
if (!func) return 0;
|
||||||
|
|
||||||
initHookInit();
|
initHookInit();
|
||||||
|
|
||||||
newHook = (initHookLink *)malloc(sizeof(initHookLink));
|
epicsMutexMustLock(listLock);
|
||||||
if (!newHook) {
|
|
||||||
printf("Cannot malloc a new initHookLink\n");
|
for(cur = ellFirst(&functionList); cur; cur = ellNext(cur)) {
|
||||||
return -1;
|
const initHookLink *fn = CONTAINER(cur, initHookLink, node);
|
||||||
|
if(fn->func==func) {
|
||||||
|
/* silently ignore duplicate */
|
||||||
|
epicsMutexUnlock(listLock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newHook = (initHookLink *)mallocMustSucceed(sizeof(initHookLink), "initHookRegister");
|
||||||
newHook->func = func;
|
newHook->func = func;
|
||||||
|
|
||||||
epicsMutexMustLock(listLock);
|
|
||||||
ellAdd(&functionList, &newHook->node);
|
ellAdd(&functionList, &newHook->node);
|
||||||
epicsMutexUnlock(listLock);
|
epicsMutexUnlock(listLock);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -163,7 +163,11 @@ typedef void (*initHookFunction)(initHookState state);
|
|||||||
*
|
*
|
||||||
* Registers \p func for initHook notifications
|
* Registers \p func for initHook notifications
|
||||||
* \param func Pointer to application's notification function.
|
* \param func Pointer to application's notification function.
|
||||||
* \return 0 if Ok, -1 on error (memory allocation failure).
|
* \return Always zero. (before UNRELEASED could return -1 on allocation failure)
|
||||||
|
*
|
||||||
|
* \since UNRELEASED initHookRegister is idempotent.
|
||||||
|
* Previously, repeated registrations would result
|
||||||
|
* in duplicate calls to the hook function.
|
||||||
*/
|
*/
|
||||||
LIBCOM_API int initHookRegister(initHookFunction func);
|
LIBCOM_API int initHookRegister(initHookFunction func);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user