Author: mturk Date: Sun Oct 18 10:19:21 2009 New Revision: 826396 URL: http://svn.apache.org/viewvc?rev=826396&view=rev Log: Unlike APR Our atomics returns the resulting value. This is how almost all implementations work
Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c?rev=826396&r1=826395&r2=826396&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c Sun Oct 18 10:19:21 2009 @@ -26,12 +26,12 @@ ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val) { - return __sync_fetch_and_add(mem, val); + return __sync_fetch_and_add(mem, val) + val; } ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem) { - return __sync_fetch_and_add(mem, 1); + return __sync_fetch_and_add(mem, 1) + 1; } ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem) Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c?rev=826396&r1=826395&r2=826396&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c Sun Oct 18 10:19:21 2009 @@ -26,12 +26,12 @@ ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val) { - return __sync_fetch_and_add(mem, val); + return __sync_fetch_and_add(mem, val) + val; } ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem) { - return __sync_fetch_and_add(mem, 1); + return __sync_fetch_and_add(mem, 1) + 1; } ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem) Modified: commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c?rev=826396&r1=826395&r2=826396&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c Sun Oct 18 10:19:21 2009 @@ -23,12 +23,12 @@ ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val) { - return atomic_add_32_nv(mem, val) - val; + return atomic_add_32_nv(mem, val); } ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem) { - return atomic_inc_32_nv(mem) - 1; + return atomic_inc_32_nv(mem); } ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem) Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c?rev=826396&r1=826395&r2=826396&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c Sun Oct 18 10:19:21 2009 @@ -22,12 +22,12 @@ ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val) { - return InterlockedExchangeAdd(mem, val); + return InterlockedExchangeAdd(mem, val) + val; } ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem) { - return InterlockedIncrement(mem) - 1; + return InterlockedIncrement(mem); } ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem) Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c?rev=826396&r1=826395&r2=826396&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Sun Oct 18 10:19:21 2009 @@ -17,6 +17,7 @@ #include "acr.h" #include "acr_private.h" #include "acr_arch.h" +#include "acr_atomic.h" #include "acr_port.h" #include "acr_error.h" #include "acr_string.h" @@ -29,8 +30,8 @@ * */ -static volatile LONG pipe_id = 0; -static int create_socket_pipe(SOCKET *rd, SOCKET *wr) +static acr_atomic_t pipe_id = 0; +static int crate_socketpair(SOCKET *rd, SOCKET *wr, int nonblocking) { FD_SET rs; SOCKET ls; @@ -53,8 +54,8 @@ * so that we know the connection originated * from us. */ - uid[0] = GetCurrentProcessId(); - uid[1] = (int)InterlockedIncrement(&pipe_id); + uid[0] = (GetCurrentProcessId() << 16) | (GetCurrentThreadId() & 0xFFFF); + uid[1] = ACR_AtomicInc32(&pipe_id); if ((ls = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) { return ACR_GET_NETOS_ERROR(); } @@ -125,14 +126,7 @@ if (nrd == sizeof(iid)) { if (memcmp(uid, iid, sizeof(uid)) == 0) { /* Wow, we recived what we send. - * Put read side of the pipe to the blocking - * mode and return. */ - bm = 0; - if (ioctlsocket(*rd, FIONBIO, &bm) == SOCKET_ERROR) { - rv = ACR_GET_NETOS_ERROR(); - goto cleanup; - } break; } } @@ -142,6 +136,25 @@ } closesocket(*rd); } + if (nonblocking) { + /* Put the write side to the nonblocking mode + * if nonblocking mode was requested + */ + bm = 1; + if (ioctlsocket(*wr, FIONBIO, &bm) == SOCKET_ERROR) { + rv = ACR_GET_NETOS_ERROR(); + goto cleanup; + } + } + else { + /* Put the read side back to the blocking mode + */ + bm = 0; + if (ioctlsocket(*rd, FIONBIO, &bm) == SOCKET_ERROR) { + rv = ACR_GET_NETOS_ERROR(); + goto cleanup; + } + } /* We don't need the listening socket any more */ closesocket(ls);