Ejemplo n.º 1
0
Archivo: Task.c Proyecto: Eufavn/ghc
static void
freeTask (Task *task)
{
    InCall *incall, *next;

    // We only free resources if the Task is not in use.  A
    // Task may still be in use if we have a Haskell thread in
    // a foreign call while we are attempting to shut down the
    // RTS (see conc059).
#if defined(THREADED_RTS)
    closeCondition(&task->cond);
    closeMutex(&task->lock);
#endif

    for (incall = task->incall; incall != NULL; incall = next) {
        next = incall->prev_stack;
        stgFree(incall);
    }
    for (incall = task->spare_incalls; incall != NULL; incall = next) {
        next = incall->next;
        stgFree(incall);
    }

    stgFree(task);
}
Ejemplo n.º 2
0
Archivo: Task.c Proyecto: A1kmm/ghc
nat
freeTaskManager (void)
{
    Task *task, *next;
    nat tasksRunning = 0;

    ACQUIRE_LOCK(&all_tasks_mutex);

    for (task = all_tasks; task != NULL; task = next) {
        next = task->all_next;
        if (task->stopped) {
            freeTask(task);
        } else {
            tasksRunning++;
        }
    }

    debugTrace(DEBUG_sched, "freeing task manager, %d tasks still running",
               tasksRunning);

    all_tasks = NULL;

    RELEASE_LOCK(&all_tasks_mutex);

#if defined(THREADED_RTS)
    closeMutex(&all_tasks_mutex); 
#if !defined(MYTASK_USE_TLV)
    freeThreadLocalKey(&currentTaskKey);
#endif
#endif

    tasksInitialized = 0;

    return tasksRunning;
}
Ejemplo n.º 3
0
ArchMultithreadPosix::~ArchMultithreadPosix()
{
	assert(s_instance != NULL);

	closeMutex(m_threadMutex);
	s_instance = NULL;
}
void
ArchMultithreadWindows::closeCondVar(ArchCond cond)
{
    CloseHandle(cond->m_events[ArchCondImpl::kSignal]);
    CloseHandle(cond->m_events[ArchCondImpl::kBroadcast]);
    closeMutex(cond->m_waitCountMutex);
    delete cond;
}
Ejemplo n.º 5
0
void XMLPlatformUtils::platformTerm()
{
    // delete the mutex we created
	closeMutex(atomicOpsMutex->fHandle);
	atomicOpsMutex->fHandle = 0;
    delete atomicOpsMutex;
    atomicOpsMutex = 0;
}
Ejemplo n.º 6
0
static void *itimer_thread_func(void *_handle_tick)
{
    TickProc handle_tick = _handle_tick;
    uint64_t nticks;
    int timerfd = -1;

#if defined(USE_TIMERFD_FOR_ITIMER) && USE_TIMERFD_FOR_ITIMER
    struct itimerspec it;
    it.it_value.tv_sec  = TimeToSeconds(itimer_interval);
    it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000;
    it.it_interval = it.it_value;

    timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
    if (timerfd == -1) {
        sysErrorBelch("timerfd_create");
        stg_exit(EXIT_FAILURE);
    }
    if (!TFD_CLOEXEC) {
      fcntl(timerfd, F_SETFD, FD_CLOEXEC);
    }
    if (timerfd_settime(timerfd, 0, &it, NULL)) {
        sysErrorBelch("timerfd_settime");
        stg_exit(EXIT_FAILURE);
    }
#endif

    while (!exited) {
        if (USE_TIMERFD_FOR_ITIMER) {
            if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks)) {
                if (errno != EINTR) {
                    sysErrorBelch("Itimer: read(timerfd) failed");
                }
            }
        } else {
            if (usleep(TimeToUS(itimer_interval)) != 0 && errno != EINTR) {
                sysErrorBelch("usleep(TimeToUS(itimer_interval) failed");
            }
        }

        // first try a cheap test
        if (stopped) {
            ACQUIRE_LOCK(&mutex);
            // should we really stop?
            if (stopped) {
                waitCondition(&start_cond, &mutex);
            }
            RELEASE_LOCK(&mutex);
        } else {
            handle_tick(0);
        }
    }

    if (USE_TIMERFD_FOR_ITIMER)
        close(timerfd);
    closeMutex(&mutex);
    closeCondition(&start_cond);
    return NULL;
}
Ejemplo n.º 7
0
void exitStaticPtrTable() {
  if (spt) {
    freeHashTable(spt, freeSptEntry);
    spt = NULL;
#ifdef THREADED_RTS
    closeMutex(&spt_lock);
#endif
  }
}
Ejemplo n.º 8
0
void XMLPlatformUtils::platformTerm()
{
#if !defined(APP_NO_THREADS)
    // delete the mutex we created
	closeMutex(atomicOpsMutex->fHandle);
	atomicOpsMutex->fHandle = 0;
	delete atomicOpsMutex;
    atomicOpsMutex = 0;
#endif
}
Ejemplo n.º 9
0
Archivo: Storage.c Proyecto: Eufavn/ghc
void
freeStorage (rtsBool free_heap)
{
    stgFree(generations);
    if (free_heap) freeAllMBlocks();
#if defined(THREADED_RTS)
    closeMutex(&sm_mutex);
#endif
    stgFree(nurseries);
    freeGcThreads();
}
Ejemplo n.º 10
0
void
freeSignalHandlers(void) {
    if (signal_handlers != NULL) {
        stgFree(signal_handlers);
        signal_handlers = NULL;
        nHandlers = 0;
        n_haskell_handlers = 0;
    }
#ifdef THREADED_RTS
    closeMutex(&sig_mutex);
#endif
}
Ejemplo n.º 11
0
void
freeStorage (rtsBool free_heap)
{
    stgFree(generations);
    if (free_heap) freeAllMBlocks();
#if defined(THREADED_RTS)
    closeMutex(&sm_mutex);
#endif
    stgFree(nurseries);
#if defined(THREADED_RTS) && defined(llvm_CC_FLAVOR) && (CC_SUPPORTS_TLS == 0)
    freeThreadLocalKey(&gctKey);
#endif
    freeGcThreads();
}
Ejemplo n.º 12
0
void
exitGlobalStore(void)
{
    uint32_t i;
#ifdef THREADED_RTS
    closeMutex(&globalStoreLock);
#endif
    for (i=0; i < MaxStoreKey; i++) {
        if (store[i] != 0) {
            freeStablePtr(store[i]);
            store[i] = 0;
        }
    }
}
Ejemplo n.º 13
0
void
exitStablePtrTable(void)
{
    if (stable_ptr_table)
        stgFree(stable_ptr_table);
    stable_ptr_table = NULL;
    SPT_size = 0;

    freeOldSPTs();

#if defined(THREADED_RTS)
    closeMutex(&stable_ptr_mutex);
#endif
}
Ejemplo n.º 14
0
Archivo: Stable.c Proyecto: Eufavn/ghc
void
exitStablePtrTable(void)
{
  if (addrToStableHash)
    freeHashTable(addrToStableHash, NULL);
  addrToStableHash = NULL;
  if (stable_ptr_table)
    stgFree(stable_ptr_table);
  stable_ptr_table = NULL;
  SPT_size = 0;
#ifdef THREADED_RTS
  closeMutex(&stable_mutex);
#endif
}
Ejemplo n.º 15
0
void XMLPlatformUtils::platformTerm()
{
    // delete the mutex we created
    closeMutex(atomicOpsMutex->fHandle);
    atomicOpsMutex->fHandle = 0;
    delete atomicOpsMutex;
    atomicOpsMutex = 0;

    usdetach (arena);
    unlink (arenaName);
    free (arenaName);

    arena = NULL;
    // We don't have any termination requirements at this time
}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
    #ifdef __linux__
	initscr();
    clear();
    noecho();
    refresh();
    nodelay(stdscr, TRUE);
    #endif
    char symbol;
    int threadsCount = 0;
    int currentThread = 1;
    Thread* thread[THREADS_NUMBER];
    while(TRUE)
    {
    	symbol = getch_noblock();
    	Sleep(SHORT_SLEEP);
        fflush(stdout);
        #ifdef __linux__
        refresh();
        #endif

    	switch (symbol)
    	{
    		case '+':
    		    if (threadsCount < THREADS_NUMBER)
    		    {
    		    	thread[threadsCount++] = new Thread(threadsCount + 1);
    		    }
    		    break;

    		case '-':
    		    if (threadsCount > 0)
    		    {
    		    	thread[--threadsCount]->closeThread();
    		    }
    		    break;

    		case 'q':
    		    if (threadsCount > 0)
    		    {
    		    	for (int i = 0; i < threadsCount; i++)
    		    	{
    		    		thread[i]->closeThread();
    		    		#ifdef __linux__
    		    		pthread_join(thread[i]->getInner(), NULL);
    		    		#endif
    		    	}
    		    }
    		    #ifdef __linux__
    		    clear();
    		    endwin();
    		    #elif _WIN32
    		    closeMutex();
    		    #endif
    		    return 0;
    	}
    	if (threadsCount && thread[currentThread - 1]->canPrint())
        {
            if (currentThread >= threadsCount)
                currentThread = 1;
            else
                currentThread++;
            thread[currentThread - 1]->startPrint();
        }
        #ifdef __linux__
        refresh();
        #endif
    }
}