Running multiple thread instances of the same function. (See MultiThread Program for an example on how to use it)

Dependents:   MutliThread Server_Multi_Client HelloWorld C027_SupportTest ... more

Threads.cpp

Committer:
lemniskata
Date:
2013-06-29
Revision:
2:46b56c9086f2
Parent:
1:ecdd97ea3d3b
Child:
3:d370bed31f45

File content as of revision 2:46b56c9086f2:

/*
** File name:            Thread.cpp
** Descriptions:        Creates multiple thread instances of the same function
**
**------------------------------------------------------------------------------------------------------
** Created by:            Ivan Shindev
** Created date:        06/29/2013
** Version:                1.0
** Descriptions:        The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:            
** Modified date:    
** Version:
** Descriptions:        
********************************************************************************************************/
#include "Threads.h"

/*Initialize memory and set the pointer to the thread*/
int initThread(ThreadList **addresOfTL,os_pthread pthread,ThreadList** addresOfThread)
{
    if(*addresOfTL==NULL)
    {
        *addresOfTL=(ThreadList*)malloc(sizeof(ThreadList));
        if(*addresOfTL==NULL)
            return 0;
        
        (*addresOfTL)->thread=NULL;
        (*addresOfTL)->thread=(osThreadDef_t *)malloc(sizeof(osThreadDef_t ));
    
        if((*addresOfTL)->thread==NULL)
            return 0;
        
        (*addresOfTL)->thread->pthread=pthread;
        (*addresOfTL)->thread->tpriority=osPriorityNormal;
        (*addresOfTL)->thread->stacksize=DEFAULT_STACK_SIZE;
    
        (*addresOfTL)->thread->stack_pointer=NULL;
        (*addresOfTL)->thread->stack_pointer=(unsigned char *)malloc(DEFAULT_STACK_SIZE);
    
        if((*addresOfTL)->thread->stack_pointer==NULL)
            return 0;
        (*addresOfTL)->nextThread=NULL;
        (*addresOfThread)=(*addresOfTL);
        return 1;
    }
    else
        return initThread(&((*addresOfTL)->nextThread),pthread,addresOfThread);
}