Skip to content

Commit

Permalink
Fix #117: Race with async channel tasks (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
eile committed Apr 26, 2012
1 parent f3ba9a1 commit 6b8d37b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/eq/client/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ void Channel::addStatistic( Event& event )
//---------------------------------------------------------------------------
// operations
//---------------------------------------------------------------------------
void Channel::waitFrameFinished( const uint32_t frame ) const
{
_impl->finishedFrame.waitGE( frame );
}

void Channel::frameClear( const uint128_t& )
{
Expand Down Expand Up @@ -1513,6 +1517,8 @@ void Channel::_unrefFrame( const uint32_t frameNumber )

stats.data.clear();
stats.region = Viewport::FULL;

_impl->finishedFrame = frameNumber;
}

void Channel::_setOutputFrames( const uint32_t nFrames,
Expand Down Expand Up @@ -1965,6 +1971,7 @@ bool Channel::_cmdConfigInit( co::Command& command )
LBASSERT( pvp.hasArea( ));
_impl->initialSize.x() = pvp.w;
_impl->initialSize.y() = pvp.h;
_impl->finishedFrame = window->getCurrentFrame();

reply.result = configInit( packet->initID );

Expand Down
1 change: 1 addition & 0 deletions libs/eq/client/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace detail { class Channel; struct RBStat; }
EQ_API co::CommandQueue* getPipeThreadQueue(); //!< @internal
EQ_API co::CommandQueue* getCommandThreadQueue(); //!< @internal
EQ_API uint32_t getCurrentFrame() const; //!< @internal render thr only
void waitFrameFinished( const uint32_t frame ) const; //!< @internal

/**
* @return true if this channel is stopped, false otherwise.
Expand Down
3 changes: 3 additions & 0 deletions libs/eq/client/detail/channel.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public:
/** The application-declared regions of interest, merged if
necessary to be non overlapping. */
PixelViewports regions;

/** The number of the last finished frame. */
lunchbox::Monitor< uint32_t > finishedFrame;
};

}
Expand Down
21 changes: 21 additions & 0 deletions libs/eq/client/pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "pipe.h"

#include "channel.h"
#include "client.h"
#include "config.h"
#include "exception.h"
Expand Down Expand Up @@ -531,9 +532,29 @@ void Pipe::notifyMapped()
_state = STATE_MAPPED;
}

namespace
{
class WaitFinishedVisitor : public PipeVisitor
{
public:
WaitFinishedVisitor( const uint32_t frame ) : _frame( frame ) {}

virtual VisitorResult visit( Channel* channel )
{
channel->waitFrameFinished( _frame );
return TRAVERSE_CONTINUE;
}

private:
const uint32_t _frame;
};
}

void Pipe::waitFrameFinished( const uint32_t frameNumber ) const
{
_finishedFrame.waitGE( frameNumber );
WaitFinishedVisitor waiter( frameNumber );
accept( waiter );
}

void Pipe::waitFrameLocal( const uint32_t frameNumber ) const
Expand Down

0 comments on commit 6b8d37b

Please sign in to comment.