Ivan Shindev / Threads

Dependents:   MutliThread Server_Multi_Client HelloWorld C027_SupportTest ... more

Revision:
0:266b0dc4f8d0
Child:
1:ecdd97ea3d3b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Threads.cpp	Sat Jun 29 21:13:52 2013 +0000
@@ -0,0 +1,72 @@
+/*
+** 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"
+
+int initThread(osThreadDef_t ***addresOfThreads,os_pthread pthread)
+{
+    *addresOfThreads=(osThreadDef_t **)malloc(sizeof(osThreadDef_t *));
+    if(*addresOfThreads==NULL)
+        return 0;
+        
+    (*addresOfThreads)[0]=NULL;
+    (*addresOfThreads)[0]=(osThreadDef_t *)malloc(sizeof(osThreadDef_t ));
+    
+    if((*addresOfThreads)[0]==NULL)
+        return 0;
+        
+    (*addresOfThreads)[0]->pthread=pthread;
+    (*addresOfThreads)[0]->tpriority=osPriorityNormal;
+    (*addresOfThreads)[0]->stacksize=DEFAULT_STACK_SIZE;
+    
+    (*addresOfThreads)[0]->stack_pointer=NULL;
+    (*addresOfThreads)[0]->stack_pointer=(unsigned char *)malloc(DEFAULT_STACK_SIZE);
+    
+    if((*addresOfThreads)[0]->stack_pointer==NULL)
+        return 0;
+    
+    return 1;
+
+}
+
+int reAlloc(osThreadDef_t ***addresOfThreads,os_pthread pthread,int numberOfThreads)
+{
+    osThreadDef_t **temp=NULL;
+    temp=(osThreadDef_t **)realloc((*addresOfThreads),numberOfThreads*sizeof(osThreadDef_t *));
+    if(temp==NULL)
+    {
+        return 0;
+    }
+    (*addresOfThreads)=temp;
+    (*addresOfThreads)[numberOfThreads-1]=NULL;
+    (*addresOfThreads)[numberOfThreads-1]=(osThreadDef_t *)malloc(sizeof(osThreadDef_t ));
+    
+    if((*addresOfThreads)[numberOfThreads-1]==NULL)
+        return 0;
+        
+    (*addresOfThreads)[numberOfThreads-1]->pthread=pthread;
+    (*addresOfThreads)[numberOfThreads-1]->tpriority=osPriorityNormal;
+    (*addresOfThreads)[numberOfThreads-1]->stacksize=DEFAULT_STACK_SIZE;
+    
+    (*addresOfThreads)[numberOfThreads-1]->stack_pointer=NULL;
+    (*addresOfThreads)[numberOfThreads-1]->stack_pointer=(unsigned char *)malloc(DEFAULT_STACK_SIZE);
+    
+    if((*addresOfThreads)[numberOfThreads-1]->stack_pointer==NULL)
+        return 0;
+    
+    return 1;
+
+}