summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2018-11-02 13:44:39 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-11-02 13:54:40 +0000
commit01c756a851bb0e03294486d9477d7568870ba3b8 (patch)
treec282fed75a88c77f302e018504b98d121b3ada12 /src/generic
parent1c9c8beb40f6e0fca90034fd026964c30235f4cf (diff)
evas - generic loaders - use eina properly so windows build works
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/evas/common/shmfile.c57
-rw-r--r--src/generic/evas/common/timeout.c4
-rw-r--r--src/generic/evas/gst/main.c4
-rw-r--r--src/generic/evas/pdf/main.cpp9
4 files changed, 65 insertions, 9 deletions
diff --git a/src/generic/evas/common/shmfile.c b/src/generic/evas/common/shmfile.c
index 9beb1161d8..0f9361397c 100644
--- a/src/generic/evas/common/shmfile.c
+++ b/src/generic/evas/common/shmfile.c
@@ -11,17 +11,27 @@
11# include <netinet/in.h> 11# include <netinet/in.h>
12#endif 12#endif
13#include <time.h> 13#include <time.h>
14#include <sys/mman.h> 14#ifdef HAVE_SHM_OPEN
15# include <sys/mman.h>
16#endif
15#include <sys/stat.h> 17#include <sys/stat.h>
16#include <fcntl.h> 18#include <fcntl.h>
17#include <string.h> 19#include <string.h>
18#include <zlib.h> 20#include <zlib.h>
19 21
22#ifdef _WIN32
23# include <windows.h>
24#endif
25
20#ifdef __cplusplus 26#ifdef __cplusplus
21extern "C" { 27extern "C" {
22#endif 28#endif
23 29
30#ifdef _WIN32
31HANDLE shm_fd = NULL;
32#else
24int shm_fd = -1; 33int shm_fd = -1;
34#endif
25static int shm_size = 0; 35static int shm_size = 0;
26void *shm_addr = NULL; 36void *shm_addr = NULL;
27char *shmfile = NULL; 37char *shmfile = NULL;
@@ -29,7 +39,31 @@ char *shmfile = NULL;
29void 39void
30shm_alloc(unsigned long dsize) 40shm_alloc(unsigned long dsize)
31{ 41{
32#ifdef HAVE_SHM_OPEN 42#ifdef _WIN32
43 if (!shmfile) shmfile = malloc(1024);
44 if (!shmfile) goto failed;
45 shmfile[0] = 0;
46 srand(time(NULL));
47 do
48 {
49 snprintf(shmfile, 1024, "/evas-loader.%i.%i",
50 (int)getpid(), (int)rand());
51 shm_fd = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
52 0, dsize, shmfile);
53 }
54 while ((shm_fd == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS));
55
56 shm_addr = MapViewOfFile(shm_fd, FILE_MAP_WRITE, 0, 0, dsize);
57 if (!shm_addr)
58 {
59 free(shmfile);
60 CloseHandle(shm_fd);
61 goto failed;
62 }
63 shm_size = dsize;
64 return;
65failed:
66#elif HAVE_SHM_OPEN
33 if (!shmfile) shmfile = malloc(1024); 67 if (!shmfile) shmfile = malloc(1024);
34 if (!shmfile) goto failed; 68 if (!shmfile) goto failed;
35 shmfile[0] = 0; 69 shmfile[0] = 0;
@@ -67,7 +101,18 @@ failed:
67void 101void
68shm_free(void) 102shm_free(void)
69{ 103{
70#ifdef HAVE_SHM_OPEN 104#ifdef _WIN32
105 if (shm_fd)
106 {
107 UnmapViewOfFile(shm_addr);
108 CloseHandle(shm_fd);
109 free(shmfile);
110 shm_addr = NULL;
111 shm_fd = NULL;
112 shmfile = NULL;
113 return;
114 }
115#elif HAVE_SHM_OPEN
71 if (shm_fd >= 0) 116 if (shm_fd >= 0)
72 { 117 {
73 munmap(shm_addr, shm_size); 118 munmap(shm_addr, shm_size);
@@ -81,7 +126,11 @@ shm_free(void)
81#endif 126#endif
82 free(shm_addr); 127 free(shm_addr);
83 shm_addr = NULL; 128 shm_addr = NULL;
129#ifdef _WIN32
130 shm_fd = NULL;
131#else
84 shm_fd = -1; 132 shm_fd = -1;
133#endif
85} 134}
86 135
87#ifdef __cplusplus 136#ifdef __cplusplus
diff --git a/src/generic/evas/common/timeout.c b/src/generic/evas/common/timeout.c
index 7737bad41f..844884c8e0 100644
--- a/src/generic/evas/common/timeout.c
+++ b/src/generic/evas/common/timeout.c
@@ -6,7 +6,7 @@
6unsigned int 6unsigned int
7_timeout(void *arg) 7_timeout(void *arg)
8{ 8{
9 int s (int)arg; 9 int s = (int)(uintptr_t)arg;
10 Sleep(s * 1000); 10 Sleep(s * 1000);
11 _Exit(-1); 11 _Exit(-1);
12 _endthreadex(0); 12 _endthreadex(0);
@@ -17,7 +17,7 @@ void
17timeout_init(int seconds) 17timeout_init(int seconds)
18{ 18{
19 unsigned int id; 19 unsigned int id;
20 _beginthreadex( NULL, 0, _timeout, (void *)seconds, 0, &id); 20 _beginthreadex( NULL, 0, _timeout, (void *)(uintptr_t)seconds, 0, &id);
21} 21}
22#else 22#else
23# include <unistd.h> 23# include <unistd.h>
diff --git a/src/generic/evas/gst/main.c b/src/generic/evas/gst/main.c
index 915622705d..e4f9f00285 100644
--- a/src/generic/evas/gst/main.c
+++ b/src/generic/evas/gst/main.c
@@ -2,7 +2,9 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <sys/mman.h> 5#ifdef HAVE_SHM_OPEN
6# include <sys/mman.h>
7#endif
6#include <fcntl.h> 8#include <fcntl.h>
7#include <unistd.h> 9#include <unistd.h>
8 10
diff --git a/src/generic/evas/pdf/main.cpp b/src/generic/evas/pdf/main.cpp
index 65a400889b..d8532fed54 100644
--- a/src/generic/evas/pdf/main.cpp
+++ b/src/generic/evas/pdf/main.cpp
@@ -2,7 +2,9 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <sys/mman.h> 5#ifdef HAVE_SHM_OPEN
6# include <sys/mman.h>
7#endif
6#include <fcntl.h> 8#include <fcntl.h>
7#include <stdio.h> 9#include <stdio.h>
8#include <unistd.h> 10#include <unistd.h>
@@ -315,8 +317,11 @@ main(int argc, char **argv)
315 317
316 if (!head_only) 318 if (!head_only)
317 { 319 {
318 if (shm_fd >= 0) printf("shmfile %s\n", shmfile); 320#ifdef HAVE_SHM_OPEN
321 if (shm_fd >= 0)
322 printf("shmfile %s\n", shmfile);
319 else 323 else
324#endif
320 { 325 {
321 // could also to "tmpfile %s\n" like shmfile but just 326 // could also to "tmpfile %s\n" like shmfile but just
322 // a mmaped tmp file on the system 327 // a mmaped tmp file on the system