Skip to content

Commit 5933a76

Browse files
committed
TS: Use finite timeout only when threadqueue has run empty
Before the timeout constant was used always, such that ThreadGroupGetDFR waited at least once with the timeout for the case the thread queue was read empty. This wait is not necessary as the thread queue can be checked for emptiness also with a zero timeout. TS_GetNewestFromThreadQueue and TS_GetNewestFromThreadQueueMult use now a timeout of zero for reading the thread queue empty and for the then first check of emptyness, where ThreadGroupGetDFR returns a null DFR. Only further read attempts, if timeout_retries are set, use the TS_GET_REPEAT_TIMEOUT_IN_MS.
1 parent 2b0dfa1 commit 5933a76

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Packages/MIES/MIES_ThreadsafeUtilities.ipf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static Constant TS_ERROR_INVALID_TGID = 980 // Invalid Thread Group ID or
1919
/// Throws away anything else in the datafolder from the thread queue.
2020
Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable timeout_default, variable timeout_tries])
2121

22-
variable var, err, i
22+
variable var, err, i, timeout
2323

2424
ASSERT_TS(!isEmpty(varName), "varName must not be empty")
2525

@@ -41,7 +41,7 @@ Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable ti
4141

4242
for(i = 0; i < timeout_tries; i += 1)
4343
AssertOnAndClearRTError()
44-
DFREF dfr = ThreadGroupGetDFR(tgID, TS_GET_REPEAT_TIMEOUT_IN_MS); err = GetRTError(1)
44+
DFREF dfr = ThreadGroupGetDFR(tgID, timeout); err = GetRTError(1)
4545

4646
if(err)
4747
ASSERT(err == TS_ERROR_INVALID_TGID, "Unexpected error value of " + num2str(err))
@@ -54,8 +54,11 @@ Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable ti
5454
elseif(TS_ThreadGroupFinished(tgID))
5555
return NaN
5656
else
57+
timeout = TS_GET_REPEAT_TIMEOUT_IN_MS
5758
continue
5859
endif
60+
else
61+
timeout = 0
5962
endif
6063

6164
NVAR/Z/SDFR=dfr var_thread = $varName
@@ -77,7 +80,7 @@ End
7780
/// Throws away anything else in the datafolder from the thread queue.
7881
Function/WAVE TS_GetNewestFromThreadQueueMult(variable tgID, WAVE/T varNames, [variable timeout_default, variable timeout_tries])
7982

80-
variable numEntries, i, j, oneValidEntry, err
83+
variable numEntries, i, j, oneValidEntry, err, timeout
8184
string varName
8285

8386
ASSERT_TS(DimSize(varNames, COLS) == 0, "Expected a 1D wave")
@@ -108,7 +111,7 @@ Function/WAVE TS_GetNewestFromThreadQueueMult(variable tgID, WAVE/T varNames, [v
108111

109112
for(i = 0; i < timeout_tries; i += 1)
110113
AssertOnAndClearRTError()
111-
DFREF dfr = ThreadGroupGetDFR(tgID, TS_GET_REPEAT_TIMEOUT_IN_MS); err = GetRTError(1)
114+
DFREF dfr = ThreadGroupGetDFR(tgID, timeout); err = GetRTError(1)
112115

113116
if(err)
114117
ASSERT(err == TS_ERROR_INVALID_TGID, "Unexpected error value of " + num2str(err))
@@ -119,12 +122,15 @@ Function/WAVE TS_GetNewestFromThreadQueueMult(variable tgID, WAVE/T varNames, [v
119122
if(TS_ThreadGroupFinished(tgID))
120123
return $""
121124
elseif(!oneValidEntry)
125+
timeout = TS_GET_REPEAT_TIMEOUT_IN_MS
122126
continue
123127
endif
124128

125129
return result
126130
endif
127131

132+
timeout = 0
133+
128134
for(j = 0; j < numEntries; j += 1)
129135
NVAR/Z/SDFR=dfr var = $GetDimLabel(result, ROWS, j)
130136

0 commit comments

Comments
 (0)