Skip to content

Commit 02db75f

Browse files
FIX on SleepQueue (#1151) (#1153) (#1155)
Co-authored-by: Coldwings <coldwings@me.com>
1 parent cba0cf1 commit 02db75f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

thread/thread.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ namespace photon
391391
thread* pop_front()
392392
{
393393
auto ret = q[0];
394+
if (q.size() == 1) {
395+
q.pop_back();
396+
return ret;
397+
}
394398
q[0] = q.back();
395399
q[0]->idx = 0;
396400
q.pop_back();
@@ -409,6 +413,11 @@ namespace photon
409413
}
410414

411415
auto id = obj->idx;
416+
if (q.size() == 1) {
417+
assert(id == 0);
418+
q.pop_back();
419+
return 0;
420+
}
412421
q[obj->idx] = q.back();
413422
q[id]->idx = id;
414423
q.pop_back();
@@ -426,6 +435,7 @@ namespace photon
426435
// compare m_nodes[idx] with parent node.
427436
bool up(int idx)
428437
{
438+
assert(!q.empty());
429439
auto tmp = q[idx];
430440
bool ret = false;
431441
while (idx != 0){
@@ -445,6 +455,7 @@ namespace photon
445455
// compare m_nodes[idx] with child node.
446456
bool down(int idx)
447457
{
458+
assert(!q.empty());
448459
auto tmp = q[idx];
449460
size_t cmpIdx = (idx << 1) + 1;
450461
bool ret = false;

0 commit comments

Comments
 (0)