]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/ORTEThreadUtils.c
9c1d713e6835a755d23a2f405300480bcd879d2b
[orte.git] / orte / liborte / ORTEThreadUtils.c
1 /*
2  *  $Id: ORTEThreadUtils.c,v 0.0.0.1    2003/08/21 
3  *
4  *  DEBUG:  section 25                   Thread utility
5  *
6  *  -------------------------------------------------------------------  
7  *                                ORTE                                 
8  *                      Open Real-Time Ethernet                       
9  *                                                                    
10  *                      Copyright (C) 2001-2006                       
11  *  Department of Control Engineering FEE CTU Prague, Czech Republic  
12  *                      http://dce.felk.cvut.cz                       
13  *                      http://www.ocera.org                          
14  *                                                                    
15  *  Author:              Petr Smolik    petr.smolik@wo.cz             
16  *  Advisor:             Pavel Pisa                                   
17  *  Project Responsible: Zdenek Hanzalek                              
18  *  --------------------------------------------------------------------
19  *
20  *  This program is free software; you can redistribute it and/or modify
21  *  it under the terms of the GNU General Public License as published by
22  *  the Free Software Foundation; either version 2 of the License, or
23  *  (at your option) any later version.
24  *  
25  *  This program is distributed in the hope that it will be useful,
26  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *  GNU General Public License for more details.
29  *  
30  */ 
31
32 #include "orte_all.h"
33
34 /*****************************************************************************/
35 void
36 ORTEDomainWakeUpReceivingThread(ORTEDomain *d,sock_t *sock,uint16_t port) {
37   struct sockaddr_in    des;
38   char                  sIPAddress[MAX_STRING_IPADDRESS_LENGTH];
39   int                   i;
40
41   des.sin_family = AF_INET;
42   des.sin_port = htons(port);             //to receiving port
43   if (d->domainProp.IFCount) {
44     for(i=0;i<d->domainProp.IFCount;i++) {
45       des.sin_addr.s_addr=htonl(d->domainProp.IFProp[i].ipAddress);
46       sock_sendto(sock,&i,1,&des,sizeof(des));
47       debug(25,2) ("Sent wake up signal to: %s.%d\n",
48                     IPAddressToString(ntohl(des.sin_addr.s_addr),sIPAddress),
49       port);
50     }
51   } else {
52     des.sin_addr.s_addr = inet_addr("127.0.0.1"); //local IPAddress
53     sock_sendto(sock,&i,1,&des,sizeof(des));
54     debug(25,2) ("Sent wake up signal to: %s.%d\n",
55                   IPAddressToString(ntohl(des.sin_addr.s_addr),sIPAddress),
56                   port);
57   }
58 }
59
60 /*****************************************************************************/
61 void
62 ORTEDomainWakeUpSendingThread(ObjectEntry *objectEntry) {
63   debug(25,10) ("WakeUpSendingThread : start\n");
64   if (objectEntry->htimNeedWakeUp) {
65     pthread_mutex_lock(&objectEntry->htimSendMutex);
66     if (objectEntry->htimSendCondValue==0) {
67       debug(25,8) ("WakeUpSendingThread : send wakeup signal\n");
68       pthread_cond_signal(&objectEntry->htimSendCond);
69       objectEntry->htimSendCondValue=1;
70     }
71     pthread_mutex_unlock(&objectEntry->htimSendMutex);
72   }
73 }
74
75
76