forked from haraldwolff/avr-fw-modules
26 lines
355 B
C
26 lines
355 B
C
|
#include <sys/mutex.h>
|
||
|
#include <sys/atomic.h>
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
extern avrThread* _thread_current;
|
||
|
|
||
|
uint8_t mutex_try_lock(MUTEX *mutex)
|
||
|
{
|
||
|
if (!mutex)
|
||
|
return 0;
|
||
|
|
||
|
{
|
||
|
ATOMIC
|
||
|
|
||
|
if ((mutex->thread == NULL) || (mutex->thread == current_thread()))
|
||
|
{
|
||
|
mutex->thread = current_thread();
|
||
|
mutex->locked++;
|
||
|
return -1;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
return 0;
|
||
|
};
|