⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worker.cpp

📁 Visual DSP++ VDK的应用举例
💻 CPP
字号:
/* =============================================================================
 *
 *  Description: This is a C++ implementation for Thread Worker
 *
 * -----------------------------------------------------------------------------
 *  Comments: 
 *
 * ===========================================================================*/

#include "Worker.h"
#include <new>

/******************************************************************************
 *  Worker Constructor
 */
 
Worker::Worker(VDK::Thread::ThreadCreationBlock &tcb)
    : VDK::Thread(tcb)
{
	/* This routine does NOT run in new thread's context.  Any non-static thread
	 *   initialization should be performed at the beginning of "Run()."
	 */

	/* TODO - Put code to be executed when this thread has just been created HERE */
    m_ExcessivelyLargePtr = 0;
    m_ExcessivelyLargePtr = (char*) malloc(2048*sizeof(char));
}

/******************************************************************************
 *  Worker Destructor
 */
 
Worker::~Worker()
{
	/* This routine does NOT run in the thread's context.  Any VDK API calls
  	 *   should be performed at the end of "Run()."
	 */

	/* TODO - Put code to be executed just before this thread is destroyed HERE */
   	if (m_ExcessivelyLargePtr != 0)
		delete [] m_ExcessivelyLargePtr;
}

/******************************************************************************
 *  Worker Externally Accessable, Pre-Constructor Create Function
 */
 
VDK::Thread*
Worker::Create(VDK::Thread::ThreadCreationBlock &tcb)
{
	/* This routine does NOT run in new thread's context.  Any non-static thread
	 *   initialization should be performed at the beginning of "Run()."
	 */

	// replaced the following code
    // return new (tcb) Worker(tcb);

	// Make the thread
	Worker	*thread_ptr = new (tcb) Worker(tcb);

	// Check that the thread and all associated data types were created okay
	if ((thread_ptr != 0) && (thread_ptr->m_ExcessivelyLargePtr == 0))
	{
		// If an error occured malloc'ing the space for m_ExcessivelyLargePtr,
		// delete the pointer, and return 0
		delete thread_ptr;
		thread_ptr = 0;
	}
	return thread_ptr;
}

/******************************************************************************
 *  Worker Run Function (Worker's main{})
 */
 
void
Worker::Run()
{
	/* TODO - Put the thread's "main" Initialzation HERE */

	while (1)
	{
		/* TODO - Put the thread's "main" body HERE */

		/* Use a "break" instruction to exit the "while (1)" loop */
	}

	/* TODO - Put the thread's exit from "main" HERE */
}

/******************************************************************************
 *  Worker Error Handler
 */
 
int
Worker::ErrorHandler()
{
	/* TODO - Put this thread's error handling code HERE */

	/* The default ErrorHandler (called below) kills the thread */
	return (VDK::Thread::ErrorHandler());
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -