#pragma once
using namespace System;

namespace lkfxdok {
	namespace c {

		public delegate long LKFAllocSemaphoreDelegate ();
		public delegate void LKFSemaphoreDelegate(long);

		ref class LKFSemaphoreHandler
		{
		internal:
			IntPtr marshaledAllocCallback;
			IntPtr marshaledEnterCallback;
			IntPtr marshaledLeaveCallback;
			IntPtr marshaledDeleteCallback;

			System::Threading::Semaphore^ _semaphore;

			LKFAllocSemaphoreDelegate^ allocDelegate;
			LKFSemaphoreDelegate^ enterDelegate;
			LKFSemaphoreDelegate^ leaveDelegate;
			LKFSemaphoreDelegate^ deleteDelegate;

			LKFSemaphoreHandler();
			void assign();
		private:
			long allocSemaphore();
			void enterSemaphore(long sem);
			void leaveSemaphore(long sem);
			void deleteSemaphore(long sem);
		};
	}
}

