Skip to content

Commit c6c4de7

Browse files
committed
atomic: fix atomic_cas* comment documenting the behavior
It was backwards from reality (and tests). Returning the "before" value is more useful because it allows us to retry the CAS without having to reload the variable to get the old value. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent d7a28ad commit c6c4de7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/jeffpc/atomic.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014-2019 Josef 'Jeff' Sipek <[email protected]>
2+
* Copyright (c) 2014-2020 Josef 'Jeff' Sipek <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -49,7 +49,7 @@ typedef struct {
4949
#define atomic_inc(var) atomic_add((var), 1)
5050
#define atomic_dec(var) atomic_sub((var), 1)
5151

52-
/* The following return the 'after' value. If == new, then a swap occured. */
52+
/* The following return the 'before' value. If == old, then a swap occured. */
5353
#define atomic_cas(var, old, new) \
5454
__sync_val_compare_and_swap(&(var)->v, (old), (new))
5555
#define atomic_cas_ptr(var, old, new) \

0 commit comments

Comments
 (0)