[vlc-devel] [PATCH 2/2] stream_filter: implement prefetch module for OS/2
KO Myung-Hun
komh78 at gmail.com
Sat Oct 10 07:08:52 CEST 2015
Ping ?
KO Myung-Hun wrote:
> 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 16f102c..608c379 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) \
> @@ -473,7 +473,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);
>
> @@ -499,6 +499,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);
> @@ -571,9 +679,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)
> {
> @@ -602,8 +716,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);
--
KO Myung-Hun
Using Mozilla SeaMonkey 2.7.2
Under OS/2 Warp 4 for Korean with FixPak #15
In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM
Korean OS/2 User Community : http://www.ecomstation.co.kr
More information about the vlc-devel
mailing list