[Red5commits] [1581] fixed potential race conditions when accessed from multiple threads

jbauch luke at codegent.com
Wed Jan 24 10:59:21 EST 2007


fixed potential race conditions when accessed from multiple threads


Timestamp: 11/29/06 17:23:08 EST (2 months ago) 
Change: 1581 
Author: jbauch

Files (see diff or trac for details): 
java/server/trunk/src/org/red5/server/so/SharedObjectService.java


Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1581

Index: /java/server/trunk/src/org/red5/server/so/SharedObjectService.java
===================================================================
--- /java/server/trunk/src/org/red5/server/so/SharedObjectService.java (revision 1519)
+++ /java/server/trunk/src/org/red5/server/so/SharedObjectService.java (revision 1581)
@@ -89,12 +89,14 @@
 	public boolean createSharedObject(IScope scope, String name,
 			boolean persistent) {
-		if (hasSharedObject(scope, name)) {
-			// The shared object already exists.
-			return true;
+		synchronized (scope) {
+			if (hasSharedObject(scope, name)) {
+				// The shared object already exists.
+				return true;
+			}
+	
+			final IBasicScope soScope = new SharedObjectScope(scope, name,
+					persistent, getStore(scope, persistent));
+			return scope.addChildScope(soScope);
 		}
-
-		final IBasicScope soScope = new SharedObjectScope(scope, name,
-				persistent, getStore(scope, persistent));
-		return scope.addChildScope(soScope);
 	}
 
@@ -105,8 +107,10 @@
 	public ISharedObject getSharedObject(IScope scope, String name,
 			boolean persistent) {
-		if (!hasSharedObject(scope, name)) {
-			createSharedObject(scope, name, persistent);
+		synchronized (scope) {
+			if (!hasSharedObject(scope, name)) {
+				createSharedObject(scope, name, persistent);
+			}
+			return getSharedObject(scope, name);
 		}
-		return getSharedObject(scope, name);
 	}
 
@@ -126,22 +130,24 @@
 	public boolean clearSharedObjects(IScope scope, String name) {
 		boolean result = false;
-		if (hasSharedObject(scope, name)) {
-			// '/' clears all local and persistent shared objects associated
-			// with the instance
-			// if (name.equals('/')) {
-			// /foo/bar clears the shared object /foo/bar; if bar is a directory
-			// name, no shared objects are deleted.
-			// if (name.equals('/')) {
-			// /foo/bar/* clears all shared objects stored under the instance
-			// directory /foo/bar. The bar directory is also deleted if no
-			// persistent shared objects are in use within this namespace.
-			// if (name.equals('/')) {
-			// /foo/bar/XX?? clears all shared objects that begin with XX,
-			// followed by any two characters. If a directory name matches this
-			// specification, all the shared objects within this directory are
-			// cleared.
-			// if (name.equals('/')) {
-			// }
-			result = ((ISharedObject) scope.getBasicScope(TYPE, name)).clear();
+		synchronized (scope) {
+			if (hasSharedObject(scope, name)) {
+				// '/' clears all local and persistent shared objects associated
+				// with the instance
+				// if (name.equals('/')) {
+				// /foo/bar clears the shared object /foo/bar; if bar is a directory
+				// name, no shared objects are deleted.
+				// if (name.equals('/')) {
+				// /foo/bar/* clears all shared objects stored under the instance
+				// directory /foo/bar. The bar directory is also deleted if no
+				// persistent shared objects are in use within this namespace.
+				// if (name.equals('/')) {
+				// /foo/bar/XX?? clears all shared objects that begin with XX,
+				// followed by any two characters. If a directory name matches this
+				// specification, all the shared objects within this directory are
+				// cleared.
+				// if (name.equals('/')) {
+				// }
+				result = ((ISharedObject) scope.getBasicScope(TYPE, name)).clear();
+			}
 		}
 		return result;


Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.



More information about the Red5commits mailing list