26 lines
355 B
C
Executable File
26 lines
355 B
C
Executable File
#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;
|
|
};
|