• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef UV_QUEUE_H
16 #define UV_QUEUE_H
17 #include <list>
18 #include <map>
19 #include <shared_mutex>
20 
21 #include "napi/native_node_api.h"
22 
23 namespace OHOS::ObjectStore {
24 typedef void (*Process)(napi_env env, std::list<void *> &);
25 class UvQueue : public std::enable_shared_from_this<UvQueue> {
26 public:
27     UvQueue(napi_env env);
28     virtual ~UvQueue();
29 
30     void CallFunction(Process process, void *argv);
31 
32 private:
33     struct UvEntry {
34         std::weak_ptr<UvQueue> uvQueue_;
35     };
36 
37     static void ExecUvWork(UvEntry *uvEntry);
38 
39     napi_env env_;
40     std::shared_mutex mutex_{};
41     // key is callback,value is list of args
42     std::map<Process, std::list<void *>> args_;
43     uv_loop_s *loop_ = nullptr;
44 };
45 } // namespace OHOS::ObjectStore
46 #endif
47