Browse Source

Assert alignment is suitable for atomic accesses

pull/761/head
Colin McEwan 4 years ago
parent
commit
7ecdc3d1c6
7 changed files with 24 additions and 3 deletions
  1. +4
    -1
      common/JackActivationCount.h
  2. +3
    -0
      common/JackAtomicArrayState.h
  3. +3
    -0
      common/JackAtomicState.h
  4. +3
    -0
      common/JackConnectionManager.cpp
  5. +5
    -1
      common/JackEngineControl.h
  6. +4
    -1
      common/JackMessageBuffer.cpp
  7. +2
    -0
      common/JackTransportEngine.cpp

+ 4
- 1
common/JackActivationCount.h View File

@@ -45,7 +45,10 @@ class JackActivationCount
public: public:


JackActivationCount(): fValue(0), fCount(0) JackActivationCount(): fValue(0), fCount(0)
{}
{
static_assert(offsetof(JackActivationCount, fValue) % sizeof(fValue) == 0,
"fValue must be aligned within JackActivationCount");
}


bool Signal(JackSynchro* synchro, JackClientControl* control); bool Signal(JackSynchro* synchro, JackClientControl* control);




+ 3
- 0
common/JackAtomicArrayState.h View File

@@ -23,6 +23,7 @@
#include "JackAtomic.h" #include "JackAtomic.h"
#include "JackCompilerDeps.h" #include "JackCompilerDeps.h"
#include <string.h> // for memcpy #include <string.h> // for memcpy
#include <cstddef>


namespace Jack namespace Jack
{ {
@@ -159,6 +160,8 @@ class JackAtomicArrayState


JackAtomicArrayState() JackAtomicArrayState()
{ {
static_assert(offsetof(JackAtomicArrayState, fCounter) % sizeof(fCounter) == 0,
"fCounter must be aligned within JackAtomicArrayState");
Counter1(fCounter) = 0; Counter1(fCounter) = 0;
} }




+ 3
- 0
common/JackAtomicState.h View File

@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackAtomic.h" #include "JackAtomic.h"
#include "JackCompilerDeps.h" #include "JackCompilerDeps.h"
#include <string.h> // for memcpy #include <string.h> // for memcpy
#include <cstddef>


namespace Jack namespace Jack
{ {
@@ -131,6 +132,8 @@ class JackAtomicState


JackAtomicState() JackAtomicState()
{ {
static_assert(offsetof(JackAtomicState, fCounter) % sizeof(fCounter) == 0,
"fCounter must be aligned within JackAtomicState");
Counter(fCounter) = 0; Counter(fCounter) = 0;
fCallWriteCounter = 0; fCallWriteCounter = 0;
} }


+ 3
- 0
common/JackConnectionManager.cpp View File

@@ -32,6 +32,9 @@ namespace Jack
JackConnectionManager::JackConnectionManager() JackConnectionManager::JackConnectionManager()
{ {
int i; int i;
static_assert(offsetof(JackConnectionManager, fInputCounter) % sizeof(UInt32) == 0,
"fInputCounter must be aligned within JackConnectionManager");

jack_log("JackConnectionManager::InitConnections size = %ld ", sizeof(JackConnectionManager)); jack_log("JackConnectionManager::InitConnections size = %ld ", sizeof(JackConnectionManager));


for (i = 0; i < PORT_NUM_MAX; i++) { for (i = 0; i < PORT_NUM_MAX; i++) {


+ 5
- 1
common/JackEngineControl.h View File

@@ -93,7 +93,11 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
#endif #endif


JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name) JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name)
{
{
static_assert(offsetof(JackEngineControl, fTransport) % sizeof(UInt32) == 0,
"fTransport must be aligned within JackEngineControl");
static_assert(offsetof(JackEngineControl, fFrameTimer) % sizeof(UInt32) == 0,
"fFrameTimer must be aligned within JackEngineControl");
fBufferSize = 512; fBufferSize = 512;
fSampleRate = 48000; fSampleRate = 48000;
fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize); fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);


+ 4
- 1
common/JackMessageBuffer.cpp View File

@@ -38,7 +38,10 @@ JackMessageBuffer::JackMessageBuffer()
fOutBuffer(0), fOutBuffer(0),
fOverruns(0), fOverruns(0),
fRunning(false) fRunning(false)
{}
{
static_assert(offsetof(JackMessageBuffer, fOverruns) % sizeof(fOverruns) == 0,
"fOverruns must be aligned within JackMessageBuffer");
}


JackMessageBuffer::~JackMessageBuffer() JackMessageBuffer::~JackMessageBuffer()
{} {}


+ 2
- 0
common/JackTransportEngine.cpp View File

@@ -36,6 +36,8 @@ namespace Jack


JackTransportEngine::JackTransportEngine(): JackAtomicArrayState<jack_position_t>() JackTransportEngine::JackTransportEngine(): JackAtomicArrayState<jack_position_t>()
{ {
static_assert(offsetof(JackTransportEngine, fWriteCounter) % sizeof(fWriteCounter) == 0,
"fWriteCounter must be first member of JackTransportEngine to ensure its alignment");
fTransportState = JackTransportStopped; fTransportState = JackTransportStopped;
fTransportCmd = fPreviousCmd = TransportCommandStop; fTransportCmd = fPreviousCmd = TransportCommandStop;
fSyncTimeout = 10000000; /* 10 seconds default... fSyncTimeout = 10000000; /* 10 seconds default...


Loading…
Cancel
Save