Esempio n. 1
0
		/* thread-safe */
		public static bool AddNativeMapping (IntPtr native, INativeEventObjectWrapper wrapper)
		{
			EventObjectToggleRef tref;
			
			if (native == IntPtr.Zero)
				return false;

			lock (objects) {
				if (objects.ContainsKey (native)) {
	#if DEBUG
					throw new ExecutionEngineException ("multiple mappings registered for the same unmanaged peer");
	#endif
					Console.WriteLine ("multiple mappings registered for the same unmanaged peer 0x{0:x}, type = {1}", native, wrapper.GetType());
					Console.WriteLine (Environment.StackTrace);
					return false;
				}
				
				tref = new EventObjectToggleRef (wrapper);
				objects[native] = tref;
			}
			tref.Initialize ();
			return true;
		}
		/* thread-safe */
		public static bool AddNativeMapping (IntPtr native, INativeEventObjectWrapper wrapper)
		{
			EventObjectToggleRef tref;
			
			if (native == IntPtr.Zero)
				return false;

			lock (objects) {
				if (objects.ContainsKey (native)) {
					Console.WriteLine ("multiple mappings registered for the same unmanaged peer 0x{0:x}, type = {1}", native, wrapper.GetType());
#if DEBUG
					throw new ExecutionEngineException (string.Format ("multiple mappings registered for the same unmanaged peer."));
#else
					return false;
#endif
				}
				
				tref = new EventObjectToggleRef (wrapper);

#if DEBUG_REF
				Console.WriteLine ("adding native mapping from {0:x} to {1}/{2}", (int)native, wrapper.GetHashCode(), wrapper.GetType());
#endif

				objects[native] = tref;
			}
			tref.Initialize ();
			return true;
		}