コード例 #1
0
ファイル: gpio_manager.c プロジェクト: vincent-tr/bouh-mylife
void gpio_terminate()
{
	io_terminate();
	pwm_terminate();
	lock_terminate();

	log_assert(list_is_empty(&gpios));
	log_assert(list_is_empty(&types));
}
コード例 #2
0
ファイル: wincache_fcnotify.c プロジェクト: juokaz/wincache
void fcnotify_terminate(fcnotify_context * pnotify)
{
    dprintverbose("start fcnotify_terminate");

    if(pnotify != NULL)
    {
        if(pnotify->listen_thread != NULL)
        {
            if(pnotify->port_handle != NULL)
            {
                /* Post termination key to completion port to terminate thread */
                PostQueuedCompletionStatus(pnotify->port_handle, 0, FCNOTIFY_TERMKEY, NULL);

                /* Wait for thread to finish */
                WaitForSingleObject(pnotify->listen_thread, INFINITE);
            }

            CloseHandle(pnotify->listen_thread);
            pnotify->listen_thread = NULL;
        }

        if(pnotify->port_handle != NULL)
        {
            CloseHandle(pnotify->port_handle);
            pnotify->port_handle = NULL;
        }

        if(pnotify->fclock != NULL)
        {
            lock_terminate(pnotify->fclock);
            lock_destroy(pnotify->fclock);

            pnotify->fclock = NULL;
        }

        if(pnotify->pidhandles != NULL)
        {
            zend_hash_destroy(pnotify->pidhandles);
            alloc_pefree(pnotify->pidhandles);

            pnotify->pidhandles = NULL;
        }

        pnotify->fcaplist = NULL;
        pnotify->fcheader = NULL;
        pnotify->fcalloc  = NULL;
    }

    dprintverbose("end fcnotify_terminate");

    return;
}
コード例 #3
0
ファイル: wincache_fcache.c プロジェクト: juokaz/wincache
void fcache_terminate(fcache_context * pfcache)
{
    dprintverbose("start fcache_terminate");

    if(pfcache != NULL)
    {
        if(pfcache->header != NULL)
        {
            InterlockedDecrement(&pfcache->header->mapcount);
            pfcache->header = NULL;
        }

        if(pfcache->palloc != NULL)
        {
            alloc_terminate(pfcache->palloc);
            alloc_destroy(pfcache->palloc);

            pfcache->palloc = NULL;
        }

        if(pfcache->pfilemap != NULL)
        {
            filemap_terminate(pfcache->pfilemap);
            filemap_destroy(pfcache->pfilemap);

            pfcache->pfilemap = NULL;
        }

        if(pfcache->prwlock != NULL)
        {
            lock_terminate(pfcache->prwlock);
            lock_destroy(pfcache->prwlock);

            pfcache->prwlock = NULL;
        }

        if(pfcache->hinitdone != NULL)
        {
            CloseHandle(pfcache->hinitdone);
            pfcache->hinitdone = NULL;
        }
    }

    dprintverbose("end fcache_terminate");

    return;
}
コード例 #4
0
ファイル: wincache_fcnotify.c プロジェクト: juokaz/wincache
int fcnotify_initialize(fcnotify_context * pnotify, unsigned short islocal, void * paplist, alloc_context * palloc, unsigned int filecount TSRMLS_DC)
{
    int               result   = NONFATAL;
    unsigned short    locktype = LOCK_TYPE_SHARED;
    fcnotify_header * header   = NULL;
    unsigned int      msize    = 0;

    _ASSERT(pnotify != NULL);
    _ASSERT(paplist != NULL);
    _ASSERT(palloc  != NULL);
    _ASSERT(palloc->memaddr != NULL);

    if(islocal)
    {
        locktype = LOCK_TYPE_LOCAL;
        pnotify->islocal = islocal;
    }

    pnotify->islocal   = islocal;
    pnotify->fcaplist  = paplist;
    pnotify->fcalloc   = palloc;

    pnotify->processid = WCG(fmapgdata)->pid;
    pnotify->fcmemaddr = palloc->memaddr;
    pnotify->lscavenge = GetTickCount();

    /* Get memory for fcnotify header */
    msize = sizeof(fcnotify_header) + (filecount - 1) * sizeof(size_t);
    pnotify->fcheader = (fcnotify_header *)alloc_get_cacheheader(pnotify->fcalloc, msize, CACHE_TYPE_FCNOTIFY);
    if(pnotify->fcheader == NULL)
    {
        result = FATAL_FCNOTIFY_INITIALIZE;
        goto Finished;
    }

    header = pnotify->fcheader;
 
    /* Create reader writer lock for the file change notification hashtable */
    result = lock_create(&pnotify->fclock);
    if(FAILED(result))
    {
        goto Finished;
    }

    result = lock_initialize(pnotify->fclock, "FILE_CHANGE_NOTIFY", 1, locktype, LOCK_USET_SREAD_XWRITE, &header->rdcount TSRMLS_CC);
    if(FAILED(result))
    {
        goto Finished;
    }

    /* Create IO completion port */
    pnotify->port_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
    if(pnotify->port_handle == NULL)
    {
        result = FATAL_FCNOTIFY_INITIALIZE;
        goto Finished;
    }

    /* Create listener thread */
    pnotify->listen_thread = CreateThread(NULL, 0, change_notification_thread, (void *)pnotify, 0, NULL);
    if(pnotify->listen_thread == NULL)
    {
        result = FATAL_FCNOTIFY_INITIALIZE;
        goto Finished;
    }

    /* Create pidhandles hashtable */
    pnotify->pidhandles = (HashTable *)alloc_pemalloc(sizeof(HashTable));
    if(pnotify->pidhandles == NULL)
    {
        result = FATAL_OUT_OF_LMEMORY;
        goto Finished;
    }

    zend_hash_init(pnotify->pidhandles, 0, NULL, NULL, 1);

Finished:

    if(FAILED(result))
    {
        dprintimportant("failure %d in fcnotify_initialize", result);
        _ASSERT(result > WARNING_COMMON_BASE);

        if(pnotify->listen_thread != NULL)
        {
            CloseHandle(pnotify->listen_thread);
            pnotify->listen_thread = NULL;
        }

        if(pnotify->port_handle != NULL)
        {
            CloseHandle(pnotify->port_handle);
            pnotify->port_handle = NULL;
        }

        if(pnotify->fclock != NULL)
        {
            lock_terminate(pnotify->fclock);
            lock_destroy(pnotify->fclock);

            pnotify->fclock = NULL;
        }

        if(pnotify->pidhandles != NULL)
        {
            zend_hash_destroy(pnotify->pidhandles);
            alloc_pefree(pnotify->pidhandles);

            pnotify->pidhandles = NULL;
        }
        
        pnotify->fcaplist = NULL;
        pnotify->fcheader = NULL;
        pnotify->fcalloc  = NULL;
    }

    return result;
}
コード例 #5
0
ファイル: wincache_fcache.c プロジェクト: juokaz/wincache
int fcache_initialize(fcache_context * pfcache, unsigned short islocal, unsigned short cachekey, unsigned int cachesize, unsigned int maxfsize TSRMLS_DC)
{
    int             result   = NONFATAL;
    size_t          size     = 0;
    fcache_header * header   = NULL;
    unsigned short  mapclass = FILEMAP_MAP_SRANDOM;
    unsigned short  locktype = LOCK_TYPE_SHARED;
    unsigned char   isfirst  = 1;
    char            evtname[   MAX_PATH];

    dprintverbose("start fcache_initialize");

    _ASSERT(pfcache   != NULL);
    _ASSERT(cachekey  != 0);
    _ASSERT(cachesize >= FCACHE_SIZE_MINIMUM && cachesize <= FCACHE_SIZE_MAXIMUM);
    _ASSERT(maxfsize  >= FILE_SIZE_MINIMUM   && maxfsize  <= FILE_SIZE_MAXIMUM);

    /* Initialize memory map to store code files */
    result = filemap_create(&pfcache->pfilemap);
    if(FAILED(result))
    {
        goto Finished;
    }

    pfcache->cachekey = cachekey;

    if(islocal)
    {
        mapclass = FILEMAP_MAP_LRANDOM;
        locktype = LOCK_TYPE_LOCAL;

        pfcache->islocal = islocal;
    }

    /* shmfilepath = NULL to use page file for shared memory */
    result = filemap_initialize(pfcache->pfilemap, FILEMAP_TYPE_FILECONTENT, cachekey, mapclass, cachesize, NULL TSRMLS_CC);
    if(FAILED(result))
    {
        goto Finished;
    }

    pfcache->memaddr = (char *)pfcache->pfilemap->mapaddr;
    size = filemap_getsize(pfcache->pfilemap TSRMLS_CC);

    /* Create allocator for filecache segment */
    result = alloc_create(&pfcache->palloc);
    if(FAILED(result))
    {
        goto Finished;
    }

    /* initmemory = 1 for all page file backed shared memory allocators */
    result = alloc_initialize(pfcache->palloc, islocal, "FILECONTENT_SEGMENT", cachekey, pfcache->memaddr, size, 1 TSRMLS_CC);
    if(FAILED(result))
    {
        goto Finished;
    }

    /* Get memory for cache header */
    pfcache->header = (fcache_header *)alloc_get_cacheheader(pfcache->palloc, sizeof(fcache_header), CACHE_TYPE_FILECONTENT);
    if(pfcache->header == NULL)
    {
        result = FATAL_FCACHE_INITIALIZE;
        goto Finished;
    }

    header = pfcache->header;

    /* Create xread xwrite lock for the filecache */
    result = lock_create(&pfcache->prwlock);
    if(FAILED(result))
    {
        goto Finished;
    }

    result = lock_initialize(pfcache->prwlock, "FILECONTENT_CACHE", cachekey, locktype, LOCK_USET_XREAD_XWRITE, NULL TSRMLS_CC);
    if(FAILED(result))
    {
        goto Finished;
    }

    result = lock_getnewname(pfcache->prwlock, "FCACHE_INIT", evtname, MAX_PATH);
    if(FAILED(result))
    {
        goto Finished;
    }

    pfcache->hinitdone = CreateEvent(NULL, TRUE, FALSE, evtname);
    if(pfcache->hinitdone == NULL)
    {
        result = FATAL_FCACHE_INIT_EVENT;
        goto Finished;
    }

    if(GetLastError() == ERROR_ALREADY_EXISTS)
    {
        _ASSERT(islocal == 0);
        isfirst = 0;

        /* Wait for other process to initialize completely */
        WaitForSingleObject(pfcache->hinitdone, INFINITE);
    }

    /* Initialize the fcache_header if its not initialized already */
    if(islocal || isfirst)
    {
        lock_writelock(pfcache->prwlock);

        header->mapcount    = 1;
        header->itemcount   = 0;
        header->hitcount    = 0;
        header->misscount   = 0;

        SetEvent(pfcache->hinitdone);
        
        lock_writeunlock(pfcache->prwlock);
    }
    else
    {
        /* Increment the mapcount */
        InterlockedIncrement(&header->mapcount);
    }

    /* Keep maxfsize in fcache_context */
    pfcache->maxfsize = maxfsize * 1024;

Finished:

    if(FAILED(result))
    {
        dprintimportant("failure %d in fcache_initialize", result);
        _ASSERT(result > WARNING_COMMON_BASE);

        if(pfcache->palloc != NULL)
        {
            alloc_terminate(pfcache->palloc);
            alloc_destroy(pfcache->palloc);

            pfcache->palloc = NULL;
        }

        if(pfcache->pfilemap != NULL)
        {
            filemap_terminate(pfcache->pfilemap);
            filemap_destroy(pfcache->pfilemap);

            pfcache->pfilemap = NULL;
        }

        if(pfcache->prwlock != NULL)
        {
            lock_terminate(pfcache->prwlock);
            lock_destroy(pfcache->prwlock);

            pfcache->prwlock = NULL;
        }

        if(pfcache->hinitdone != NULL)
        {
            CloseHandle(pfcache->hinitdone);
            pfcache->hinitdone = NULL;
        }
    }

    dprintverbose("end fcache_initialize");

    return result;
}