// File: sjtuwrk[P]SunwayMR/tools/SunwayMRHelper.hpp
// Function: SunwayMRHelper::initListening(int)
bool SunwayMRHelper::initListening(int port) {
	string msg;
	int listenPort = port;
	struct thread_data *data = new thread_data (*this, "", listenPort);
	pthread_t thread;
	pthread_mutex_init(&mutex_listen_status, NULL);
	pthread_mutex_lock(&mutex_listen_status);
	int rc = pthread_create(&thread, NULL, startHelperListening, (void *)data);
	if (rc){
		Logging::logError("JobScheduler: failed to create thread to listen");
	}

	pthread_mutex_lock(&mutex_listen_status);
	pthread_mutex_unlock(&mutex_listen_status);

	if(getListenStatus() == SUCCESS) {
		setLocalResouce(this->threads, this->memory);
		void *status;
		pthread_join(thread, &status); // always listen

		Logging::logInfo("SunwayMRHelper: listen thread finished");

		return true;
	} else {
		return false;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x45c0
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl $0x18, %edi
callq 0x4400
movq %rax, -0xc8(%rbp)
jmp 0xc7ef
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdi
movl -0x3c(%rbp), %ecx
leaq 0xd878(%rip), %rdx      # 0x1a07f
callq 0xf840
jmp 0xc80e
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq %rax, -0x48(%rbp)
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4630
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0x4610
movq -0x48(%rbp), %rcx
leaq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x2ae0(%rip), %rdx     # 0x9d70
callq 0x47c0
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0xc923
leaq -0x89(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x47a0
movq -0xd8(%rbp), %rdx
leaq 0xde60(%rip), %rsi      # 0x1a6e3
leaq -0x88(%rbp), %rdi
callq 0xe8d0
jmp 0xc891
leaq -0x88(%rbp), %rdi
callq 0x7300
jmp 0xc89f
leaq -0x88(%rbp), %rdi
callq 0x4878
leaq -0x89(%rbp), %rdi
callq 0x4470
jmp 0xc923
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xca42
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x18, %esi
callq 0x4410
jmp 0xca42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xc912
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x4878
leaq -0x89(%rbp), %rdi
callq 0x4470
jmp 0xca42
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0x4610
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0x42d0
movq -0xd0(%rbp), %rdi
callq 0x9b90
cmpl $0x1, %eax
jne 0xca1d
movq -0xd0(%rbp), %rdi
movl 0x134(%rdi), %esi
movl 0x138(%rdi), %edx
callq 0xac90
jmp 0xc972
movq -0x60(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4390
jmp 0xc984
leaq -0xb9(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x47a0
movq -0xe0(%rbp), %rdx
leaq 0xdd6e(%rip), %rsi      # 0x1a713
leaq -0xb8(%rbp), %rdi
callq 0xe8d0
jmp 0xc9b3
leaq -0xb8(%rbp), %rdi
callq 0x7140
jmp 0xc9c1
leaq -0xb8(%rbp), %rdi
callq 0x4878
leaq -0xb9(%rbp), %rdi
callq 0x4470
movb $0x1, -0x1(%rbp)
movl $0x1, -0xc0(%rbp)
jmp 0xca2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xca0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4878
leaq -0xb9(%rbp), %rdi
callq 0x4470
jmp 0xca42
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x4878
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x4878
movq -0x50(%rbp), %rdi
callq 0x4780
nopw %cs:(%rax,%rax)