2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef SERVER_WORKER_THREAD_HH_
18 #define SERVER_WORKER_THREAD_HH_
20 #include <glib-2.0/glib.h>
22 #include <sys/types.h>
24 #include <condition_variable>
32 #include "shared_object.hh"
33 #include "pkg_request.hh"
35 namespace pkgmgr_server {
38 #define EXPORT_API __attribute__((visibility("default")))
41 class EXPORT_API WorkerThread {
43 explicit WorkerThread(unsigned int num);
45 bool PushQueue(std::shared_ptr<PkgRequest> req);
46 void SetLocale(std::string locale);
50 void SendError(const std::shared_ptr<PkgRequest>& req);
51 void SetMemoryTrimTimer();
52 void StopDbChangeListening();
53 static gboolean TrimMemory(void* data);
54 std::shared_ptr<PkgRequest> PopQueue();
58 utils::SharedObject<std::string> locale_;
59 std::queue<std::shared_ptr<PkgRequest>> queue_;
60 std::vector<std::thread> threads_;
62 std::condition_variable cv_;
63 std::recursive_mutex mutex_;
67 } // namespace pkgmgr_server
69 #endif // SERVER_WORKER_THREAD_HH_