2017-12-18 15:41:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
2018-04-06 01:11:15 +08:00
|
|
|
#include <ksched.h>
|
|
|
|
#include <wait_q.h>
|
|
|
|
#include <posix/pthread.h>
|
2017-12-18 15:41:03 +08:00
|
|
|
|
|
|
|
int pthread_mutex_trylock(pthread_mutex_t *m)
|
|
|
|
{
|
2018-02-08 11:20:06 +08:00
|
|
|
int key = irq_lock(), ret = EBUSY;
|
2017-12-18 15:41:03 +08:00
|
|
|
|
|
|
|
if (m->sem->count) {
|
|
|
|
m->sem->count = 0;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|