void WebKitCookieStorageShimInitialize(const CookieStorageShimCallbacks& callbacks)
{
    // Because the value of cookieStorageShimCallbacks will be read from mulitple threads,
    // only allow it to be initialized once.
    static int initialized = 0;
    if (!OSAtomicCompareAndSwapInt(0, 1, &initialized)) {
        return;
    }

    cookieStorageShimCallbacks = callbacks;
}
Ejemplo n.º 2
0
/**
 * Atomic reference count increment.
 */
static int latching_incr_int(int *where) {
    while (1) {
        int old_value = *(volatile int *)where;
        if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
            return BLOCK_REFCOUNT_MASK;
        }
        if (OSAtomicCompareAndSwapInt(old_value, old_value+1, (volatile int *)where)) {
            return old_value+1;
        }
    }
}
Ejemplo n.º 3
0
int netdev_pcap::recv_dev(UINT8 **buf)
{
#ifdef SDLMAME_MACOSX
	UINT8 pktbuf[2048];
	int ret;

	// Empty
	if(OSAtomicCompareAndSwapInt(m_ctx.head, m_ctx.tail, &m_ctx.tail)) {
		return 0;
	}

	memcpy(pktbuf, m_ctx.packets[m_ctx.tail], m_ctx.packetlens[m_ctx.tail]);
	ret = m_ctx.packetlens[m_ctx.tail];
	OSAtomicCompareAndSwapInt(m_ctx.tail, (m_ctx.tail+1) & 0x1F, &m_ctx.tail);
	*buf = pktbuf;
	return ret;
#else
	struct pcap_pkthdr *header;
	if(!m_p) return 0;
	return ((*module->pcap_next_ex_dl)(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
#endif
}
Ejemplo n.º 4
0
// hit zero?
static bool latching_decr_int_now_zero(volatile int32_t *where) {
    while (1) {
        int32_t old_value = *where;
        if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
            return false; // latched high
        }
        if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
            return false;   // underflow, latch low
        }
        int32_t new_value = old_value - 2;
        if (OSAtomicCompareAndSwapInt(old_value, new_value, where)) {
            return (new_value & BLOCK_REFCOUNT_MASK) == 0;
        }
    }
}
Ejemplo n.º 5
0
static bool latching_incr_int_not_deallocating(volatile int32_t *where) {
    while (1) {
        int32_t old_value = *where;
        if (old_value & BLOCK_DEALLOCATING) {
            // if deallocating we can't do this
            return false;
        }
        if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
            // if latched, we're leaking this block, and we succeed
            return true;
        }
        if (OSAtomicCompareAndSwapInt(old_value, old_value+2, where)) {
            // otherwise, we must store a new retained value without the deallocating bit set
            return true;
        }
    }
}
Ejemplo n.º 6
0
// return should_deallocate?
static bool latching_decr_int_should_deallocate(volatile int32_t *where) {
    while (1) {
        int32_t old_value = *where;
        if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
            return false; // latched high
        }
        if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
            return false;   // underflow, latch low
        }
        int32_t new_value = old_value - 2;
        bool result = false;
        if ((old_value & (BLOCK_REFCOUNT_MASK|BLOCK_DEALLOCATING)) == 2) {
            new_value = old_value - 1;
            result = true;
        }
        if (OSAtomicCompareAndSwapInt(old_value, new_value, where)) {
            return result;
        }
    }
}
Ejemplo n.º 7
0
int OSAtomicCompareAndSwap32(int32_t oldValue,int32_t newValue,volatile int32_t* target) {
    return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target);
}
Ejemplo n.º 8
0
int OSAtomicCompareAndSwapLong(long oldValue,long newValue,volatile long* target) {
    return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target);
}
Ejemplo n.º 9
0
int OSAtomicCompareAndSwapPtr(void* oldValue,void* newValue,void* volatile* target) {
    return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target);
}
Ejemplo n.º 10
0
int OSAtomicCompareAndSwapIntBarrier(int oldValue,int newValue,volatile int* target) {
    return OSAtomicCompareAndSwapInt(oldValue,newValue,target);
}