Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MutliThread Server_Multi_Client HelloWorld C027_SupportTest ... more
Diff: Threads.cpp
- Revision:
- 0:266b0dc4f8d0
- Child:
- 1:ecdd97ea3d3b
diff -r 000000000000 -r 266b0dc4f8d0 Threads.cpp
--- /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;
+
+}