discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Discuss-gnuradio] binary installer gnuradio-2.5cvs.win32.exeforwind


From: Beck, Andrew Thomas - BECAT001
Subject: RE: [Discuss-gnuradio] binary installer gnuradio-2.5cvs.win32.exeforwindows
Date: Fri, 12 Aug 2005 14:13:53 +0930

> Trust me, they have to be contiguous... (circular buffer hack).

I figured that would be the case, so didn't bother looking. Anyway
I think I fixed it. There was a logic error in the mapping algorithm.
If the second mapping wasn't contiguous, it just tried to map to the
same space over and over & so never succeeded.

Here is a new version of
gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size)
from src/lib/runtime/gr_vmcircbuf_createmapping.c. I'll submit a patch
as well.

cheers,
andrew


gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size)
  : gr_vmcircbuf (size)
{

#if !defined(HAVE_CREATEFILEMAPPING)
    fprintf (stderr, "%s: createfilemapping is not available\n",__FUNCTION__);
    throw std::runtime_error ("gr_vmcircbuf_createfilemapping");
#else

    if (size <= 0 || (size % gr_pagesize ()) != 0)
    {
        fprintf (stderr, "gr_vmcircbuf_createfilemapping: invalid size = %d\n", size);
        throw std::runtime_error ("gr_vmcircbuf_createfilemapping");
    }
    char    seg_name[1024];
    snprintf (seg_name, sizeof (seg_name),
        "/gnuradio-%d-%d", getpid (), s_seg_counter);

    d_handle = CreateFileMapping(INVALID_HANDLE_VALUE,    // use paging file
                    NULL,                    // default security
                    PAGE_READWRITE,          // read/write access
                    0,                       // max. object size
                    size,                // buffer size
                    seg_name);                 // name of mapping object

    s_seg_counter++;
    if (d_handle == NULL || d_handle == INVALID_HANDLE_VALUE)
    {
        char msg[1024];
        snprintf (msg, sizeof (msg), "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s] :%d", seg_name,GetLastError());
        perror (msg);
        throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
    }


    int i = 0;

    d_first_copy = d_second_copy = NULL;
   
    while (i++ < 8 && d_second_copy == NULL)
    {
        // keep the first map allocation to force allocation in a new address
        // space
        LPVOID first_tmp = d_first_copy;
       
        d_first_copy =  MapViewOfFile((HANDLE)d_handle,   // handle to map object
                            FILE_MAP_WRITE,//FILE_MAP_ALL_ACCESS, // read/write permission
                            0,
                            0,
                            size);
  
        if (d_first_copy == NULL)
        {
            CloseHandle(d_handle);         // cleanup
            char msg[1024];
            snprintf (msg, sizeof (msg), "gr_vmcircbuf_mmap_createfilemapping: MapViewOfFile (1) :%d", GetLastError());
            perror (msg);
            throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
        }

        // NOTE: d_second_copy will be NULL if MapViewFileEx() fails to allocate the
        //       requested address space
        d_second_copy =  MapViewOfFileEx((HANDLE)d_handle,   // handle to map object
                            FILE_MAP_WRITE, // read/write permission
                            0,
                            0,
                            size,
                            (char *)d_first_copy + size);//(LPVOID) ((char *)d_first_copy + size));

        if (first_tmp)
            UnmapViewOfFile(first_tmp);
     }


#ifdef DEBUG
    if (i!=0)
        fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: contiguous? mmap %p %p %p %p, %d\n",
          (char *)d_first_copy, (char *)d_second_copy, size, (char *)d_first_copy + size,i);
#endif

    if (d_second_copy == NULL)
    {
                                           // cleanup
        fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: non contiguous mmap %p %p %p %p\n",
            (char *)d_first_copy, (char *)d_second_copy, size, (char *)d_first_copy + size);
        UnmapViewOfFile(d_first_copy);
        CloseHandle(d_handle);                      // cleanup
        throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping");
    }

    // Now remember the important stuff
    d_base = (char *) d_first_copy;
    //d_second =(char *) d_second_copy;
    d_size = size;
#endif /*HAVE_CREATEFILEMAPPING*/
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]