[FFmpeg-devel] [PATCH] Reimplementation of OS/2 threads model

Måns Rullgård mans
Mon Apr 26 16:07:49 CEST 2010


KO Myung-Hun <komh at chollian.net> writes:

> M?ns Rullg?rd wrote:
>> KO Myung-Hun <komh at chollian.net> writes:
>> 
>>> Hi/2.
>>>
>>> This patch reimplements OS/2 threads model based on Win32 threads model.
>>>
>>> -- 
>>> KO Myung-Hun
>>>
>>> Using Mozilla SeaMonkey 2.0.3
>>> Under OS/2 Warp 4 for Korean with FixPak #15
>>> On AMD ThunderBird 1GHz with 512 MB RAM
>>>
>>> Korean OS/2 User Community : http://www.ecomstation.co.kr
>>>
>>>
>>> Index: libavcodec/os2thread.c
>>> ===================================================================
>>> --- libavcodec/os2thread.c	(revision 22960)
>>> +++ libavcodec/os2thread.c	(working copy)
>>> @@ -1,5 +1,5 @@
>>>  /*
>>> - * Copyright (c) 2004 Michael Niedermayer <michaelni at gmx.at>
>>> + * Copyright (c) 2010 KO Myung-Hun <komh at chollian.net>
>>>   *
>>>   * This file is part of FFmpeg.
>>>   *
>>> @@ -17,51 +17,120 @@
>>>   * License along with FFmpeg; if not, write to the Free Software
>>>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>>>   */
>>> -//#define DEBUG
>>>
>>> -// Ported by Vlad Stelmahovsky
>>> +#define INCL_DOS
>>> +#include <os2.h>
>>>
>>> +#undef __STRICT_ANSI__  /* for _beginthread() */
>>> +#include <stdlib.h>
>>> +
>>>  #include "avcodec.h"
>>>
>>> -#define INCL_DOS
>>> -#define INCL_DOSERRORS
>>> -#define INCL_DOSDEVIOCTL
>>> -#include <os2.h>
>>> +typedef struct Semaphore{
>>> +    HEV   hev;
>>> +    HMTX  hmtxWait;
>>> +    HMTX  hmtxCount;
>>> +    LONG  lCount;
>>> +    LONG  lMax;
>>> +}Semaphore;
>> 
>> Can we please not use Hungarian names?
>
> Ok.
>
>> Also, please add a space
>> before { and after }.  This applies to the entire patch.
>> 
>
> w32thread.c has a that style. So I just followed it.
>
> Anyway, maybe do you also want K&R style like Diego ? ^^

Of course.

>>>  typedef struct ThreadContext{
>>>      AVCodecContext *avctx;
>>> -    int thread;
>>> -    HEV work_sem;
>>> -    HEV done_sem;
>>> +    TID thread;
>>> +    Semaphore *work_sem;
>>> +    Semaphore *job_sem;
>>> +    Semaphore *done_sem;
>>>      int (*func)(AVCodecContext *c, void *arg);
>>> +    int (*func2)(AVCodecContext *c, void *arg, int, int);
>>>      void *arg;
>>> -    int ret;
>>> +    int argsize;
>>> +    int *jobnr;
>>> +    int *ret;
>>> +    int threadnr;
>>>  }ThreadContext;
>>>
>>> +#define INFINITE  ((ULONG)SEM_INDEFINITE_WAIT)
>> 
>> What's with the cast?
>
> Removed.

If it was that simple, what's the purpose of the extra define?

>>> +static Semaphore *CreateSemaphore(void *v1, LONG lCount, LONG lMax, void *v2){
>> 
>> Is this emulating something?  What's wrong with semaphore calls in the
>> old code?
>> 
>
> The (event) semaphore of the old code wakes up all the waiting threads.
> And it resets the status to non-signaled regardless of its post count.
>
> So I decided to emulate the semaphore model of Win32. It can wake up
> waiting threads one by one and decrease its post count.

Would it be possible to use the native semaphores, or is this
emulation strictly required?  If we end up emulating win32threads, we
might as well use the pthreads emulation instead and save ourselves
some trouble.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list