* Releases the pinCount of a SessionState entry. If the pinCount * drops to 0, it puts the entry back to the freeList for reuse. */
| 130 | * drops to 0, it puts the entry back to the freeList for reuse. |
| 131 | */ |
| 132 | static void |
| 133 | SessionState_Release(SessionState *acquired) |
| 134 | { |
| 135 | if (!sessionStateInited) |
| 136 | { |
| 137 | Assert(NULL == acquired); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | Assert(NULL != acquired); |
| 142 | Assert(0 < acquired->pinCount); |
| 143 | Assert(acquired->sessionId == gp_session_id || acquired->isModifiedSessionId); |
| 144 | |
| 145 | LWLockAcquire(SessionStateLock, LW_EXCLUSIVE); |
| 146 | |
| 147 | Assert(!isProcessActive); |
| 148 | Assert(acquired->activeProcessCount < acquired->pinCount); |
| 149 | |
| 150 | int pinCount = pg_atomic_sub_fetch_u32((pg_atomic_uint32 *) &acquired->pinCount, 1); |
| 151 | |
| 152 | ereport(gp_sessionstate_loglevel, (errmsg("SessionState_Release: pinCount: %d, activeProcessCount: %d", |
| 153 | pinCount, acquired->activeProcessCount), errprintstack(true))); |
| 154 | |
| 155 | /* Before this point the process should have been deactivated */ |
| 156 | Assert(acquired->activeProcessCount <= acquired->pinCount); |
| 157 | Assert(0 <= acquired->pinCount); |
| 158 | |
| 159 | if (0 == acquired->pinCount) |
| 160 | { |
| 161 | RunawayCleaner_RunawayCleanupDoneForSession(); |
| 162 | |
| 163 | acquired->sessionId = INVALID_SESSION_ID; |
| 164 | |
| 165 | Assert(acquired->runawayStatus == RunawayStatus_NotRunaway); |
| 166 | Assert(CLEANUP_COUNTDOWN_BEFORE_RUNAWAY == acquired->cleanupCountdown); |
| 167 | Assert(0 == acquired->activeProcessCount); |
| 168 | |
| 169 | acquired->sessionVmem = 0; |
| 170 | acquired->runawayStatus = RunawayStatus_NotRunaway; |
| 171 | acquired->sessionVmemRunaway = 0; |
| 172 | acquired->commandCountRunaway = 0; |
| 173 | acquired->cleanupCountdown = CLEANUP_COUNTDOWN_BEFORE_RUNAWAY; |
| 174 | acquired->activeProcessCount = 0; |
| 175 | acquired->idle_start = 0; |
| 176 | acquired->latestCursorCommandId = 0; |
| 177 | acquired->resGroupSlot = NULL; |
| 178 | |
| 179 | #ifdef USE_ASSERT_CHECKING |
| 180 | acquired->isModifiedSessionId = false; |
| 181 | #endif |
| 182 | |
| 183 | SessionState *cur = AllSessionStateEntries->usedList; |
| 184 | SessionState *prev = NULL; |
| 185 | |
| 186 | while (cur != acquired && cur != NULL) |
| 187 | { |
| 188 | prev = cur; |
| 189 | cur = cur->next; |
no test coverage detected