"Fossies" - the Fresh Open Source Software Archive

Member "dmd2/src/druntime/import/core/sync/rwmutex.di" (20 Nov 2020, 1871 Bytes) of package /linux/misc/dmd.2.094.2.linux.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 // D import file generated from 'src/core/sync/rwmutex.d'
    2 module core.sync.rwmutex;
    3 public import core.sync.exception;
    4 private import core.sync.condition;
    5 private import core.sync.mutex;
    6 private import core.memory;
    7 version (Posix)
    8 {
    9 	private import core.sys.posix.pthread;
   10 }
   11 class ReadWriteMutex
   12 {
   13 	enum Policy 
   14 	{
   15 		PREFER_READERS,
   16 		PREFER_WRITERS,
   17 	}
   18 	this(Policy policy = Policy.PREFER_WRITERS)
   19 	{
   20 		m_commonMutex = new Mutex;
   21 		if (!m_commonMutex)
   22 			throw new SyncError("Unable to initialize mutex");
   23 		m_readerQueue = new Condition(m_commonMutex);
   24 		if (!m_readerQueue)
   25 			throw new SyncError("Unable to initialize mutex");
   26 		m_writerQueue = new Condition(m_commonMutex);
   27 		if (!m_writerQueue)
   28 			throw new SyncError("Unable to initialize mutex");
   29 		m_policy = policy;
   30 		m_reader = new Reader;
   31 		m_writer = new Writer;
   32 	}
   33 	@property Policy policy();
   34 	@property Reader reader();
   35 	@property Writer writer();
   36 	class Reader : Object.Monitor
   37 	{
   38 		this()
   39 		{
   40 			m_proxy.link = this;
   41 			this.__monitor = &m_proxy;
   42 		}
   43 		@trusted void lock();
   44 		@trusted void unlock();
   45 		bool tryLock();
   46 		bool tryLock(Duration timeout);
   47 		private 
   48 		{
   49 			@property bool shouldQueueReader();
   50 			struct MonitorProxy
   51 			{
   52 				Object.Monitor link;
   53 			}
   54 			MonitorProxy m_proxy;
   55 		}
   56 	}
   57 	class Writer : Object.Monitor
   58 	{
   59 		this()
   60 		{
   61 			m_proxy.link = this;
   62 			this.__monitor = &m_proxy;
   63 		}
   64 		@trusted void lock();
   65 		@trusted void unlock();
   66 		bool tryLock();
   67 		bool tryLock(Duration timeout);
   68 		private 
   69 		{
   70 			@property bool shouldQueueWriter();
   71 			struct MonitorProxy
   72 			{
   73 				Object.Monitor link;
   74 			}
   75 			MonitorProxy m_proxy;
   76 		}
   77 	}
   78 	private 
   79 	{
   80 		Policy m_policy;
   81 		Reader m_reader;
   82 		Writer m_writer;
   83 		Mutex m_commonMutex;
   84 		Condition m_readerQueue;
   85 		Condition m_writerQueue;
   86 		int m_numQueuedReaders;
   87 		int m_numActiveReaders;
   88 		int m_numQueuedWriters;
   89 		int m_numActiveWriters;
   90 	}
   91 }