cond_var.c

00001 #include <native/mutex.h>
00002 #include <native/cond.h>
00003 
00004 RT_COND cond_desc;
00005 
00006 RT_MUTEX mutex_desc;
00007 
00008 int shared_event = 0;
00009 
00010 void foo (void)
00011 
00012 {
00013     int err;
00014 
00015     /* Create a condition variable and a mutex guarding it; we could
00016        also have attempted to bind to some pre-existing objects, using
00017        rt_cond_bind() and rt_mutex_bind() instead of creating them. */
00018 
00019     err = rt_mutex_create(&mutex_desc,"MyCondMutex");
00020     err = rt_cond_create(&cond_desc,"MyCondVar");
00021 
00022     /* Now, wait for some task to post the shared event... */
00023 
00024     rt_mutex_acquire(&mutex_desc,TM_INFINITE);
00025 
00026     while (!shared_event && !err)
00027         err = rt_cond_wait(&cond_desc,&mutex_desc,TM_INFINITE);
00028     
00029     rt_mutex_release(&mutex_desc);
00030 
00031     /* ... */
00032 }
00033 
00034 void bar (void)
00035 
00036 {
00037     /* ... */
00038 
00039     /* Post the shared event. */
00040 
00041     rt_mutex_acquire(&mutex_desc,TM_INFINITE);
00042 
00043     shared_event = 1;
00044     rt_cond_signal(&cond_desc);
00045 
00046     rt_mutex_release(&mutex_desc);
00047 
00048     /* ... */
00049 }
00050 
00051 void cleanup (void)
00052 
00053 {
00054     rt_cond_delete(&cond_desc);
00055     rt_mutex_delete(&mutex_desc);
00056 }

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3