Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43d8a281 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

fix a race condition in undoDequeue(), where 'tail' could be computed incorrectly.

in the undoDequeue() case, 'tail' was recalculated from 'available' and 'head'
however there was a race between this and retireAndLock(), which could cause
'tail' to be recalculated wrongly.

the interesting thing though is that retireAndLock() shouldn't have any impact
on the value of 'tail', which is client-side only attribute.
we fix the race by saving the value of 'tail' before dequeue() and restore it
in the case of undoDequeue(), since we know it doesn't depend on retireAndLock().

Change-Id: I4bcc4d16b6bc4dd93717ee739c603040b18295a0
parent c32cd79d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ protected:
    SharedBufferStack* const mSharedStack;
    const int mNumBuffers;
    const int mIdentity;
    int32_t computeTail() const;

    friend struct Update;
    friend struct QueueUpdate;
@@ -260,8 +261,6 @@ private:
    friend struct DequeueCondition;
    friend struct LockCondition;

    int32_t computeTail() const;

    struct QueueUpdate : public UpdateBase {
        inline QueueUpdate(SharedBufferBase* sbb);
        inline ssize_t operator()();
@@ -288,6 +287,7 @@ private:
    };

    int32_t tail;
    int32_t undoDequeueTail;
    // statistics...
    nsecs_t mDequeueTime[NUM_BUFFER_MAX];
};