Skip to content

Commit

Permalink
Replace platform-dependent barriers with c++11 std
Browse files Browse the repository at this point in the history
  • Loading branch information
cannam committed Mar 7, 2024
1 parent 5a4e3a8 commit e5bff67
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 66 deletions.
9 changes: 6 additions & 3 deletions src/common/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ RingBuffer<T>::resized(int newSize) const
{
RingBuffer<T> *newBuffer = new RingBuffer<T>(newSize);

MBARRIER();
std::atomic_thread_fence(std::memory_order_seq_cst);

int w = m_writer;
int r = m_reader;

Expand Down Expand Up @@ -464,7 +465,8 @@ RingBuffer<T>::write(const S *const R__ source, int n)
w += n;
while (w >= m_size) w -= m_size;

MBARRIER();
std::atomic_thread_fence(std::memory_order_seq_cst);

m_writer = w;

return n;
Expand Down Expand Up @@ -498,7 +500,8 @@ RingBuffer<T>::zero(int n)
w += n;
while (w >= m_size) w -= m_size;

MBARRIER();
std::atomic_thread_fence(std::memory_order_seq_cst);

m_writer = w;

return n;
Expand Down
25 changes: 0 additions & 25 deletions src/common/sysutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,6 @@ void gettimeofday(struct timeval *tv, void * /* tz */)

#endif

#ifdef _WIN32
void system_memorybarrier()
{
#ifdef _MSC_VER
MemoryBarrier();
#else /* (mingw) */
LONG Barrier = 0;
__asm__ __volatile__("xchgl %%eax,%0 "
: "=r" (Barrier));
#endif
}
#else /* !_WIN32 */
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
// Not required
#else
#include <pthread.h>
void system_memorybarrier()
{
pthread_mutex_t dummy = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&dummy);
pthread_mutex_unlock(&dummy);
}
#endif
#endif

}


Expand Down
38 changes: 0 additions & 38 deletions src/common/sysutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,43 +117,5 @@ void gettimeofday(struct timeval *p, void *tz);

} // end namespace

// The following should be functions in the RubberBand namespace, really

#ifdef _WIN32

namespace RubberBand {
extern void system_memorybarrier();
}
#define MBARRIER() RubberBand::system_memorybarrier()

#else // !_WIN32

#include <stdio.h>

#ifdef __APPLE__
# if defined __MAC_10_12
# define MBARRIER() __sync_synchronize()
# else
# include <libkern/OSAtomic.h>
# define MBARRIER() OSMemoryBarrier()
# endif
#else
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
# define MBARRIER() __sync_synchronize()
# else
namespace RubberBand {
extern void system_memorybarrier();
}
# define MBARRIER() ::RubberBand::system_memorybarrier()
# endif
#endif

#endif // !_WIN32

#ifdef NO_THREADING
# undef MBARRIER
# define MBARRIER()
#endif // NO_THREADING

#endif

0 comments on commit e5bff67

Please sign in to comment.