[vlc-devel] [PATCH 3/4] stream_filter: implement prefetch module for OS/2
KO Myung-Hun
komh78 at gmail.com
Sun Nov 22 04:24:41 CET 2015
From: KO Myung-Hun <komh78 at gmail.com>
---
modules/stream_filter/prefetch.c | 125 +++++++++++++++++++++++++++++++++++++--
1 file changed, 121 insertions(+), 4 deletions(-)
diff --git a/modules/stream_filter/prefetch.c b/modules/stream_filter/prefetch.c
index d7c34c7..4ac28f8 100644
--- a/modules/stream_filter/prefetch.c
+++ b/modules/stream_filter/prefetch.c
@@ -33,7 +33,7 @@
#ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS MAP_ANON
#endif
-#else
+#elif !defined(__OS2__)
#include <errno.h>
#define MAP_FAILED ((void *)-1)
#define mmap(a,l,p,f,d,o) \
@@ -476,7 +476,7 @@ static int Open(vlc_object_t *obj)
if (sys->buffer_size < sys->read_size)
sys->buffer_size = sys->read_size;
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__OS2__)
/* Round up to a multiple of the page size */
long page_size = sysconf(_SC_PAGESIZE);
@@ -502,6 +502,114 @@ static int Open(vlc_object_t *obj)
goto error;
}
close(fd);
+#elif defined(__OS2__)
+ /* On OS/2 Warp, page size is 4K, but the smallest chunk size is 64K */
+ int page_size = 64 * 1024;
+
+ sys->buffer_size += page_size - 1;
+ sys->buffer_size &= ~(page_size - 1);
+ sys->buffer = NULL;
+
+ char *buffer;
+
+ if (DosAllocMem(&buffer, 2 * sys->buffer_size, fALLOC))
+ goto error;
+
+ struct buffer_list
+ {
+ char *buffer;
+ struct buffer_list *next;
+ } *buffer_list_start = NULL;
+
+ for (;;)
+ {
+ char *buf;
+
+ if (DosAllocMem(&buf, sys->buffer_size, fPERM | OBJ_TILE))
+ break;
+
+ struct buffer_list *new_buffer = calloc(1, sizeof(*new_buffer));
+
+ if (!new_buffer)
+ {
+ DosFreeMem(buf);
+
+ break;
+ }
+
+ new_buffer->buffer = buf;
+ new_buffer->next = buffer_list_start;
+
+ buffer_list_start = new_buffer;
+
+ if (buf > buffer)
+ {
+ /* Disable thread switching */
+ DosEnterCritSec();
+
+ char *addr = buffer;
+
+ DosFreeMem(buffer);
+ buffer = NULL;
+
+ if (DosAllocMem(&buf, sys->buffer_size, fALLOC))
+ goto exitcritsec;
+
+ /* Was hole ? */
+ if (buf < addr)
+ {
+ DosFreeMem(buf);
+ buf = NULL;
+
+ char *tmp;
+
+ /* Try to fill the hole out */
+ if (DosAllocMem(&tmp, addr - buf, fALLOC))
+ goto exitcritsec;
+
+ DosAllocMem(&buf, sys->buffer_size, fALLOC);
+
+ DosFreeMem(tmp);
+ }
+
+ if (buf != addr)
+ {
+ DosFreeMem(buf);
+ goto exitcritsec;
+ }
+
+ char *alias = NULL;
+
+ if (!DosAliasMem(buf, sys->buffer_size, &alias, 0)
+ && alias == buf + sys->buffer_size)
+ sys->buffer = addr;
+ else
+ {
+ DosFreeMem(buf);
+ DosFreeMem(alias);
+ }
+
+exitcritsec:
+ /* Enable thread switching */
+ DosExitCritSec();
+
+ break;
+ }
+ }
+
+ DosFreeMem(buffer);
+
+ for (struct buffer_list *l = buffer_list_start, *next; l; l = next)
+ {
+ next = l->next;
+
+ DosFreeMem(l->buffer);
+ free(l);
+
+ }
+
+ if (sys->buffer == NULL)
+ goto error;
#else
SYSTEM_INFO info;
GetSystemInfo(&info);
@@ -574,9 +682,15 @@ static int Open(vlc_object_t *obj)
return VLC_SUCCESS;
error:
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__OS2__)
if (sys->buffer != MAP_FAILED)
munmap(sys->buffer, 2 * sys->buffer_size);
+#elif defined(__OS2__)
+ if (sys->buffer != NULL)
+ {
+ DosFreeMem(sys->buffer + sys->buffer_size);
+ DosFreeMem(sys->buffer);
+ }
#else
if (sys->buffer != NULL)
{
@@ -605,8 +719,11 @@ static void Close (vlc_object_t *obj)
vlc_cond_destroy(&sys->wait_data);
vlc_mutex_destroy(&sys->lock);
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__OS2__)
munmap(sys->buffer, 2 * sys->buffer_size);
+#elif defined(__OS2__)
+ DosFreeMem(sys->buffer + sys->buffer_size);
+ DosFreeMem(sys->buffer);
#else
UnmapViewOfFile(sys->buffer + sys->buffer_size);
UnmapViewOfFile(sys->buffer);
--
2.6.0
More information about the vlc-devel
mailing list