Browse Source

Minor clean-up

gingerBill 4 years ago
parent
commit
662c7b1e71
3 changed files with 17 additions and 14 deletions
  1. 1 0
      src/array.cpp
  2. 3 3
      src/llvm_backend.cpp
  3. 13 11
      src/queue.cpp

+ 1 - 0
src/array.cpp

@@ -333,6 +333,7 @@ void array_set_capacity(Array<T> *array, isize capacity) {
 	if (new_data == nullptr) {
 	if (new_data == nullptr) {
 		if (capacity > 0) {
 		if (capacity > 0) {
 			new_data = gb_alloc_array(array->allocator, T, capacity);
 			new_data = gb_alloc_array(array->allocator, T, capacity);
+			GB_ASSERT(new_data != nullptr);
 			gb_memmove(new_data, array->data, gb_size_of(T) * array->capacity);
 			gb_memmove(new_data, array->data, gb_size_of(T) * array->capacity);
 		}
 		}
 		gb_free(array->allocator, array->data);
 		gb_free(array->allocator, array->data);

+ 3 - 3
src/llvm_backend.cpp

@@ -523,7 +523,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
 
 
 	lbValue hashed_key = {};
 	lbValue hashed_key = {};
 
 
-
+#if 0
 	if (lb_is_const(key)) {
 	if (lb_is_const(key)) {
 		u64 hash = 0xcbf29ce484222325;
 		u64 hash = 0xcbf29ce484222325;
 		if (is_type_cstring(key_type)) {
 		if (is_type_cstring(key_type)) {
@@ -545,7 +545,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
 
 
 				size_t ulength = 0;
 				size_t ulength = 0;
 				text = LLVMGetAsString(data, &ulength);
 				text = LLVMGetAsString(data, &ulength);
-				gb_printf_err("%td %td %s\n", length, ulength, text);
+				gb_printf_err("%lld %llu %s\n", length, ulength, text);
 				length = gb_min(length, cast(i64)ulength);
 				length = gb_min(length, cast(i64)ulength);
 			}
 			}
 			hash = fnv64a(text, cast(isize)length);
 			hash = fnv64a(text, cast(isize)length);
@@ -559,7 +559,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
 		}
 		}
 		hashed_key = lb_const_int(m, t_uintptr, hash);
 		hashed_key = lb_const_int(m, t_uintptr, hash);
 	}
 	}
-
+#endif
 	return hashed_key;
 	return hashed_key;
 }
 }
 
 

+ 13 - 11
src/queue.cpp

@@ -1,27 +1,29 @@
 #define MPMC_CACHE_LINE_SIZE 64
 #define MPMC_CACHE_LINE_SIZE 64
 
 
+typedef std::atomic<i32> MPMCQueueAtomicIdx;
+
 // Multiple Producer Multiple Consumer Queue
 // Multiple Producer Multiple Consumer Queue
 template <typename T>
 template <typename T>
 struct MPMCQueue {
 struct MPMCQueue {
-	static size_t const PAD0_OFFSET = (sizeof(T *) + sizeof(std::atomic<i32> *) + sizeof(gbAllocator) + sizeof(BlockingMutex) + sizeof(i32) + sizeof(i32));
+	static size_t const PAD0_OFFSET = (sizeof(T *) + sizeof(MPMCQueueAtomicIdx *) + sizeof(gbAllocator) + sizeof(BlockingMutex) + sizeof(i32) + sizeof(i32));
 
 
-	T *               nodes;
-	std::atomic<i32> *indices;
-	gbAllocator       allocator;
-	BlockingMutex     mutex;
-	std::atomic<i32>  count;
-	i32               mask;
+	T *                 nodes;
+	MPMCQueueAtomicIdx *indices;
+	gbAllocator         allocator;
+	BlockingMutex       mutex;
+	MPMCQueueAtomicIdx  count;
+	i32                 mask; // capacity-1, because capacity must be a power of 2
 
 
 	char pad0[(MPMC_CACHE_LINE_SIZE*2 - PAD0_OFFSET) % MPMC_CACHE_LINE_SIZE];
 	char pad0[(MPMC_CACHE_LINE_SIZE*2 - PAD0_OFFSET) % MPMC_CACHE_LINE_SIZE];
-	std::atomic<i32> head_idx;
+	MPMCQueueAtomicIdx head_idx;
 
 
 	char pad1[MPMC_CACHE_LINE_SIZE - sizeof(i32)];
 	char pad1[MPMC_CACHE_LINE_SIZE - sizeof(i32)];
-	std::atomic<i32> tail_idx;
+	MPMCQueueAtomicIdx tail_idx;
 };
 };
 
 
 
 
 
 
-void mpmc_internal_init_indices(std::atomic<i32> *indices, i32 offset, i32 size) {
+void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 size) {
 	GB_ASSERT(offset % 8 == 0);
 	GB_ASSERT(offset % 8 == 0);
 	GB_ASSERT(size % 8 == 0);
 	GB_ASSERT(size % 8 == 0);
 
 
@@ -54,7 +56,7 @@ void mpmc_init(MPMCQueue<T> *q, gbAllocator a, isize size_i) {
 	q->mask = size-1;
 	q->mask = size-1;
 	q->allocator = a;
 	q->allocator = a;
 	q->nodes   = gb_alloc_array(a, T, size);
 	q->nodes   = gb_alloc_array(a, T, size);
-	q->indices = cast(std::atomic<i32> *)gb_alloc_array(a, i32, size);
+	q->indices = gb_alloc_array(a, MPMCQueueAtomicIdx, size);
 
 
 	mpmc_internal_init_indices(q->indices, 0, q->mask+1);
 	mpmc_internal_init_indices(q->indices, 0, q->mask+1);
 }
 }