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 <afsconfig.h>
14 #include <afs/param.h>
18 #include "TaAfsAdmSvrInternal.h"
21 * VARIABLES __________________________________________________________________
30 } CALLBACKDATA, *LPCALLBACKDATA;
35 LPHASHLIST pListCallbacks;
42 * CALLBACKS __________________________________________________________________
46 void AfsAdmSvr_FreeCallbackData (LPCALLBACKDATA pData)
51 Delete (pData->pAction);
57 void AfsAdmSvr_CallbackManager (void)
60 if ((++l.cManagers) == 1)
62 l.heCallback = CreateEvent (NULL, TRUE, FALSE, TEXT("AfsAdmSvr_CallbackManager Event"));
63 l.pListCallbacks = New (HASHLIST);
69 WaitForSingleObjectEx (l.heCallback, INFINITE, FALSE);
74 // We must ensure that we don't block the server's operations because
75 // a callback doesn't go through; since other operations may need
76 // access to the l.pListCallbacks structure in order to queue new
77 // callbacks, we can't leave it locked by issuing callbacks while
78 // enumerating it. Instead we'll copy the list into a local copy,
79 // clear it, and enumerate that local copy--other threads can then
80 // continue to add new requests to l.pListCallbacks.
84 LPHASHLIST pList = New (HASHLIST);
86 for (pEnum = l.pListCallbacks->FindFirst(); pEnum; pEnum = pEnum->FindNext())
88 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
90 l.pListCallbacks->Remove (pData);
93 ResetEvent (l.heCallback);
96 // Now enumerate that copied list, and issue callbacks for each item.
98 for (pEnum = pList->FindFirst(); pEnum; pEnum = pEnum->FindNext())
100 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
106 AfsAdmSvrCallback_Action (pData->pAction, pData->fFinished);
113 pList->Remove (pData);
114 AfsAdmSvr_FreeCallbackData (pData);
121 if ((--l.cManagers) == 0)
123 Delete (l.pListCallbacks);
124 l.pListCallbacks = NULL;
125 CloseHandle (l.heCallback);
132 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction, DWORD dwRemoveMe)
135 if (l.pListCallbacks)
137 LPCALLBACKDATA pData = New (CALLBACKDATA);
138 memset (pData, 0x00, sizeof(CALLBACKDATA));
140 pData->fFinished = fFinished;
143 pData->pAction = New (ASACTION);
144 memcpy (pData->pAction, pAction, sizeof(ASACTION));
147 l.pListCallbacks->Add (pData);
148 SetEvent (l.heCallback);
154 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction)
156 AfsAdmSvr_PostCallback (Type, fFinished, pAction, 0);
160 void AfsAdmSvr_StopCallbackManagers (void)
165 l.fStopManagers = TRUE;
166 SetEvent (l.heCallback);