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
10 #include <afs/param.h>
13 #include "TaAfsAdmSvrInternal.h"
16 * VARIABLES __________________________________________________________________
25 } CALLBACKDATA, *LPCALLBACKDATA;
30 LPHASHLIST pListCallbacks;
37 * CALLBACKS __________________________________________________________________
41 void AfsAdmSvr_FreeCallbackData (LPCALLBACKDATA pData)
46 Delete (pData->pAction);
52 void AfsAdmSvr_CallbackManager (void)
55 if ((++l.cManagers) == 1)
57 l.heCallback = CreateEvent (NULL, TRUE, FALSE, NULL);
58 l.pListCallbacks = New (HASHLIST);
64 WaitForSingleObjectEx (l.heCallback, INFINITE, FALSE);
69 // We must ensure that we don't block the server's operations because
70 // a callback doesn't go through; since other operations may need
71 // access to the l.pListCallbacks structure in order to queue new
72 // callbacks, we can't leave it locked by issuing callbacks while
73 // enumerating it. Instead we'll copy the list into a local copy,
74 // clear it, and enumerate that local copy--other threads can then
75 // continue to add new requests to l.pListCallbacks.
79 LPHASHLIST pList = New (HASHLIST);
80 for (LPENUM pEnum = l.pListCallbacks->FindFirst(); pEnum; pEnum = pEnum->FindNext())
82 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
84 l.pListCallbacks->Remove (pData);
87 ResetEvent (l.heCallback);
90 // Now enumerate that copied list, and issue callbacks for each item.
92 for (pEnum = pList->FindFirst(); pEnum; pEnum = pEnum->FindNext())
94 LPCALLBACKDATA pData = (LPCALLBACKDATA)( pEnum->GetObject() );
100 AfsAdmSvrCallback_Action (pData->pAction, pData->fFinished);
107 pList->Remove (pData);
108 AfsAdmSvr_FreeCallbackData (pData);
115 if ((--l.cManagers) == 0)
117 Delete (l.pListCallbacks);
118 l.pListCallbacks = NULL;
119 CloseHandle (l.heCallback);
126 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction, DWORD dwRemoveMe)
129 if (l.pListCallbacks)
131 LPCALLBACKDATA pData = New (CALLBACKDATA);
132 memset (pData, 0x00, sizeof(CALLBACKDATA));
134 pData->fFinished = fFinished;
137 pData->pAction = New (ASACTION);
138 memcpy (pData->pAction, pAction, sizeof(ASACTION));
141 l.pListCallbacks->Add (pData);
142 SetEvent (l.heCallback);
148 void AfsAdmSvr_PostCallback (CALLBACKTYPE Type, BOOL fFinished, LPASACTION pAction)
150 AfsAdmSvr_PostCallback (Type, fFinished, pAction, 0);
154 void AfsAdmSvr_StopCallbackManagers (void)
159 l.fStopManagers = TRUE;
160 SetEvent (l.heCallback);