Commit 0010afc2 authored by KO Myung-Hun's avatar KO Myung-Hun Committed by Jean-Baptiste Kempf

stream_filter: implement prefetch module for OS/2

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent d2976281
......@@ -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,110 @@ 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 +678,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 +715,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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment