All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ravid Baruch Naali <ravidbn@domain.hid>
To: xenomai@xenomai.org
Subject: [Xenomai-core] [PATCH] VxWorks semaphore usage demo
Date: Mon, 03 Sep 2007 18:13:08 +0300	[thread overview]
Message-ID: <46DC2484.6040004@domain.hid> (raw)

[-- Attachment #1: Type: text/plain, Size: 257 bytes --]

Hello again,


I'm not sure what is the preferred way to commit my changes, so before I 
commit i'm Attaching my patch in order to get you remarks and further 
instructions


Thanks

-- 
Ravid Baruch Naali
ravidbn@domain.hid
+972 4 6732729
+972 52 5830021


[-- Attachment #2: vxworks_demo.2960.patch --]
[-- Type: text/x-patch, Size: 3733 bytes --]

Index: ksrc/skins/vxworks/demos/sem.c
===================================================================
--- ksrc/skins/vxworks/demos/sem.c	(revision 0)
+++ ksrc/skins/vxworks/demos/sem.c	(revision 0)
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <vxworks/vxworks.h>
+#include <sys/mman.h>
+
+
+#define TASK_NUM 10
+#define STACK_SIZE 1024
+#define xnarch_printf printf
+
+SEM_ID semID, syncSEM;
+
+void taskMain(long arg1, long arg2, long arg3, long arg4, long arg5, long arg6, long arg7, long arg8, long arg9, long arg10)
+{
+    int localerrno;
+    //Waiting to start synchronized with all other spawned tasks
+    semTake(syncSEM, WAIT_FOREVER);
+    //Taking the counting semaphore to indicate task started running, 
+    //stall main from exiting 
+    STATUS result = semTake(semID, WAIT_FOREVER);
+    //Chaking for failures
+    if(result == ERROR){
+	localerrno = errnoGet();
+	//checking failure reason
+	switch(localerrno){
+	    case S_objLib_OBJ_ID_ERROR:
+		xnprintf( "Semaphore ID is invalid\n");
+		break;
+	    case S_objLib_OBJ_UNAVAILABLE:
+		xnprintf( "Semaphore unavailable (NO_WAIT)\n");
+		break;
+	    case S_objLib_OBJ_TIMEOUT:
+		xnprintf( "Timeout occured before semaphore was released\n");
+		break;
+	    case S_semLib_INVALID_OPTION:
+		xnprintf( "Semaphore type is invalid\n");
+		break;
+	    case EINTR:
+		xnprintf( "Received interup\n");
+		break;
+	    default:
+		break;
+	}
+	return;
+    }
+    
+    int i = 10;
+    //Getting this task's ID
+    int ownID = taskIdSelf();
+    //Getting this task's pririty
+    int priority;
+    result = taskPriorityGet(ownID, &priority);
+    
+    xnprintf( "My priority is %d\n", priority);
+    while(i){
+	    printf("My name is %s my tid=%d\n", taskName(ownID), ownID);
+	    sleep(1);
+	    i--;
+    }
+    //Signaling main that this task as finished
+    semGive(semID);
+    //Not realy required but releasing semaphore
+    semGive(syncSEM);
+}
+
+
+int main(int argc, char **argv)
+{
+	
+    mlockall(MCL_CURRENT|MCL_FUTURE);
+    int tidStat;
+    int tids[TASK_NUM];
+    //Creating counting semaphore on which main waits until all tasks are done
+    semID = semCCreate(SEM_Q_PRIORITY, TASK_NUM);
+    if(!semID){
+	xnprintf( "Failed to create semaphore\n");
+	exit(1);
+    }
+    //Creating a binary semaphore to sync all tasks 
+    syncSEM = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY);
+    if(!syncSEM){
+	xnprintf( "Failed to create binary semaphore\n");
+	exit(1);
+    }
+    //creating all the tasks 
+    int i;
+    for(i = 0; i < TASK_NUM; i++){
+	tids[i] = taskSpawn(NULL, 25-i, 0, STACK_SIZE , taskMain,0,0,0,0,0,0,0,0,0,0);
+	xnprintf( "Spawned task: %d\n", tids[i]);
+    }
+    //Giving all tasks a signal to start
+    semFlush(syncSEM);
+    //Waiting for all task to complete their main routine
+    semTake(semID, WAIT_FOREVER);
+    for(i = 0; i < TASK_NUM; i++)
+	taskDelete(tids[i]);
+    semDelete(semID);
+    semDelete(syncSEM);
+}
Index: ksrc/skins/vxworks/demos/Makefile
===================================================================
--- ksrc/skins/vxworks/demos/Makefile	(revision 2960)
+++ ksrc/skins/vxworks/demos/Makefile	(working copy)
@@ -7,7 +7,7 @@
 
 STD_CFLAGS  := $(shell $(XENO_CONFIG) --xeno-cflags)
 STD_LDFLAGS := $(shell $(XENO_CONFIG) --xeno-ldflags) -lvxworks
-STD_TARGETS := satch
+STD_TARGETS := satch sem
 
 GCIC := $(prefix)/bin/gcic
 SIM_CFLAGS  := -g
@@ -27,6 +27,9 @@
 satch: satch.c
 	$(CC) -o $@ $< $(STD_CFLAGS) $(STD_LDFLAGS)
 
+sem: sem.c
+	$(CC) -o $@ $< $(STD_CFLAGS) $(STD_LDFLAGS)
+
 satch_sim: satch_sim.o
 	$(GCIC) -o $@ $< $(SIM_LDFLAGS)
 

             reply	other threads:[~2007-09-03 15:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-03 15:13 Ravid Baruch Naali [this message]
2007-09-03 15:32 ` [Xenomai-core] [PATCH] VxWorks semaphore usage demo Gilles Chanteperdrix
2007-09-03 17:17   ` Philippe Gerum
2007-09-03 17:29     ` Ravid Baruch Naali
2007-09-03 20:57   ` Ravid Baruch Naali
2007-09-04  8:50     ` Gilles Chanteperdrix
2007-09-04 14:12       ` Philippe Gerum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46DC2484.6040004@domain.hid \
    --to=ravidbn@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.