/*
 * EmulatedThreadEvents.cpp
 *
 *  Created on: Sep 17, 2012
 *      Author: maiello
 */

#include <windows.h>





HANDLE CreateThread(
  LPSECURITY_ATTRIBUTES lpThreadAttributes,     // SD
  SIZE_T dwStackSize,                           // initial stack size
  LPTHREAD_START_ROUTINE lpStartAddress,        // thread function
  LPVOID lpParameter,                           // thread argument
  DWORD dwCreationFlags,                        // creation option
  LPDWORD lpThreadId                            // thread identifier
)
{
	pthread_t thread;

	pthread_attr_t threadAttr;

	struct sched_param param;  // scheduling priority

	   // initialize the thread attribute
	pthread_attr_init(&threadAttr);

	// Set the stack size of the thread
	pthread_attr_setstacksize(&threadAttr, 120*1024);

	// Set thread to detached state. No need for pthread_join
	pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED);

	// Create the threads
	pthread_create(&thread, &threadAttr, (void * (*)(void *)) lpStartAddress, NULL);

	// Destroy the thread attributes
	pthread_attr_destroy(&threadAttr);


	return thread;

}


DWORD ResumeThread(
  HANDLE hThread
)
{

	return 1;

}


HANDLE CreateEvent(
  LPSECURITY_ATTRIBUTES lpEventAttributes,
  BOOL bManualReset,
  BOOL bInitialState,
  LPCTSTR lpName
)
{
	sem_t sem;

	// Initialize event semaphore
	sem_init(&sem,   // handle to the event semaphore
	         0,     // not shared
	         0);    // initially set to non signaled state


	return (HANDLE) sem;
}


