Skip to content

Commit

Permalink
Use <stdatomic.h> in vproc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
wjk committed Jul 11, 2020
1 parent 625bccb commit 5540e6a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libxpc/libvproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include <sys/types.h>
#include <machine/atomic.h>
#include <stdatomic.h>

#include <os/assumes.h>

Expand Down Expand Up @@ -76,7 +77,7 @@ void _vproc_transaction_end_internal(void *arg __unused);

#pragma mark vproc Object
struct vproc_s {
int32_t refcount;
atomic_int_fast32_t refcount;
mach_port_t j_port;
};

Expand All @@ -103,7 +104,7 @@ vprocmgr_lookup_vproc(const char *label)
vproc_t
vproc_retain(vproc_t vp)
{
int32_t orig = OSAtomicAdd32(1, &vp->refcount) - 1;
int32_t orig = atomic_fetch_add(&vp->refcount, 1) - 1;
if (orig <= 0) {
_vproc_set_crash_log_message("Under-retain / over-release of vproc_t.");
__builtin_trap();
Expand All @@ -115,7 +116,7 @@ vproc_retain(vproc_t vp)
void
vproc_release(vproc_t vp)
{
int32_t newval = OSAtomicAdd32(-1, &vp->refcount);
int32_t newval = atomic_fetch_sub(&vp->refcount, 1) - 1;
if (newval < 0) {
_vproc_set_crash_log_message("Over-release of vproc_t.");
__builtin_trap();
Expand Down

0 comments on commit 5540e6a

Please sign in to comment.