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
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include "TaAfsAdmSvrInternal.h"
23 * VARIABLES __________________________________________________________________
32 } CALLBACKDATA, *LPCALLBACKDATA;
37 LPHASHLIST pListCallbacks;
44 * CALLBACKS __________________________________________________________________
48 void AfsAdmSvr_FreeCallbackData (LPCALLBACKDATA pData)
53 Delete (pData->pAction);
59 void AfsAdmSvr_CallbackManager (void)
62 if ((++l.cManagers) == 1)
64 l.heCallback = CreateEvent (NULL, TRUE, FALSE, TEXT("AfsAdmSvr_CallbackManager Event"));
65 l.pListCallbacks = New (HASHLIST);
71 WaitForSingleObjectEx (l.heCallback, INFINITE, FALSE);
76 // We must ensure that we don't block the server's operations because
77 // a callback doesn't go through; since other operations may need
78 // access to the l.pListCallbacks structure in order to queue new
79 // callbacks, we can't leave it locked by issuing callbacks while
80 // enumerating it. Instead we'll copy the list into a local copy,
81 // clear it, and enumerate that local copy--other threads can then
82 // continue to add new requests to l.pListCallbacks.
86 LPHASHLIST pList = New (HASHLIST);
88 for (pEnum = l.pListCallbacks->FindFirst(); pEnum; pEnum = pEnum->FindNext())
90 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
92 l.pListCallbacks->Remove (pData);
95 ResetEvent (l.heCallback);
98 // Now enumerate that copied list, and issue callbacks for each item.
100 for (pEnum = pList->FindFirst(); pEnum; pEnum = pEnum->FindNext())
102 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
108 AfsAdmSvrCallback_Action (pData->pAction, pData->fFinished);
115 pList->Remove (pData);
116 AfsAdmSvr_FreeCallbackData (pData);
123 if ((--l.cManagers) == 0)
125 Delete (l.pListCallbacks);
126 l.pListCallbacks = NULL;
127 CloseHandle (l.heCallback);
134 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction, DWORD dwRemoveMe)
137 if (l.pListCallbacks)
139 LPCALLBACKDATA pData = New (CALLBACKDATA);
140 memset (pData, 0x00, sizeof(CALLBACKDATA));
142 pData->fFinished = fFinished;
145 pData->pAction = New (ASACTION);
146 memcpy (pData->pAction, pAction, sizeof(ASACTION));
149 l.pListCallbacks->Add (pData);
150 SetEvent (l.heCallback);
156 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction)
158 AfsAdmSvr_PostCallback (Type, fFinished, pAction, 0);
162 void AfsAdmSvr_StopCallbackManagers (void)
167 l.fStopManagers = TRUE;
168 SetEvent (l.heCallback);