From 7b23eefd840a23d09859a4edf71eb30d80991714 Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Thu, 6 Jan 2022 13:04:37 +0900 Subject: v0.5.6 --- src/inpla.y | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/inpla.y') diff --git a/src/inpla.y b/src/inpla.y index 45bbbd1..b57c3a7 100644 --- a/src/inpla.y +++ b/src/inpla.y @@ -1,4 +1,5 @@ %{ +%{ #define _GNU_SOURCE #include #include @@ -33,13 +34,13 @@ // ---------------------------------------------- -int MaxThreadNum=1; +int MaxThreadsNum=1; #ifdef THREAD #include extern int pthread_setconcurrency(int concurrency); -int ActiveThreadNum=0; +int SleepingThreadsNum=0; // for cas spinlock #include "cas_spinlock.h" @@ -671,8 +672,7 @@ void VM_InitBuffer(VirtualMachine *vm, int size) { // Agent Heap - //vm->agentHeap.lastAlloc = size-1; - vm->agentHeap.lastAlloc = 0; + vm->agentHeap.lastAlloc = size-1; vm->agentHeap.heap = (VALUE *)malloc(sizeof(Agent)*size); vm->agentHeap.size = size; if (vm->agentHeap.heap == (VALUE *)NULL) { @@ -688,7 +688,6 @@ void VM_InitBuffer(VirtualMachine *vm, int size) { //size = size/2; vm->nameHeap.lastAlloc = size-1; - //vm->nameHeap.lastAlloc = 0; vm->nameHeap.heap = (VALUE *)malloc(sizeof(Name)*size); vm->nameHeap.size = size; if (vm->nameHeap.heap == (VALUE *)NULL) { @@ -1455,7 +1454,7 @@ void PushEQStack(VALUE l, VALUE r) { unlock(&GlobalEQS.lock); - if (ActiveThreadNum < MaxThreadNum) { + if (SleepingThreadsNum > 0) { pthread_mutex_lock(&Sleep_lock); pthread_cond_signal(&EQStack_not_empty); pthread_mutex_unlock(&Sleep_lock); @@ -5406,7 +5405,7 @@ void *ExecCode(int mode, VirtualMachine *restrict vm, void *restrict *code) { if ((!IS_FIXNUM(a1)) && (IS_NAMEID(BASIC(a1)->id)) && \ (NAME(a1)->port == (VALUE)NULL)) { \ if (!(__sync_bool_compare_and_swap(&(NAME(a1)->port), NULL, a2))) { \ - if (MaxThreadNum - ActiveThreadNum > 0) { \ + if (SleepingThreadsNum > 0) { \ PushEQStack(NAME(a1)->port,a2); \ freeName(a1); \ } else { \ @@ -5417,7 +5416,7 @@ void *ExecCode(int mode, VirtualMachine *restrict vm, void *restrict *code) { } else if ((!IS_FIXNUM(a2)) && (IS_NAMEID(BASIC(a2)->id)) && \ (NAME(a2)->port == (VALUE)NULL)) { \ if (!(__sync_bool_compare_and_swap(&(NAME(a2)->port), NULL, a1))) { \ - if (MaxThreadNum - ActiveThreadNum > 0) { \ + if (SleepingThreadsNum > 0) { \ PushEQStack(a1,NAME(a2)->port); \ freeName(a2); \ } else { \ @@ -5426,7 +5425,7 @@ void *ExecCode(int mode, VirtualMachine *restrict vm, void *restrict *code) { } \ } \ } else { \ - if (MaxThreadNum - ActiveThreadNum > 0) { \ + if (SleepingThreadsNum > 0) { \ PushEQStack(a1,a2); \ } else { \ VM_PushEQStack(vm, a1,a2); \ @@ -7046,9 +7045,9 @@ void *tpool_thread(void *arg) { VALUE t1, t2; while (!PopEQStack(vm, &t1, &t2)) { pthread_mutex_lock(&Sleep_lock); - ActiveThreadNum--; - - if (ActiveThreadNum == 0) { + SleepingThreadsNum++; + + if (SleepingThreadsNum == MaxThreadsNum) { pthread_mutex_lock(&AllSleep_lock); pthread_cond_signal(&ActiveThread_all_sleep); pthread_mutex_unlock(&AllSleep_lock); @@ -7056,7 +7055,7 @@ void *tpool_thread(void *arg) { // printf("[Thread %d is slept.]\n", vm->id); pthread_cond_wait(&EQStack_not_empty, &Sleep_lock); - ActiveThreadNum++; + SleepingThreadsNum--; pthread_mutex_unlock(&Sleep_lock); // printf("[Thread %d is waked up.]\n", vm->id); @@ -7087,21 +7086,21 @@ void tpool_init(unsigned int agentBufferSize, unsigned int eqstack_size) { pthread_setconcurrency(CpuNum); - Threads = (pthread_t *)malloc(sizeof(pthread_t)*MaxThreadNum); + SleepingThreadsNum = 0; + Threads = (pthread_t *)malloc(sizeof(pthread_t)*MaxThreadsNum); if (Threads == NULL) { printf("the thread pool could not be created."); exit(-1); } - ActiveThreadNum = MaxThreadNum; - VMs = malloc(sizeof(VirtualMachine*)*MaxThreadNum); + VMs = malloc(sizeof(VirtualMachine*)*MaxThreadsNum); if (VMs == NULL) { printf("the thread pool could not be created."); exit(-1); } - for (i=0; iid = i; Init_VM(VMs[i], agentBufferSize, eqstack_size); @@ -7118,7 +7117,7 @@ void tpool_init(unsigned int agentBufferSize, unsigned int eqstack_size) { void tpool_destroy() { int i; - for (i=0; i Set the number of threads (Default: %8d)\n", - MaxThreadNum); + MaxThreadsNum); #else printf(" -w Enable Weak Reduction strategy (Default: false)\n" @@ -7454,7 +7454,7 @@ int main(int argc, char *argv[]) exit(-1); } - MaxThreadNum=param; + MaxThreadsNum=param; break; #else case 'w': @@ -7506,7 +7506,7 @@ int main(int argc, char *argv[]) - max_AgentBuffer = min_AgentBuffer + max_AgentBuffer/MaxThreadNum; + max_AgentBuffer = min_AgentBuffer + max_AgentBuffer/MaxThreadsNum; //printf("max_AgentBuffer:%d\n", max_AgentBuffer); IdTable_init(); -- cgit v1.2.3