Revision 408b49ce src/urt_node.c

View differences:

src/urt_node.c
48 48
 */
49 49
void _main(void* arg)
50 50
{
51
  urt_node_t* localNode = (urt_node_t*)arg;
52 51
  urt_osEventMask_t mask;
53 52
  urt_osEventFlags_t flag = 0;
54
  urtEventRegister(urtCoreGetEvtSource(), &(localNode->listener), mask, flag);
55
  if (localNode->setupcallback != NULL)
53
  urtEventRegister(urtCoreGetEvtSource(), &(((urt_node_t*)arg)->listener), mask, flag);
54
  if (((urt_node_t*)arg)->setupcallback != NULL)
56 55
  {
57
    mask = localNode->setupcallback(localNode, localNode->setupparams);
56
    mask = ((urt_node_t*)arg)->setupcallback(((urt_node_t*)arg), ((urt_node_t*)arg)->setupparams);
58 57
    if (mask == urtCoreGetEventMask())
59 58
    {
60
        urtCoreStopNodes(URT_STATUS_NODE_INVALEVTMASK);
59
      urtCoreStopNodes(URT_STATUS_NODE_INVALEVTMASK);
61 60
    }
62 61
  }
63 62
  else
64 63
  {
65
     mask = URT_EVENTMASK_ALL;
64
    mask = URT_EVENTMASK_ALL;
66 65
  }
67 66

  
68 67
  if (urtCoreGetStatus() == URT_STATUS_OK)
69 68
  {
70
    urtCoreSynchronizeNodes(localNode);
69
    urtCoreSynchronizeNodes(((urt_node_t*)arg));
71 70
  }
72 71

  
73
  if (!urtThreadShouldTerminate())
72
  while (!urtThreadShouldTerminate())
74 73
  {
75 74
    urt_osEventMask_t temp = urtEventWait(mask, URT_EVENT_WAIT_ONE, URT_DELAY_INFINITE);
76 75
    if (temp == urtCoreGetEventMask())
77 76
    {
78
      localNode->loopcallback(localNode, mask, localNode->loopparams);
77
      ((urt_node_t*)arg)->loopcallback(((urt_node_t*)arg), mask, ((urt_node_t*)arg)->loopparams);
79 78
      #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
80
        localNode->loops++;
79
        ((urt_node_t*)arg)->loops++;
81 80
      #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
82 81
      if (mask == urtCoreGetEventMask())
83 82
      {
......
86 85
    }
87 86
  }
88 87

  
89
  if (localNode->shutdowncallback)
88
  if (((urt_node_t*)arg)->shutdowncallback != NULL)
90 89
  {
91
    localNode->shutdowncallback(localNode, urtCoreGetStatus(), localNode->shutdownparams);
90
    ((urt_node_t*)arg)->shutdowncallback(((urt_node_t*)arg), urtCoreGetStatus(), ((urt_node_t*)arg)->shutdownparams);
92 91
  }
93
  urtEventUnregister(urtCoreGetEvtSource(), &localNode->listener);
92
  urtEventUnregister(urtCoreGetEvtSource(), &((urt_node_t*)arg)->listener);
94 93

  
95
  urt_osThread_t* threadToTerminate = localNode->thread;
94
  urt_osThread_t* threadToTerminate = ((urt_node_t*)arg)->thread;
96 95
  while (threadToTerminate->children != NULL || threadToTerminate->sibling != NULL)
97 96
  {
98 97
    if (threadToTerminate->children != NULL)
......
102 101
  }
103 102
  urtThreadTerminate(threadToTerminate, URT_THREAD_TERMINATE_REQUEST);
104 103

  
105
  urt_osThread_t* threadToJoin = localNode->thread;
104
  urt_osThread_t* threadToJoin = ((urt_node_t*)arg)->thread;
106 105
  while (threadToJoin->children != NULL || threadToJoin->sibling != NULL)
107 106
  {
108 107
    if (threadToJoin->children != NULL)
......
123 122
 * @brief  Initalize a node.
124 123
 *
125 124
 * @param[in] node  The node to initialize. Must not be NULL.
126
 * @param[in] thread  The thread to intialize. Must be NULL.
125
 * @param[in] thread  The thread to intialize.
127 126
 * @param[in] setupcallback  Callback function to be executed during setup.
128 127
 *                           May be NULL if no custom setup is required.
129 128
 * @param[in] setupparams  Parameters for the setup callback function.
......
143 142
                 urt_nodeShutdownCallback_t shutdowncallback, void* shutdownparams)
144 143
{
145 144
  urtDebugAssert(node != NULL);
146
  urtDebugAssert(thread == NULL);
147 145
  if (setupcallback == NULL)
148 146
    urtDebugAssert(setupparams == NULL);
149 147

  
150 148
  node->next = NULL;
151
  node->thread = urtThreadInit(thread, sizeof(thread), prio, _main, node);
149
  node->thread = urtThreadInit((void*)thread, sizeof(thread), prio, (urt_osThreadFunction_t) _main, (void*)node);
152 150
  node->setupcallback = setupcallback;
153 151
  node->setupparams = setupparams;
154 152
  node->loopcallback = loopcallback;

Also available in: Unified diff