/****************************************************************************
				rc_accessd content access time extract control header 
				-----------------------------------------

	begin      : 2021/04/14
	copyright  : (C) 2005 Solbox Inc.
	author     : huibong
	email      : huibong@solbox.com
	version    : 3.5

	CopyRight(C) 2005 Solbox Inc. All Rights reserved.
	Redistribution and use in source and binary forms, with or with out
	modification, are not permitted in outside of Solbox Inc.
*****************************************************************************/


#ifndef __THREAD_EXTRACT_CONTROL_H__
#define __THREAD_EXTRACT_CONTROL_H__

#include <pthread.h>

#include "DataAccess.h"
#include "DataQueue.hpp"



// CThreadExtractControl class
// - queue 에 저장된 각 content 에 대해 access time 정보 추출을 처리할 개별 thread 생성 처리 담당.
class CThreadExtractControl
{
	public:

		CThreadExtractControl( CDataQueue<CDataAccess> * const pQueueTarget
			, CDataQueue<CDataAccess> * const pQueueComplete, unsigned int nMaxThreadCount );

		~CThreadExtractControl();

		// Thread 생성 및 작업 시작
		bool Start( void );


		// current thread count info

		void PlusThreadCountAccess( void );
		void MinusThreadCountAccess( void );
		int GetThreadCountAccess( void );

		int GetCreateableThreadCount( void );




	private:

		// thread handle
		pthread_t m_threadHandle;

		// Thread loop 마다 sleep time 저장
		unsigned int m_uSleep;

		// 작업 대상 content 목록을 저장하기 위한 queue 로서... 생성자를 통해 전달받은 queue point 를 의미
		CDataQueue<CDataAccess> * m_pQueueTarget;

		// 작업 완료된 content 목록을 저장하기 위한 queue 로서... 생성자를 통해 전달받은 queue point 를 의미
		CDataQueue<CDataAccess> * m_pQueueComplete;


		// 최대 생성 가능 theread count
		unsigned int m_nMaxThreadCount;

		// 작업 thread 관리
		int m_nCurrentThreadCount;
		pthread_mutex_t m_mutexThreadCount;


	private:

		// Thread function
		static void * threadFunc( void * arg );

		// 실제 작업을 수행하기 위한 함수
		void Execute( void );


};

#endif /* __THREAD_EXTRACT_CONTROL_H__ */

