1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "thread_adapter.h"
16 #include "common.h"
17 #include <cmsis_os.h>
18 
19 
MUTEX_InitValue()20 MutexId MUTEX_InitValue()
21 {
22     return osMutexNew(NULL);
23 }
24 
MUTEX_Lock(MutexId mutex)25 void MUTEX_Lock(MutexId mutex)
26 {
27     if (mutex == NULL) {
28         return;
29     }
30     osMutexAcquire(mutex, osWaitForever);
31 }
32 
MUTEX_Unlock(MutexId mutex)33 void MUTEX_Unlock(MutexId mutex)
34 {
35     if (mutex == NULL) {
36         return;
37     }
38     osMutexRelease(mutex);
39 }
40 
MUTEX_GlobalLock(void)41 void MUTEX_GlobalLock(void)
42 {
43     osKernelLock();
44 }
45 
MUTEX_GlobalUnlock(void)46 void MUTEX_GlobalUnlock(void)
47 {
48     osKernelUnlock();
49 }
50 
THREAD_Create(Runnable run,void * argv,const ThreadAttr * attr)51 ThreadId THREAD_Create(Runnable run, void *argv, const ThreadAttr *attr)
52 {
53     osThreadAttr_t taskAttr = {attr->name, 0, NULL, 0, NULL, attr->stackSize, (osPriority_t)(attr->priority), 0, 0};
54     return (ThreadId)osThreadNew((osThreadFunc_t)run, argv, &taskAttr);
55 }
56 
THREAD_Total(void)57 int THREAD_Total(void)
58 {
59     return osThreadGetCount();
60 }
61 
THREAD_GetThreadLocal(void)62 void *THREAD_GetThreadLocal(void)
63 {
64     return osThreadGetArgument();
65 }
66 
THREAD_SetThreadLocal(const void * local)67 void THREAD_SetThreadLocal(const void *local)
68 {
69     (void)local;
70 }
71