ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/RdataShareMap.cpp
(Generate patch)

Comparing ray/src/rt/RdataShareMap.cpp (file contents):
Revision 2.1 by greg, Tue Oct 29 00:36:54 2024 UTC vs.
Revision 2.3 by greg, Thu Oct 31 23:55:04 2024 UTC

# Line 36 | Line 36 | RdataShareMap::RdataShareMap(const char *name, int fla
36                  error(CONSISTENCY, "bad RDSextend in RdataShareMap()");
37                  return;
38          }
39 <        int     mmprot = PROT_NONE;
40 <        int     oflags = 0;
39 >        int     oflags, mmprot;
40          switch (flags & (RDSread|RDSwrite)) {
41          case RDSread|RDSwrite:
42 <                mmprot |= PROT_READ|PROT_WRITE;
43 <                oflags |= O_RDWR;
42 >                mmprot = PROT_READ|PROT_WRITE;
43 >                oflags = O_RDWR|O_CREAT;
44                  break;
46        case RDSread:
47                mmprot |= PROT_READ;
48                oflags |= O_RDONLY;
49                break;
45          case RDSwrite:
46 <                mmprot |= PROT_WRITE;
47 <                oflags |= O_WRONLY;
46 >                mmprot = PROT_WRITE;
47 >                oflags = O_RDWR|O_CREAT;        // XXX system limitation
48                  break;
49 +        case RDSread:
50 +                mmprot = PROT_READ;
51 +                oflags = O_RDONLY;
52 +                break;
53          }
54          int     fd = -1;
55          if (name) {                     // opening a shared file
56 <                if (flags & RDSexcl) oflags |= O_CREAT|O_EXCL;
56 >                if (flags & RDSexcl) oflags |= O_EXCL;
57                  else if (flags & RDSextend && !siz) oflags |= O_TRUNC;
58                  fd = open(name, oflags, 0666);
59                  if (fd < 0) {
# Line 81 | Line 80 | RdataShareMap::RdataShareMap(const char *name, int fla
80                          return;
81                  }
82          }
83 <        mmorg = (void *)mmap(NULL, siz, mmprot,
83 >        if (siz) mmorg = (void *)mmap(NULL, siz, mmprot,
84                                  MAP_SHARED|(name ? MAP_FILE : MAP_ANON), fd, 0);
85          close(fd);
86          if (mmorg == MAP_FAILED) {
# Line 108 | Line 107 | RdataShareMap::~RdataShareMap()
107   size_t
108   RdataShareMap::Resize(size_t new_siz)
109   {
111        if (!mmorg)
112                return 0;
110          if (new_siz > 0) {
111                  if (new_siz == osiz)
112                          return osiz;
# Line 156 | Line 153 | RdataShareMap::Resize(size_t new_siz)
153                          close(fd);
154                          return 0;
155                  }
156 <                munmap(mmorg, osiz);
156 >                if (mmorg) munmap(mmorg, osiz);
157                  mmorg = mmap(NULL, new_siz,
158                                  mode&RDSread ? PROT_READ|PROT_WRITE : PROT_WRITE,
159                                  MAP_SHARED|MAP_FILE, fd, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines