Changeset 43879 in vbox for trunk/include
- Timestamp:
- Nov 15, 2012 2:49:23 PM (12 years ago)
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/once.h
r37316 r43879 4 4 5 5 /* 6 * Copyright (C) 2006-20 07Oracle Corporation6 * Copyright (C) 2006-2012 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 31 31 #include <iprt/asm.h> 32 32 #include <iprt/err.h> 33 #include <iprt/list.h> 33 34 34 35 RT_C_DECLS_BEGIN … … 40 41 41 42 /** 43 * Callback that gets executed once. 44 * 45 * @returns IPRT style status code, RTOnce returns this. 46 * 47 * @param pvUser The user parameter. 48 */ 49 typedef DECLCALLBACK(int32_t) FNRTONCE(void *pvUser); 50 /** Pointer to a FNRTONCE. */ 51 typedef FNRTONCE *PFNRTONCE; 52 53 /** 54 * Callback that gets executed on IPRT/process termination. 55 * 56 * @param pvUser The user parameter. 57 * @param fLazyCleanUpOk Indicates whether lazy clean-up is OK (see 58 * initterm.h). 59 */ 60 typedef DECLCALLBACK(void) FNRTONCECLEANUP(void *pvUser, bool fLazyCleanUpOk); 61 /** Pointer to a FNRTONCE. */ 62 typedef FNRTONCECLEANUP *PFNRTONCECLEANUP; 63 64 /** 42 65 * Execute once structure. 43 66 * … … 48 71 { 49 72 /** Event semaphore that the other guys are blocking on. */ 50 RTSEMEVENTMULTI volatile hEventMulti;73 RTSEMEVENTMULTI volatile hEventMulti; 51 74 /** Reference counter for hEventMulti. */ 52 int32_t volatile cEventRefs;53 /** -1 when uninitialized, 1 when initializing (busy) and 2 when done. */54 int32_t volatile iState;75 int32_t volatile cEventRefs; 76 /** See RTONCESTATE. */ 77 int32_t volatile iState; 55 78 /** The return code of pfnOnce. */ 56 int32_t volatile rc; 79 int32_t volatile rc; 80 81 /** Pointer to the clean-up function. */ 82 PFNRTONCECLEANUP pfnCleanUp; 83 /** Argument to hand to the clean-up function. */ 84 void *pvUser; 85 /** Clean-up list entry. */ 86 RTLISTNODE CleanUpNode; 57 87 } RTONCE; 58 88 /** Pointer to a execute once struct. */ … … 94 124 95 125 /** Static initializer for RTONCE variables. */ 96 #define RTONCE_INITIALIZER { NIL_RTSEMEVENTMULTI, 0, RTONCESTATE_UNINITIALIZED, VERR_INTERNAL_ERROR } 97 98 99 /** 100 * Callback that gets executed once. 101 * 102 * @returns IPRT style status code, RTOnce returns this. 103 * 104 * @param pvUser1 The first user parameter. 105 * @param pvUser2 The second user parameter. 106 */ 107 typedef DECLCALLBACK(int32_t) FNRTONCE(void *pvUser1, void *pvUser2); 108 /** Pointer to a FNRTONCE. */ 109 typedef FNRTONCE *PFNRTONCE; 126 #define RTONCE_INITIALIZER \ 127 { NIL_RTSEMEVENTMULTI, 0, RTONCESTATE_UNINITIALIZED, VERR_INTERNAL_ERROR, NULL, NULL, { NULL, NULL } } 128 110 129 111 130 /** … … 118 137 * @param pOnce Pointer to the execute once variable. 119 138 * @param pfnOnce The function to executed once. 120 * @param pvUser1 The first user parameter for pfnOnce. 121 * @param pvUser2 The second user parameter for pfnOnce. 122 */ 123 RTDECL(int) RTOnceSlow(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser1, void *pvUser2); 139 * @param pfnCleanUp The function that will be doing the cleaning up. 140 * Optional. 141 * @param pvUser The user parameter for pfnOnce. 142 */ 143 RTDECL(int) RTOnceSlow(PRTONCE pOnce, PFNRTONCE pfnOnce, FNRTONCECLEANUP pfnCleanUp, void *pvUser); 124 144 125 145 /** … … 132 152 * @param pOnce Pointer to the execute once variable. 133 153 * @param pfnOnce The function to executed once. 134 * @param pvUser1 The first user parameter for pfnOnce. 135 * @param pvUser2 The second user parameter for pfnOnce. 136 */ 137 DECLINLINE(int) RTOnce(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser1, void *pvUser2) 154 * @param pvUser The user parameter for pfnOnce. 155 */ 156 DECLINLINE(int) RTOnce(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser) 138 157 { 139 158 int32_t iState = ASMAtomicUoReadS32(&pOnce->iState); … … 142 161 || iState == RTONCESTATE_DONE_HAVE_SEM )) 143 162 return ASMAtomicUoReadS32(&pOnce->rc); 144 return RTOnceSlow(pOnce, pfnOnce, pvUser1, pvUser2);163 return RTOnceSlow(pOnce, pfnOnce, NULL, pvUser); 145 164 } 165 166 /** 167 * Execute pfnOnce once and register a termination clean-up callback. 168 * 169 * Serializes execution of the pfnOnce function, making sure it's 170 * executed exactly once and that nobody returns from RTOnce before 171 * it has executed successfully. 172 * 173 * @returns IPRT like status code returned by pfnOnce. 174 * 175 * @param pOnce Pointer to the execute once variable. 176 * @param pfnOnce The function to executed once. 177 * @param pfnCleanUp The function that will be doing the cleaning up. 178 * @param pvUser The user parameter for pfnOnce. 179 */ 180 DECLINLINE(int) RTOnceEx(PRTONCE pOnce, PFNRTONCE pfnOnce, PFNRTONCECLEANUP pfnCleanUp, void *pvUser) 181 { 182 int32_t iState = ASMAtomicUoReadS32(&pOnce->iState); 183 if (RT_LIKELY( iState == RTONCESTATE_DONE 184 || iState == RTONCESTATE_DONE_CREATING_SEM 185 || iState == RTONCESTATE_DONE_HAVE_SEM )) 186 return ASMAtomicUoReadS32(&pOnce->rc); 187 return RTOnceSlow(pOnce, pfnOnce, pfnCleanUp, pvUser); 188 } 189 146 190 147 191 /** -
trunk/include/iprt/runtime-loader.h
r36511 r43879 4 4 5 5 /* 6 * Copyright (C) 2008-201 0Oracle Corporation6 * Copyright (C) 2008-2012 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 116 116 * serialised for thread safety. 117 117 */ 118 static DECLCALLBACK(int) rtldrLoadOnce(void * , void *)118 static DECLCALLBACK(int) rtldrLoadOnce(void *) 119 119 { 120 120 RTLDRMOD hLib; … … 145 145 146 146 LogFlowFunc(("\n")); 147 rc = RTOnce(&s_Once, rtldrLoadOnce, NULL , NULL);147 rc = RTOnce(&s_Once, rtldrLoadOnce, NULL); 148 148 LogFlowFunc(("rc = %Rrc\n", rc)); 149 149
Note:
See TracChangeset
for help on using the changeset viewer.