Skip to content

Commit

Permalink
Rename MVM_cas => MVM_trycas.
Browse files Browse the repository at this point in the history
The traditional cas definition is to return what was seen. We'll make
MVM_cas mean that in the future, so rename the bool-returning one to
MVM_trycas.
  • Loading branch information
jnthn committed Aug 17, 2013
1 parent 72a9fd4 commit 06ae890
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/compunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ MVMCompUnit * MVM_cu_map_from_file(MVMThreadContext *tc, char *filename) {
/* Add the compilation unit to the head of the unit linked lists. */
do {
MVM_ASSIGN_REF(tc, cu, cu->body.next_compunit, tc->instance->head_compunit);
} while (!MVM_cas(&tc->instance->head_compunit, cu->body.next_compunit, cu));
} while (!MVM_trycas(&tc->instance->head_compunit, cu->body.next_compunit, cu));

return cu;
}
2 changes: 1 addition & 1 deletion src/core/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static MVMuint64 return_or_unwind(MVMThreadContext *tc, MVMuint8 unwind) {
* set us as it. */
do {
prior = returner->static_info->body.prior_invocation;
} while (!MVM_cas(&returner->static_info->body.prior_invocation, prior, returner));
} while (!MVM_trycas(&returner->static_info->body.prior_invocation, prior, returner));
if (prior)
MVM_frame_dec_ref(tc, prior);

Expand Down
10 changes: 5 additions & 5 deletions src/gc/orchestrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static void signal_child(MVMThreadContext *tc) {
/* this will never return nonzero, because the child's status
* will always be UNABLE or STOLEN. */
signal_one_thread(tc, child->body.tc);
while (!MVM_cas(&tc->thread_obj->body.new_child,
while (!MVM_trycas(&tc->thread_obj->body.new_child,
tc->thread_obj->body.new_child, NULL));
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ void MVM_gc_enter_from_allocator(MVMThreadContext *tc) {
GCORCH_LOG(tc, "Thread %d run %d : Entered from allocate\n");

/* Try to start the GC run. */
if (MVM_cas(&tc->instance->gc_start, 0, 1)) {
if (MVM_trycas(&tc->instance->gc_start, 0, 1)) {
MVMThread *last_starter = NULL;
MVMuint32 num_threads = 0;

Expand All @@ -331,7 +331,7 @@ void MVM_gc_enter_from_allocator(MVMThreadContext *tc) {
if (tc->instance->threads && tc->instance->threads != last_starter) {
MVMThread *head;
MVMuint32 add;
while (!MVM_cas(&tc->instance->threads, (head = tc->instance->threads), NULL));
while (!MVM_trycas(&tc->instance->threads, (head = tc->instance->threads), NULL));

add = signal_all_but(tc, head, last_starter);
last_starter = head;
Expand All @@ -343,7 +343,7 @@ void MVM_gc_enter_from_allocator(MVMThreadContext *tc) {
}
} while (tc->instance->gc_start > 1);

if (!MVM_cas(&tc->instance->threads, NULL, last_starter))
if (!MVM_trycas(&tc->instance->threads, NULL, last_starter))
MVM_panic(MVM_exitcode_gcorch, "threads list corrupted\n");

if (tc->instance->gc_finish != 0)
Expand Down Expand Up @@ -384,7 +384,7 @@ void MVM_gc_enter_from_interrupt(MVMThreadContext *tc) {
GCORCH_LOG(tc, "Thread %d run %d : Entered from interrupt\n");

while ((curr = tc->instance->gc_start) < 2
|| !MVM_cas(&tc->instance->gc_start, curr, curr - 1)) {
|| !MVM_trycas(&tc->instance->gc_start, curr, curr - 1)) {
/* apr_sleep(1);
apr_thread_yield();*/
}
Expand Down
9 changes: 6 additions & 3 deletions src/moarvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ void MVM_vm_run_file(MVMInstance *instance, char *filename);
void MVM_vm_dump_file(MVMInstance *instance, char *filename);
void MVM_vm_destroy_instance(MVMInstance *instance);

/* returns original. Use only on AO_t-sized values (including pointers). */
/* Returns original. Use only on AO_t-sized values (including pointers). */
#define MVM_atomic_incr(addr) AO_fetch_and_add1_full((volatile AO_t *)(addr))
#define MVM_atomic_decr(addr) AO_fetch_and_sub1_full((volatile AO_t *)(addr))
#define MVM_atomic_add(addr, add) AO_fetch_and_add_full((volatile AO_t *)(addr), (AO_t)(add))
/* returns non-zero for success. Use for both AO_t numbers and pointers. */
#define MVM_cas(addr, old, new) AO_compare_and_swap_full((volatile AO_t *)(addr), (AO_t)(old), (AO_t)(new))

/* Returns non-zero for success. Use for both AO_t numbers and pointers. */
#define MVM_trycas(addr, old, new) AO_compare_and_swap_full((volatile AO_t *)(addr), (AO_t)(old), (AO_t)(new))

/* Full memory barrier. */
#define MVM_barrier() AO_nop_full()

0 comments on commit 06ae890

Please sign in to comment.