Revision 408a606c

View differences:

inc/urt_core.h
40 40
/* DATA STRUCTURES AND TYPES                                                  */
41 41
/******************************************************************************/
42 42

  
43
/**
44
 * @brief  core
45
 */
46
typedef struct urt_core
47
{
48
  urt_node_t* _nodes;
49
  urt_osEventSource_t* _evtSource;
50
  urt_osMutex_t _lock;
51
  urt_status_t _status;
52
  #if (URT_CFG_PUBSUB_ENABLED)
53
    urt_topic_t* _topics;
54
  #endif /* URT_CFG_PUBSUB_ENABLED */
55
  #if (URT_CFG_RPC_ENABLED)
56
    urt_service_t* _services;
57
  #endif /* URT_CFG_RPC_ENABLED */
58
}urt_core_t;
59

  
60
static urt_core_t core;
61

  
62 43
/******************************************************************************/
63 44
/* MACROS                                                                     */
64 45
/******************************************************************************/
......
73 54

  
74 55
  void urtCoreInit(void);
75 56
  urt_status_t urtCoreGetStatus(void);
57
  urt_osMutex_t urtCoreGetMutex(void);
58
  urt_osEventSource_t* urtCoreGetEvtSource(void);
59
  urt_node_t* urtCoreGetNodes(void);
76 60
  void urtCoreStartNodes(void);
77 61
  urt_status_t urtCoreSynchronizeNodes(urt_node_t* node);
78 62
  urt_status_t urtCoreStopNodes(urt_status_t reason);
src/urt_core.c
33 33
/* LOCAL TYPES                                                                */
34 34
/******************************************************************************/
35 35

  
36
/**
37
 * @brief  core
38
 */
39
typedef struct urt_core
40
{
41
  urt_node_t* _nodes;
42
  urt_osEventSource_t* _evtSource;
43
  urt_osMutex_t _lock;
44
  urt_status_t _status;
45
  #if (URT_CFG_PUBSUB_ENABLED)
46
    urt_topic_t* _topics;
47
  #endif /* URT_CFG_PUBSUB_ENABLED */
48
  #if (URT_CFG_RPC_ENABLED)
49
    urt_service_t* _services;
50
  #endif /* URT_CFG_RPC_ENABLED */
51
}urt_core_t;
52

  
53
static urt_core_t core;
54

  
36 55
/******************************************************************************/
37 56
/* LOCAL VARIABLES                                                            */
38 57
/******************************************************************************/
......
74 93
}
75 94

  
76 95
/**
96
 * @brief   Get Core mutex.
97
 *
98
 * @return  Current system mutex.
99
 */
100
urt_osMutex_t urtCoreGetMutex(void)
101
{
102
    return core._lock;
103
}
104

  
105
/**
106
 * @brief   Get Core event source.
107
 *
108
 * @return  Current system event source.
109
 */
110
urt_osEventSource_t* urtCoreGetEvtSource(void)
111
{
112
    return core._evtSource;
113
}
114

  
115
urt_node_t* urtCoreGetNodes(void)
116
{
117
    return core._nodes;
118
}
119

  
120
/**
77 121
 * @brief   Start threads of all nodes of the Core.
78 122
 */
79 123
void urtCoreStartNodes(void)
src/urt_node.c
52 52
{
53 53
  urt_osEventMask_t mask;
54 54
  urt_osEventFlags_t flag;   //TODO: flag from core here
55
  urtEventRegister(core._evtSource, &localNode.listener, mask, flag);
55
  urtEventRegister(urtCoreGetEvtSource(), &localNode.listener, mask, flag);
56 56
  if (localNode.setupcallback != NULL)
57 57
  {
58 58
    mask = localNode.setupcallback(&localNode, arg);
......
66 66
     mask = 0xFFFFFFFF;
67 67
  }
68 68

  
69
  if (core._status == URT_STATUS_OK)
69
  if (urtCoreGetStatus() == URT_STATUS_OK)
70 70
  {
71 71
    urtCoreSynchronizeNodes(&localNode);
72 72
  }
......
92 92
  {
93 93
    localNode.shutdowncallback(&localNode, urtCoreGetStatus(), arg);
94 94
  }
95
  urtEventUnregister(core._evtSource, &localNode.listener);
95
  urtEventUnregister(urtCoreGetEvtSource(), &localNode.listener);
96 96
  urt_osThread_t* threadToTerminate = localNode.thread;
97 97
  urt_osThread_t* threadToTerminateChild;
98 98
  while (threadToTerminate != NULL)
......
150 150
  #if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING)
151 151
    node->loops = 0;
152 152
  #endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */
153
  urtMutexLock(&core._lock);
154
    node->next = core._nodes;
155
    core._nodes = node;
156
  urtMutexUnlock(&core._lock);
153
  urt_osMutex_t mutexTemp = urtCoreGetMutex();
154
  urtMutexLock(&mutexTemp);
155
    node->next = urtCoreGetNodes();
156
    urt_node_t* nodeCore = urtCoreGetNodes();
157
    nodeCore = node;
158
  urtMutexUnlock(&mutexTemp);
157 159
  localNode = *node;
158 160
  return;
159 161
}

Also available in: Unified diff