vm: add atomic::load and atomic::store functions

Abstract out the fence-and-load and store-and-fence patterns
db4
Joe Groff 2011-11-01 21:00:46 -07:00
parent 81aac9359f
commit 4d39e59054
8 changed files with 21 additions and 14 deletions

View File

@ -1,3 +1,5 @@
#define FACTOR_FORCE_INLINE __forceinline
namespace factor {
namespace atomic {
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
@ -44,3 +46,4 @@ namespace factor {
}
}
#include "atomic.hpp"

View File

@ -1,3 +1,5 @@
#define FACTOR_FORCE_INLINE __forceinline
namespace factor {
namespace atomic {
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
@ -44,3 +46,4 @@ namespace factor {
}
}
#include "atomic.hpp"

View File

@ -1,3 +1,4 @@
#define FACTOR_FORCE_INLINE __attribute__((always_inline)) inline
namespace factor {
namespace atomic {
__attribute__((always_inline))
@ -40,3 +41,5 @@ namespace factor {
}
}
}
#include "atomic.hpp"

View File

@ -172,20 +172,20 @@ void factor_vm::enqueue_safepoint_fep()
{
if (fep_p)
fatal_error("Low-level debugger interrupted", 0);
safepoint_fep = true;
atomic::store(&safepoint_fep_p, true);
code->guard_safepoint();
}
void factor_vm::handle_safepoint()
{
code->unguard_safepoint();
if (safepoint_fep)
if (atomic::load(&safepoint_fep_p))
{
if (sampling_profiler_p)
if (atomic::load(&sampling_profiler_p))
end_sampling_profiler();
std::cout << "Interrupted\n";
factorbug();
safepoint_fep = false;
atomic::store(&safepoint_fep_p, false);
}
else if (sampling_profiler_p)
record_sample();

View File

@ -309,7 +309,7 @@ void factor_vm::sampler_thread_loop()
assert(QueryPerformanceCounter(&counter));
counter.QuadPart *= samples_per_second;
while (atomic::fence(), sampling_profiler_p)
while (atomic::load(&sampling_profiler_p))
{
SwitchToThread();
assert(QueryPerformanceCounter(&new_counter));
@ -345,8 +345,7 @@ void factor_vm::start_sampling_profiler_timer()
void factor_vm::end_sampling_profiler_timer()
{
sampling_profiler_p = false;
atomic::fence();
atomic::store(&sampling_profiler_p, false);
DWORD wait_result = WaitForSingleObject(sampler_thread,
3000*(DWORD)samples_per_second);
if (wait_result != WAIT_OBJECT_0)

View File

@ -93,8 +93,7 @@ void factor_vm::start_sampling_profiler(fixnum rate)
void factor_vm::end_sampling_profiler()
{
sampling_profiler_p = false;
atomic::fence();
atomic::store(&sampling_profiler_p, false);
end_sampling_profiler_timer();
record_sample();
}
@ -151,13 +150,13 @@ void factor_vm::primitive_clear_samples()
void factor_vm::enqueue_safepoint_sample(cell samples, cell pc, bool foreign_thread_p)
{
if (atomic::fence(), sampling_profiler_p)
if (atomic::load(&sampling_profiler_p))
{
atomic::add(&safepoint_sample_counts.sample_count, samples);
if (foreign_thread_p)
atomic::add(&safepoint_sample_counts.foreign_thread_sample_count, samples);
else {
if (atomic::fence(), current_gc)
if (atomic::load(&current_gc_p))
atomic::add(&safepoint_sample_counts.gc_sample_count, samples);
if (pc != 0 && !code->seg->in_segment_p(pc))
atomic::add(&safepoint_sample_counts.foreign_sample_count, samples);

View File

@ -9,7 +9,7 @@ factor_vm::factor_vm() :
c_to_factor_func(NULL),
counting_profiler_p(false),
sampling_profiler_p(false),
safepoint_fep(false),
safepoint_fep_p(false),
gc_off(false),
current_gc(NULL),
gc_events(NULL),

View File

@ -62,7 +62,7 @@ struct factor_vm
/* Is profiling enabled? */
bool counting_profiler_p;
volatile bool sampling_profiler_p;
volatile cell sampling_profiler_p;
fixnum samples_per_second;
/* Global variables used to pass fault handler state from signal handler
@ -71,7 +71,7 @@ struct factor_vm
cell signal_number;
cell signal_fault_addr;
unsigned int signal_fpu_status;
volatile bool safepoint_fep;
volatile cell safepoint_fep_p;
/* State kept by the sampling profiler */
std::vector<profiling_sample> samples;