Projekte
workwind
Multitasking optimiert
semaphore.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
Multitask...optimiert
cdll.c
cdll.h
condition.c
condition.h
main.c
mutex.c
mutex.h
scheduler.S
semaphore.c
semaphore.h
thread.c
thread.h
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7426 private projects
385 public projects
16180353 lines compiled
58212 builds
NIBO
@
multitasking_opt/semaphore.c [read only]
#include <avr/interrupt.h> #include "semaphore.h" /* cdll_t waiting_threads; uint16_t counter; */ void semaphore_init(semaphore_t * semaphore) { cdll_reset(&(semaphore->waiting_threads)); semaphore->counter = 0; } void semaphore_delete(semaphore_t * semaphore) { } uint8_t semaphore_acquire(semaphore_t * semaphore, uint16_t timeout) { uint8_t result; cli(); thread_t * thread = thread_getCurrent(); if (semaphore->counter>0) { // semaphore is available semaphore->counter--; result = 1; } else if (timeout==TO_POLL) { // not yet available - return false result = 0; } else { // wait for mutex... cdll_push_back(&(semaphore->waiting_threads), &(thread->rivals_list)); if (timeout == TO_INF) { thread_wait(); } else { thread_waitTimeout(timeout); } cdll_remove(&(thread->rivals_list)); if (semaphore->counter>0) { semaphore->counter--; result = 1; } else { result = 0; } } sei(); return result; } void semaphore_signal(semaphore_t * semaphore) { cli(); semaphore->counter++; cdll_t * next = cdll_peek_front(&(semaphore->waiting_threads)); if (next) { thread_t * t = THREAD_FROM_RIVALS_CDLL(next); thread_signalISR(t); } sei(); } uint8_t semaphore_acquireISR(semaphore_t * semaphore) { if (semaphore->counter>0) { // semaphore is available semaphore->counter--; return 1; } else { return 0; } } void semaphore_signalISR(semaphore_t * semaphore) { semaphore->counter++; cdll_t * next = cdll_peek_front(&(semaphore->waiting_threads)); if (next) { thread_t * t = THREAD_FROM_RIVALS_CDLL(next); thread_signalISR(t); } }
Compiler results:
Werbung
Online
almeda92990951273114
dtsjada1842883129
elidabaylee669745
jeanniebland8449
kimlindberg1853496