Revision e566c39e src/urt_core.c
src/urt_core.c | ||
---|---|---|
80 | 80 |
*/ |
81 | 81 |
void urtCoreStartNodes(void) |
82 | 82 |
{ |
83 |
//TODO: Lock core
|
|
83 |
urtMutexLock(&core._lock);
|
|
84 | 84 |
urt_node_t* node = core._nodes; |
85 | 85 |
while (node) |
86 | 86 |
{ |
87 | 87 |
urtThreadStart(node->thread); |
88 | 88 |
node = node->next; |
89 | 89 |
} |
90 |
//TODO: Unlock core
|
|
90 |
urtMutexUnlock(&core._lock);
|
|
91 | 91 |
return; |
92 | 92 |
} |
93 | 93 |
|
... | ... | |
101 | 101 |
* Returns URT_STATUS_SYNC_PENDING if there are nodes left to synchronize. |
102 | 102 |
* In the latter case, the node thread must still wait for the control event (proceed) to synchronize. |
103 | 103 |
*/ |
104 |
urt_status_t urtCoreSynchronize(urt_node_t* node) |
|
104 |
urt_status_t urtCoreSynchronizeNodes(urt_node_t* node)
|
|
105 | 105 |
{ |
106 |
//TODO: Lock core
|
|
107 |
//TODO: Increment node's stage value
|
|
106 |
urtMutexLock(&core._lock);
|
|
107 |
node->stage -= 1;
|
|
108 | 108 |
urt_node_t* nodeFromCore = core._nodes; |
109 |
while (nodeFromCore /*stage equals stage*/)
|
|
109 |
while (nodeFromCore && nodeFromCore->stage == node->stage)
|
|
110 | 110 |
{ |
111 | 111 |
nodeFromCore = nodeFromCore->next; |
112 | 112 |
} |
113 |
bool temp = false; |
|
114 |
if (temp/*all nodes are the same stage*/) |
|
113 |
if (nodeFromCore) |
|
115 | 114 |
{ |
116 |
//TODO: Unlock core |
|
115 |
urt_osEventFlags_t flag = 0; /*TODO: set to proceed? */ |
|
116 |
urtEventSourceBroadcast(core._evtSource, flag); |
|
117 |
urtMutexUnlock(&core._lock); |
|
117 | 118 |
return URT_STATUS_OK; |
118 | 119 |
} |
119 |
else if (temp/*stage of the last checked node was one less than the argument*/)
|
|
120 |
else if (nodeFromCore->stage == (node->stage - 1))
|
|
120 | 121 |
{ |
121 |
//TODO: Unlock core
|
|
122 |
urtMutexUnlock(&core._lock);
|
|
122 | 123 |
return URT_STATUS_SYNC_PENDING; |
123 | 124 |
} |
124 | 125 |
else |
125 | 126 |
{ |
126 | 127 |
urtCoreStopNodes(URT_STATUS_SYNC_ERROR); |
128 |
urtMutexUnlock(&core._lock); |
|
127 | 129 |
return URT_STATUS_SYNC_ERROR; |
128 | 130 |
} |
129 | 131 |
} |
... | ... | |
138 | 140 |
*/ |
139 | 141 |
urt_status_t urtCoreStopNodes(urt_status_t reason) |
140 | 142 |
{ |
141 |
//TODO: Lock core |
|
143 |
urtMutexLock(&core._lock); |
|
144 |
bool priorityBoosted = false; |
|
145 |
urt_osThreadPrio_t oldPrio; |
|
146 |
|
|
142 | 147 |
if (core._status == URT_STATUS_OK) |
143 | 148 |
{ |
144 | 149 |
if (core._nodes->thread->prio < URT_THREAD_PRIO_HIGH_MAX) |
145 | 150 |
{ |
151 |
oldPrio = core._nodes->thread->prio; |
|
152 |
priorityBoosted = true; |
|
146 | 153 |
core._nodes->thread->prio = URT_THREAD_PRIO_HIGH_MAX; |
147 | 154 |
} |
148 |
else |
|
155 |
core._status = reason; |
|
156 |
urt_node_t* node = core._nodes; |
|
157 |
while (node) |
|
149 | 158 |
{ |
150 |
core._status = reason; |
|
151 |
urt_node_t* node = core._nodes; |
|
152 |
while (node) |
|
153 |
{ |
|
154 |
urt_node_t* tempNode = node; |
|
155 |
tempNode = NULL; |
|
156 |
node = node->next; |
|
157 |
} |
|
158 |
//TODO: broadcast control event (terminate) |
|
159 |
//TODO:Unlock core |
|
160 |
//TODO: Thread boosted its priority? |
|
159 |
urtThreadTerminate(node->thread, URT_THREAD_TERMINATE_REQUEST); |
|
160 |
node = node->next; |
|
161 | 161 |
} |
162 |
urt_osEventFlags_t flag = 0; /*TODO: set to terminate? */ |
|
163 |
urtEventSourceBroadcast(core._evtSource, flag); |
|
164 |
urtMutexUnlock(&core._lock); |
|
165 |
if (priorityBoosted) |
|
166 |
core._nodes->thread->prio = oldPrio; |
|
167 |
return URT_STATUS_OK; |
|
162 | 168 |
} |
163 | 169 |
else |
164 | 170 |
{ |
165 |
//TODO:Unlock core
|
|
166 |
return core._status;
|
|
171 |
urtMutexUnlock(&core._lock);
|
|
172 |
return core._status; |
|
167 | 173 |
} |
168 |
return URT_STATUS_OK; |
|
169 | 174 |
} |
170 | 175 |
|
171 | 176 |
/** |
Also available in: Unified diff