2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 #include <afs/param.h>
16 #include "TaAfsAdmSvrInternal.h"
19 * VARIABLES __________________________________________________________________
28 } CALLBACKDATA
, *LPCALLBACKDATA
;
33 LPHASHLIST pListCallbacks
;
40 * CALLBACKS __________________________________________________________________
44 void AfsAdmSvr_FreeCallbackData (LPCALLBACKDATA pData
)
49 Delete (pData
->pAction
);
55 void AfsAdmSvr_CallbackManager (void)
58 if ((++l
.cManagers
) == 1)
60 l
.heCallback
= CreateEvent (NULL
, TRUE
, FALSE
, TEXT("AfsAdmSvr_CallbackManager Event"));
61 l
.pListCallbacks
= New (HASHLIST
);
67 WaitForSingleObjectEx (l
.heCallback
, INFINITE
, FALSE
);
72 // We must ensure that we don't block the server's operations because
73 // a callback doesn't go through; since other operations may need
74 // access to the l.pListCallbacks structure in order to queue new
75 // callbacks, we can't leave it locked by issuing callbacks while
76 // enumerating it. Instead we'll copy the list into a local copy,
77 // clear it, and enumerate that local copy--other threads can then
78 // continue to add new requests to l.pListCallbacks.
82 LPHASHLIST pList
= New (HASHLIST
);
84 for (pEnum
= l
.pListCallbacks
->FindFirst(); pEnum
; pEnum
= pEnum
->FindNext())
86 LPCALLBACKDATA pData
= (LPCALLBACKDATA
)( pEnum
->GetObject() );
88 l
.pListCallbacks
->Remove (pData
);
91 ResetEvent (l
.heCallback
);
94 // Now enumerate that copied list, and issue callbacks for each item.
96 for (pEnum
= pList
->FindFirst(); pEnum
; pEnum
= pEnum
->FindNext())
98 LPCALLBACKDATA pData
= (LPCALLBACKDATA
)( pEnum
->GetObject() );
104 AfsAdmSvrCallback_Action (pData
->pAction
, pData
->fFinished
);
111 pList
->Remove (pData
);
112 AfsAdmSvr_FreeCallbackData (pData
);
119 if ((--l
.cManagers
) == 0)
121 Delete (l
.pListCallbacks
);
122 l
.pListCallbacks
= NULL
;
123 CloseHandle (l
.heCallback
);
130 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type
, BOOL fFinished
, LPASACTION pAction
, DWORD dwRemoveMe
)
133 if (l
.pListCallbacks
)
135 LPCALLBACKDATA pData
= New (CALLBACKDATA
);
136 memset (pData
, 0x00, sizeof(CALLBACKDATA
));
138 pData
->fFinished
= fFinished
;
141 pData
->pAction
= New (ASACTION
);
142 memcpy (pData
->pAction
, pAction
, sizeof(ASACTION
));
145 l
.pListCallbacks
->Add (pData
);
146 SetEvent (l
.heCallback
);
152 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type
, BOOL fFinished
, LPASACTION pAction
)
154 AfsAdmSvr_PostCallback (Type
, fFinished
, pAction
, 0);
158 void AfsAdmSvr_StopCallbackManagers (void)
163 l
.fStopManagers
= TRUE
;
164 SetEvent (l
.heCallback
);