(file) Return to SafeHandle.h CVS log (file) (dir) Up to [OMI] / omi / miapi

 1 krisbash 1.1 /*============================================================================
 2               * Copyright (C) Microsoft Corporation, All rights reserved. 
 3               *============================================================================
 4               */
 5              #ifndef _miapi_safehandle_h_
 6              #define _miapi_safehandle_h_
 7              #include <MI.h>
 8              #if !defined(_MSC_VER)
 9              #include <common/linux/sal.h>
10              #endif
11              #include <pal/slist.h>
12              
13              /* Thunk handle manager */
14              typedef struct _ThunkHandleManager 
15              {
16                  SListHead freeList;
17              }
18              ThunkHandleManager;
19              
20              /* Generic version of the client handle */
21              typedef struct _GenericHandle
22 krisbash 1.1 {
23                  MI_Uint64  version;
24                  struct _ThunkHandle *thunkHandle;
25                  void *functionTable;
26              } 
27              GenericHandle;
28              
29              /* Thunk handle sits inbetween the clients handle and the real object that the handle represents */
30              
31              typedef struct _ThunkHandle ThunkHandle;
32              struct _ThunkHandle
33              {
34                  union
35                  {
36                      SListEntry freeListData; /* When free, object is in free list  */
37                      void *object; /* When allocated, object points to real session/operation/etc */
38                  } u;
39              
40                  /* Handle version number.  When accessing handle this is comapred with generic handle version to make sure it matches */
41                  volatile ptrdiff_t version; 
42              
43 krisbash 1.1     ThunkHandleManager *handleManager; /* So we know where this object goes when freed */
44              
45                  volatile ptrdiff_t refcount; /* Refcount & shutdown */
46              
47                  /* Called when the recount goes to zero which means it was also cancelled (shutdown) */
48                  void (*destructor)(_In_ ThunkHandle *thunkHandle);
49              };
50              
51              /* PUBLIC functions for RealHandleFreeList */
52              void ThunkHandleManager_Initialize(_Inout_ ThunkHandleManager *freeList);
53              void ThunkHandleManager_DeInitialize(_Inout_ ThunkHandleManager *freeList);
54              
55              MI_Result ThunkHandleManager_GetHandle(_Inout_ ThunkHandleManager *self, _Outptr_ ThunkHandle **thunkHandle);
56              
57              /* PUBLIC functions for RealHandle */
58              _Check_return_ int ThunkHandle_AddRef(_Inout_ ThunkHandle *thunkHandle);
59              long ThunkHandle_Release(_Inout_ ThunkHandle *thunkHandle);
60              int ThunkHandle_Shutdown(_Inout_ ThunkHandle *thunkHandle, _In_opt_ void (*destructor)(_In_ ThunkHandle *thunkHandle));
61              
62              /* Safely return thunk handle from a generic form.  Call ThunkHandle_Release when finished */
63              void ThunkHandle_FromGeneric(_Inout_ GenericHandle *genericHandle, _Outptr_result_maybenull_ ThunkHandle **thunkHandle);
64 krisbash 1.1 void ThunkHandle_FromGeneric_ForCompletionCallback(_Inout_ GenericHandle *genericHandle, _Outptr_result_maybenull_ ThunkHandle **thunkHandle);
65              
66              #endif /* _miapi_safehandle_h_ */
67              

ViewCVS 0.9.2