// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/src/cl_async.c
// Function: citrusleaf_async_init
int citrusleaf_async_init(int size_limit, int num_receiver_threads, cl_async_fail_cb fail_cb_fn, cl_async_success_cb success_cb_fn)
{
	int i, num_threads;

	//Make sure that we do the initialization only once
	if (1 == cf_atomic32_incr(&g_async_initialized)) {

		// Start the receiver threads
		num_threads = num_receiver_threads;
		if (num_threads > MAX_ASYNC_RECEIVER_THREADS) {
			//Limit the threads to the max value even if caller asks for it
			num_threads = MAX_ASYNC_RECEIVER_THREADS;
		}

#if ONEASYNCFD
		g_async_h_szlimit = size_limit * 3;	//Max number of elements in the hash table
		g_async_h_buckets = g_async_h_szlimit/10;//Number of buckets in the hash table

		if (shash_create(&g_cl_async_hashtab, async_trid_hash, sizeof(uint64_t), sizeof(cl_async_work *),
					g_async_h_buckets, SHASH_CR_MT_BIGLOCK) != SHASH_OK) {
			cf_error("Failed to initialize the async work hastable");
			cf_atomic32_decr(&g_async_initialized);
			return -1;
		}
#else
		// create work queue
		g_async_q_szlimit = size_limit;
		if ((g_cl_async_q = cf_queue_create(sizeof(cl_async_work *), true)) == NULL) {
			cf_error("Failed to initialize the async work queue");
			cf_atomic32_decr(&g_async_initialized);
			return -1;
		}

		for (i=0; i<num_threads; i++) {
			pthread_create(&g_async_reciever[i], 0, async_receiver_fn, NULL);
		}
		g_async_num_threads = num_threads;
#endif

		if ((g_cl_workitems_freepool_q = cf_queue_create(sizeof(cl_async_work *), true)) == NULL) {
			cf_error("Failed to create memory pool for workitems");
			return -1;
		}

		g_fail_cb_fn = fail_cb_fn;
		g_success_cb_fn = success_cb_fn;

		// Initialize the stats
		g_async_stats.retries = 0;
		g_async_stats.dropouts = 0;

	}
	
	return(0);	
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq 0xf6ab(%rip), %rdi      # 0x204b8
movl $0x1, %esi
callq 0x10f90
movq %rax, %rcx
movl $0x1, %eax
cmpq %rcx, %rax
jne 0x10f73
movl 0x1c(%rsp), %eax
movl %eax, (%rsp)
cmpl $0x20, (%rsp)
jle 0x10e3c
movl $0x20, (%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0xf662(%rip)      # 0x204a8
movl $0x8, %edi
movl $0x1, %esi
callq 0x13e70
leaq 0xf634(%rip), %rcx      # 0x20490
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x10ea9
leaq 0xd46c(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x10e8b
leaq 0xd465(%rip), %rax      # 0x1e2e0
movq (%rax), %rcx
xorl %edi, %edi
leaq 0x83f9(%rip), %rsi      # 0x19280
movb $0x0, %al
callq *%rcx
leaq 0xf626(%rip), %rdi      # 0x204b8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10f90
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x10f7b
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
cmpl (%rsp), %eax
jge 0x10eed
movslq 0x4(%rsp), %rax
leaq 0xf5fa(%rip), %rdi      # 0x204c0
shlq $0x3, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x6c8(%rip), %rdx      # 0x10810
movq %rcx, %rsi
callq 0x2500
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x10eb1
movl (%rsp), %eax
movl %eax, 0xf5c6(%rip)      # 0x204bc
movl $0x8, %edi
movl $0x1, %esi
callq 0x13e70
leaq 0xf5a4(%rip), %rcx      # 0x204b0
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x10f45
leaq 0xd3bc(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x10f3b
leaq 0xd3b5(%rip), %rax      # 0x1e2e0
movq (%rax), %rcx
xorl %edi, %edi
leaq 0x8373(%rip), %rsi      # 0x192aa
movb $0x0, %al
callq *%rcx
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x10f7b
movq 0x10(%rsp), %rax
movq %rax, 0xf66f(%rip)      # 0x205c0
movq 0x8(%rsp), %rax
movq %rax, 0xf66b(%rip)      # 0x205c8
movq $0x0, 0xf530(%rip) # 0x20498
movq $0x0, 0xf52d(%rip) # 0x204a0
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
nop