/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace Dali
{
-
namespace Integration
{
-
-LocklessBuffer::LocklessBuffer( uint32_t size )
-: mState( R0W1 ),
- mSize( size )
+LocklessBuffer::LocklessBuffer(uint32_t size)
+: mState(R0W1),
+ mSize(size)
{
// allocate memory to speed up operation
mBuffer[0] = new uint8_t[size];
mBuffer[1] = new uint8_t[size];
- memset (mBuffer[0], 0, size );
- memset (mBuffer[1], 0, size );
+ memset(mBuffer[0], 0, size);
+ memset(mBuffer[1], 0, size);
}
LocklessBuffer::~LocklessBuffer()
delete[] mBuffer[1];
}
-void LocklessBuffer::Write( const uint8_t *src, uint32_t size )
+void LocklessBuffer::Write(const uint8_t* src, uint32_t size)
{
- DALI_ASSERT_ALWAYS( size <= mSize );
+ DALI_ASSERT_ALWAYS(size <= mSize);
// set WRITING bit
- BufferState currentState( __sync_fetch_and_or( &mState, WRITING ) );
- DALI_ASSERT_DEBUG( !(currentState & WRITING_MASK) ); // WRITING bit should never be set when we get here
+ BufferState currentState(__sync_fetch_and_or(&mState, WRITING));
+ DALI_ASSERT_DEBUG(!(currentState & WRITING_MASK)); // WRITING bit should never be set when we get here
// copy data to current write buffer, negate state to get actual index (recap: R0W1 = 0, R1W0 = 1)
const unsigned int index = (currentState & WRITE_BUFFER_MASK);
- memcpy( mBuffer[index], src, size );
+ memcpy(mBuffer[index], src, size);
// unset WRITING bit, set UPDATED bit
- BufferState checkState = __sync_val_compare_and_swap( &mState,
- static_cast<BufferState>(currentState | WRITING),
- static_cast<BufferState>(index | UPDATED) );
+ BufferState checkState = __sync_val_compare_and_swap(&mState,
+ static_cast<BufferState>(currentState | WRITING),
+ static_cast<BufferState>(index | UPDATED));
- DALI_ASSERT_DEBUG( checkState & WRITING );
+ DALI_ASSERT_DEBUG(checkState & WRITING);
(void)checkState; // Avoid unused variable warning
}
const uint8_t* LocklessBuffer::Read()
{
// current state (only to avoid multiple memory reads with volatile variable)
- BufferState currentState( mState );
- BufferState currentWriteBuf( static_cast<BufferState>( currentState & WRITE_BUFFER_MASK ) );
+ BufferState currentState(mState);
+ BufferState currentWriteBuf(static_cast<BufferState>(currentState & WRITE_BUFFER_MASK));
- if( currentState & UPDATED_MASK )
+ if(currentState & UPDATED_MASK)
{
// Try to swap buffers.
// This will set mState to 1 if readbuffer 0 was updated, 0 if readbuffer 1 was updated and fail if WRITING is set
- if( __sync_bool_compare_and_swap( &mState,
- static_cast<BufferState>(currentWriteBuf | UPDATED),
- static_cast<BufferState>(!currentWriteBuf) ) )
+ if(__sync_bool_compare_and_swap(&mState,
+ static_cast<BufferState>(currentWriteBuf | UPDATED),
+ static_cast<BufferState>(!currentWriteBuf)))
{
// swap successful
return mBuffer[currentWriteBuf];
return static_cast<unsigned int>(mSize);
}
-} // Internal
+} // namespace Integration
-} // Dali
+} // namespace Dali