Skip to content

Commit

Permalink
Synchronizers are now managed only (except for Semaphore[Slim], due t…
Browse files Browse the repository at this point in the history
…o circular dependencies).
  • Loading branch information
Duarte Nunes committed Jun 7, 2011
1 parent 98db271 commit 21d0dbe
Show file tree
Hide file tree
Showing 25 changed files with 3,423 additions and 851 deletions.
112 changes: 112 additions & 0 deletions mcs/class/System/System.Threading/Semaphore.cs.new
@@ -0,0 +1,112 @@
//
// System.Threading.Semaphore.cs
//
// Copyright 2011 Duarte Nunes
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Duarte Nunes (duarte.m.nunes@gmail.com)
//

#if NET_2_0

using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.AccessControl;

namespace System.Threading
{
[ComVisible (false)]
public sealed class Semaphore : WaitHandle
{
internal Semaphore (StWaitable waitable)
{
Waitable = waitable;
}

public Semaphore (int initialCount, int maximumCount)
{
if (initialCount < 0)
throw new ArgumentOutOfRangeException("initialCount", "< 0");
if (maximumCount < 1)
throw new ArgumentOutOfRangeException("maximumCount", "< 1");
if (initialCount > maximumCount)
throw new ArgumentException("initialCount > maximumCount");

Waitable = new StSemaphore (initialCount, maximumCount);
}

public Semaphore (int initialCount, int maximumCount, string name)
{
throw new NotImplementedException ();
}

public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew)
: this (initialCount, maximumCount, name, out createdNew, null) { }

[MonoTODO ("Does not support access control, semaphoreSecurity is ignored")]
public Semaphore (int initialCount, int maximumCount, string name, out bool createdNew,
SemaphoreSecurity semaphoreSecurity)
{
throw new NotImplementedException ();
}

public static Semaphore OpenExisting (string name)
{
return OpenExisting(name, SemaphoreRights.Synchronize | SemaphoreRights.Modify);
}

public static Semaphore OpenExisting (string name, SemaphoreRights rights)
{
throw new NotImplementedException ();
}

[MonoTODO]
public SemaphoreSecurity GetAccessControl ()
{
throw new NotImplementedException ();
}

[PrePrepareMethod]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public int Release ()
{
return (Release (1));
}

[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public int Release (int releaseCount)
{
var sem = Waitable as StSemaphore;
return sem != null ? sem.Release(releaseCount) : 0;
}

internal override bool _WaitOne(int timeout)
{
var sem = Waitable as StSemaphore;
return sem != null ? sem.Wait (1, new StCancelArgs (timeout)) : false;
}

[MonoTODO]
public void SetAccessControl (SemaphoreSecurity semaphoreSecurity)
{
if (semaphoreSecurity == null) {
throw new ArgumentNullException ("semaphoreSecurity");
}

throw new NotImplementedException ();
}
}
}

#endif
53 changes: 23 additions & 30 deletions mcs/class/corlib/Microsoft.Win32.SafeHandles/SafeWaitHandle.cs
@@ -1,51 +1,44 @@
//
// Microsoft.Win32.SafeHandles.SafeWaitHandle
// System.Threading.SafeWaitHandle.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
// Miguel de Icaza <miguel@novell.com>
//
// Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// Copyright 2011 Duarte Nunes
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// http://www.apache.org/licenses/LICENSE-2.0
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Duarte Nunes (duarte.m.nunes@gmail.com)
//

using System;
using System.IO;
using System.Threading;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;

namespace Microsoft.Win32.SafeHandles {

public sealed class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid {

[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeWaitHandle (IntPtr existingHandle, bool ownsHandle) : base (ownsHandle)
public SafeWaitHandle (IntPtr existingHandle, bool ownsHandle)
: base (ownsHandle)
{
SetHandle (existingHandle);
}

protected override bool ReleaseHandle ()
{
NativeEventCalls.CloseEvent_internal (handle);
return true;
if (handle != IntPtr.Zero) {
GCHandle.FromIntPtr (handle).Free ();
}
return true;
}

}
}
}
157 changes: 0 additions & 157 deletions mcs/class/corlib/System.Threading/CancelArgs.cs

This file was deleted.

0 comments on commit 21d0dbe

Please sign in to comment.