Skip to content

Commit 85aeb8f

Browse files
committed
Make gst_proxy thread safe
1 parent 87c5eea commit 85aeb8f

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

configure.ac

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ GST_HAVE_GMP
2727

2828
_AM_DEPENDENCIES(OBJC)
2929
AC_CANONICAL_HOST
30-
LDFLAGS=-module
30+
LDFLAGS="-module -lpthread -no-undefined"
3131
case $host in
3232
*-*-darwin*) OBJCLIBS='-framework Cocoa' ;;
3333
*) AC_CHECK_TOOL(GNUSTEP_CONFIG, [gnustep-config],
@@ -43,8 +43,7 @@ case $host in
4343
*i386*) AC_DEFINE([__i386__]) ;;
4444
*x86_64*) AC_DEFINE([__x86_64__]) ;;
4545
esac
46-
47-
LDFLAGS+=" -no-undefined"
46+
4847
AC_SUBST(OBJC, [$CC])
4948
AC_SUBST(OBJCFLAGS, [$CFLAGS])
5049
AC_SUBST(GNUSTEP_CFLAGS)

gst-objc-ext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ typedef struct gst_objc_object
1515
}
1616
*gst_objc_object;
1717

18+
/* Initialize threading object */
19+
void gst_initThreading ();
20+
1821
/* Initialize ffi type */
1922
void gst_initFFIType ();
2023

gst-objc-ext.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <ffi.h>
22
#import "gst-objc-ext.h"
33

4-
//extern VMProxy* gst_proxy;
4+
pthread_mutex_t gstProxyMutex;
5+
56
ffi_type *ffi_type_cgfloat;
67
ffi_type ffi_type_nspoint;
78
ffi_type ffi_type_nsrect;
@@ -20,6 +21,11 @@
2021
}
2122
objc_ffi_closure;
2223

24+
void gst_initThreading ()
25+
{
26+
pthread_mutex_init (&gstProxyMutex, NULL);
27+
}
28+
2329
void gst_initFFIType ()
2430
{
2531
ffi_type_cgfloat = (sizeof(CGFloat) == sizeof(double)) ? &ffi_type_double : &ffi_type_float;
@@ -524,7 +530,9 @@ void gst_initFFIType ()
524530
gst_boxValue (args[i+2], argsOOP+i, [sig getArgumentTypeAtIndex: i+2]);
525531
}
526532
argsOOP[i] = NULL;
533+
GST_LOCK_PROXY;
527534
resultOOP = gst_proxy->vmsgSend (receiver, selector, argsOOP);
535+
GST_UNLOCK_PROXY;
528536
gst_unboxValue (resultOOP, result, [sig methodReturnType]);
529537

530538
}

gst-objc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#include <gstpub.h>
2+
#include <pthread.h>
23
#import "gst-objc-ext.h"
34
#import <Foundation/Foundation.h>
45
//#import "LKInterpreterRuntime.h"
56
#ifndef GNU_RUNTIME
67
#include <objc/objc-runtime.h>
78
#endif
89

10+
/* Smallltalk proxy */
911
extern VMProxy* gst_proxy;
12+
13+
/* Mutex to prevent gst_proxy race access */
14+
extern pthread_mutex_t gstProxyMutex;
15+
16+
#define GST_LOCK_PROXY (pthread_mutex_lock (&gstProxyMutex))
17+
#define GST_UNLOCK_PROXY (pthread_mutex_unlock (&gstProxyMutex))

gst-objc.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#endif // __APPLE__
1818

1919
gst_initFFIType ();
20+
gst_initThreading ();
2021
proxy->defineCFunc ("objc_sendMsg", gst_sendMessage);
21-
proxy->defineCFunc ("objc_sizeofCGFloat", gst_sizeofCGFloat);
22+
proxy->defineCFunc ("objc_sizeofCGFloat", gst_sizeofCGFloat);
2223
proxy->defineCFunc ("objc_sendReturnSize", gst_sendMessageReturnSize);
2324
proxy->defineCFunc ("objc_sendReturnType", gst_sendMessageReturnType);
2425
proxy->defineCFunc ("objc_setIvarOOP", gst_setIvarOOP);

objc-proxy.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ - (void) forwardInvocation: (NSInvocation*) anInvocation
4141
gst_boxValue (argumentBuffer, args+i, [sig getArgumentTypeAtIndex: i+2]);
4242
}
4343
args[i] = NULL;
44-
44+
45+
GST_LOCK_PROXY;
4546
OOP returnOOP = gst_proxy->vmsgSend (stObject, selector, args);
47+
GST_UNLOCK_PROXY;
48+
4649
gst_unboxValue (returnOOP, (void*)returnBuffer, [sig methodReturnType]);
4750
[anInvocation setReturnValue: (void*)returnBuffer];
4851
}

0 commit comments

Comments
 (0)