Skip to content

Commit

Permalink
Add bitOrU32 to AtomicSupport.hpp
Browse files Browse the repository at this point in the history
bitAndU32 was there, bitOrU32 was not for some reason.

Signed-off-by: Graham Chapman <[email protected]>
  • Loading branch information
gacholio committed Oct 2, 2018
1 parent 870c5d6 commit b353e53
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include_core/AtomicSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,30 @@ class VM_AtomicSupport
return oldValue;
}

/**
* OR a mask with the value at a specific memory location as an atomic operation.
* ORs the value <b>mask</b> with the value stored at memory location pointed
* to by <b>address</b>.
*
* @param address The memory location to be updated
* @param mask The value to be added
*
* @return The value at memory location <b>address</b> BEFORE the OR is completed
*/
VMINLINE static uint32_t
bitOrU32(volatile uint32_t *address, uint32_t mask)
{
/* Stop compiler optimizing away load of oldValue */
volatile uint32_t *localAddr = address;
uint32_t oldValue;

oldValue = (uint32_t)*localAddr;
while ((lockCompareExchangeU32(localAddr, oldValue, oldValue | mask)) != oldValue) {
oldValue = (uint32_t)*localAddr;
}
return oldValue;
}

/**
* Add a 32 bit number to the value at a specific memory location as an atomic operation.
* Adds the value <b>addend</b> to the value stored at memory location pointed
Expand Down

0 comments on commit b353e53

Please sign in to comment.