2 * PASS (Power Aware System Service)
4 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <libsyscommon/resource-manager.h>
21 #include <monitor/monitor.h>
23 static void _monitor_command_wait_done(struct monitor_command *cmd, int polling)
29 cnd_wait(&cmd->signal, &cmd->lock);
30 mtx_unlock(&cmd->lock);
31 /* done at this time */
37 void monitor_command_wait_done(struct monitor_command *cmd)
39 _monitor_command_wait_done(cmd, 0);
42 void monitor_command_submit(struct monitor_command *cmd)
44 struct monitor *monitor = monitor_get();
47 enqueue(monitor->q, (void *)cmd);
49 cnd_signal(&monitor->signal);
52 void monitor_command_submit_sync(struct monitor_command *cmd)
54 monitor_command_submit(cmd);
55 _monitor_command_wait_done(cmd, MONITOR_POLLING_DURATION);
58 void monitor_command_bind_resource(struct monitor_command *cmd, int resource_id)
60 if (cmd->resource_id >= 0) {
61 _E("resource is already bound\n");
65 cmd->resource_id = resource_id;
68 void monitor_command_unbind_resource(struct monitor_command *cmd)
70 if (cmd->resource_id < 0) {
71 _E("resource is not bound yet\n");
75 cmd->resource_id = -1;
78 int monitor_command_init(struct monitor_command **cmd)
80 struct monitor_command *new_cmd;
82 new_cmd = calloc(1, sizeof(struct monitor_command));
86 mtx_init(&new_cmd->lock, mtx_plain);
87 cnd_init(&new_cmd->signal);
88 new_cmd->resource_id = -1;
89 new_cmd->done = false;
96 void monitor_command_exit(struct monitor_command *cmd)
98 cnd_destroy(&cmd->signal);
99 mtx_destroy(&cmd->lock);
101 if (cmd->resource_id >= 0)
102 _W("resource is not unbound before destroying request\n");