static void * collaborator_A(void *data) { uint32_t *valuePointer = (uint32_t *) data; uint32_t contribution = 0; while (*valuePointer < 1000000) { parcAtomicInteger_Uint32Increment(valuePointer); contribution++; } printf("A contribution %d\n", contribution); pthread_exit((void *) NULL); }
void * parcStdlibMemory_Reallocate(void *pointer, size_t newSize) { #if HAVE_REALLOC void *result = realloc(pointer, newSize); #else void *result = _parcStdlibMemory_rplRealloc(pointer, newSize); #endif if (pointer == NULL) { parcAtomicInteger_Uint32Increment(&_parcStdlibMemory_OutstandingAllocations); } return result; }
void * parcStdlibMemory_Allocate(size_t size) { if (size == 0) { return NULL; } void *result = malloc(size); if (result != NULL) { #ifdef PARCLibrary_DISABLE_ATOMICS parcAtomicInteger_Uint32Increment(&_parcStdlibMemory_OutstandingAllocations); #else __sync_add_and_fetch(&_parcStdlibMemory_OutstandingAllocations, 1); #endif } return result; }
int parcStdlibMemory_MemAlign(void **pointer, size_t alignment, size_t size) { if (size == 0) { return EINVAL; } int failure = posix_memalign(pointer, alignment, size); if (failure != 0) { return failure; } if (*pointer == NULL) { return ENOMEM; } parcAtomicInteger_Uint32Increment(&_parcStdlibMemory_OutstandingAllocations); return 0; }
char * parcStdlibMemory_StringDuplicate(const char *string, size_t length) { parcAtomicInteger_Uint32Increment(&_parcStdlibMemory_OutstandingAllocations); return strndup(string, length); }
LONGBOW_TEST_CASE(Global, parcAtomicInteger_Uint32Decrement) { uint32_t value = 0; parcAtomicInteger_Uint32Increment(&value); assertTrue(value == 1, "Expected 1, actual, %u", value); }