summaryrefslogtreecommitdiff
path: root/legacy/evas/src/bin/evas_cserve2_shm.c
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2012-06-22 20:31:17 +0000
committerRafael Antognolli <antognolli@gmail.com>2012-06-22 20:31:17 +0000
commit64fecc2faba783ef63a719cbf2868458401cb61a (patch)
treed8cd00b8e05173cd44185e81ed98fa950896ee61 /legacy/evas/src/bin/evas_cserve2_shm.c
parentde28f1ed31048b8d899bd932de3b0d95b5bec5f5 (diff)
evas/cserve2: Add font and glyphs loading implementation
to cserve2. Big commit that implements the entire functionality. Besides loading fonts and glyphs, and sharing the glyph bitmaps with clients, it also adds: - new request system, with a much better abstraction; - new working slaves management; - slaves can be threads or process now; - started a debugging and statistics implementation on server. The image caching part still uses the old request and slaves system, but should be changed to use the new one soon and get more easily maintainable. SVN revision: 72699
Diffstat (limited to 'legacy/evas/src/bin/evas_cserve2_shm.c')
-rw-r--r--legacy/evas/src/bin/evas_cserve2_shm.c66
1 files changed, 57 insertions, 9 deletions
diff --git a/legacy/evas/src/bin/evas_cserve2_shm.c b/legacy/evas/src/bin/evas_cserve2_shm.c
index 36291f947c..5e60138b42 100644
--- a/legacy/evas/src/bin/evas_cserve2_shm.c
+++ b/legacy/evas/src/bin/evas_cserve2_shm.c
@@ -27,10 +27,30 @@ struct _Shm_Handle
27 off_t image_offset; 27 off_t image_offset;
28 size_t map_size; 28 size_t map_size;
29 size_t image_size; 29 size_t image_size;
30 int refcount;
31 void *data;
30}; 32};
31 33
32static int id = 0; 34static int id = 0;
33 35
36size_t
37cserve2_shm_size_normalize(size_t size)
38{
39 long pagesize;
40 size_t normalized;
41
42 pagesize = sysconf(_SC_PAGESIZE);
43 if (pagesize < 1)
44 {
45 ERR("sysconf() reported weird value for PAGESIZE, assuming 4096.");
46 pagesize = 4096;
47 }
48
49 normalized = ((size + pagesize - 1) / pagesize) * pagesize;
50
51 return normalized;
52}
53
34Shm_Handle * 54Shm_Handle *
35cserve2_shm_request(size_t size) 55cserve2_shm_request(size_t size)
36{ 56{
@@ -38,7 +58,6 @@ cserve2_shm_request(size_t size)
38 Shm_Handle *shm; 58 Shm_Handle *shm;
39 char shmname[NAME_MAX]; 59 char shmname[NAME_MAX];
40 size_t map_size; 60 size_t map_size;
41 long pagesize;
42 int fd; 61 int fd;
43 62
44 map = calloc(1, sizeof(Shm_Mapping)); 63 map = calloc(1, sizeof(Shm_Mapping));
@@ -59,14 +78,7 @@ cserve2_shm_request(size_t size)
59 } 78 }
60 } while (fd == -1); 79 } while (fd == -1);
61 80
62 pagesize = sysconf(_SC_PAGESIZE); 81 map_size = cserve2_shm_size_normalize(size);
63 if (pagesize < 1)
64 {
65 ERR("sysconf() reported weird value for PAGESIZE, assuming 4096.");
66 pagesize = 4096;
67 }
68
69 map_size = ((size + pagesize - 1) / pagesize) * pagesize;
70 82
71 if (ftruncate(fd, map_size) == -1) 83 if (ftruncate(fd, map_size) == -1)
72 { 84 {
@@ -106,6 +118,9 @@ cserve2_shm_unref(Shm_Handle *shm)
106 Shm_Mapping *map = shm->mapping; 118 Shm_Mapping *map = shm->mapping;
107 119
108 map->segments = eina_inlist_remove(map->segments, EINA_INLIST_GET(shm)); 120 map->segments = eina_inlist_remove(map->segments, EINA_INLIST_GET(shm));
121
122 if (shm->data)
123 munmap(shm->data, shm->image_size);
109 free(shm); 124 free(shm);
110 125
111 if (map->segments) 126 if (map->segments)
@@ -145,3 +160,36 @@ cserve2_shm_size_get(const Shm_Handle *shm)
145{ 160{
146 return shm->image_size; 161 return shm->image_size;
147} 162}
163
164void *
165cserve2_shm_map(Shm_Handle *shm)
166{
167 int fd;
168 const char *name;
169
170 if (shm->refcount++)
171 return shm->data;
172
173 name = cserve2_shm_name_get(shm);
174
175 fd = shm_open(name, O_RDWR, S_IWUSR);
176 if (fd == -1)
177 return MAP_FAILED;
178
179 shm->data = mmap(NULL, shm->image_size, PROT_WRITE, MAP_SHARED,
180 fd, shm->image_offset);
181
182 close(fd);
183
184 return shm->data;
185}
186
187void
188cserve2_shm_unmap(Shm_Handle *shm)
189{
190 if (--shm->refcount)
191 return;
192
193 munmap(shm->data, shm->image_size);
194 shm->data = NULL;
195}