• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 extern void *osThreadGetArgument(void);
20 
MUTEX_InitValue()21 MutexId MUTEX_InitValue()
22 {
23     return osMutexNew(NULL);
24 }
25 
MUTEX_Lock(MutexId mutex)26 void MUTEX_Lock(MutexId mutex)
27 {
28     if (mutex == NULL) {
29         return;
30     }
31     osMutexAcquire(mutex, osWaitForever);
32 }
33 
MUTEX_Unlock(MutexId mutex)34 void MUTEX_Unlock(MutexId mutex)
35 {
36     if (mutex == NULL) {
37         return;
38     }
39     osMutexRelease(mutex);
40 }
41 
MUTEX_GlobalLock(void)42 void MUTEX_GlobalLock(void)
43 {
44     osKernelLock();
45 }
46 
MUTEX_GlobalUnlock(void)47 void MUTEX_GlobalUnlock(void)
48 {
49     osKernelUnlock();
50 }
51 
THREAD_Create(Runnable run,void * argv,const ThreadAttr * attr)52 ThreadId THREAD_Create(Runnable run, void *argv, const ThreadAttr *attr)
53 {
54     osThreadAttr_t taskAttr = {attr->name, 0, NULL, 0, NULL, attr->stackSize, attr->priority, 0, 0};
55     return (ThreadId)osThreadNew((osThreadFunc_t)run, argv, &taskAttr);
56 }
57 
THREAD_Total(void)58 int THREAD_Total(void)
59 {
60     return osThreadGetCount();
61 }
62 
THREAD_GetThreadLocal(void)63 void *THREAD_GetThreadLocal(void)
64 {
65     return osThreadGetArgument();
66 }
67 
THREAD_SetThreadLocal(const void * local)68 void THREAD_SetThreadLocal(const void *local)
69 {
70     (void)local;
71 }
72