Debian Codegraph @

source/common.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5 #include "common.h"
6
7 #include <aws/common/system_info.h>
8 #include <aws/common/thread.h>
9
10 PyObject *aws_py_get_cpu_group_count(PyObject *self, PyObject *args) {
11 (void)self;
12 (void)args;
13 uint16_t count = aws_get_cpu_group_count();
14 return PyLong_FromUnsignedLong(count);
15 }
16
17 PyObject *aws_py_get_cpu_count_for_group(PyObject *self, PyObject *args) {
18 (void)self;
19
20 uint16_t group_idx;
21 if (!PyArg_ParseTuple(args, "H", &group_idx)) {
22 return NULL;
23 }
24
25 size_t count = aws_get_cpu_count_for_group(group_idx);
26 return PyLong_FromSize_t(count);
27 }
28
29 PyObject *aws_py_thread_join_all_managed(PyObject *self, PyObject *args) {
30 (void)self;
31
32 double timeout_sec = 0.0;
33 if (!PyArg_ParseTuple(args, "d", &timeout_sec)) {
34 PyErr_SetNone(PyExc_ValueError);
35 return NULL;
36 }
37
38 /* Actual call uses 0 to denote "wait forever" */
39 uint64_t timeout_ns;
40 if (timeout_sec < 0.0) {
41 timeout_ns = 0;
42 } else {
43 timeout_ns = (uint64_t)(timeout_sec * 1000000000);
44 if (timeout_ns == 0) {
45 timeout_ns = 1;
46 }
47 }
48 aws_thread_set_managed_join_timeout_ns(timeout_ns);
49 int res = AWS_OP_SUCCESS;
50 /* clang-format off */
51 Py_BEGIN_ALLOW_THREADS
52 /* Drop GIL to allow other threads callback into python to finish joining. */
53 res = aws_thread_join_all_managed();
54 Py_END_ALLOW_THREADS
55
56 if(res == AWS_OP_SUCCESS) {
57 Py_RETURN_TRUE;
58 } else {
59 Py_RETURN_FALSE;
60 }
61 /* clang-format on */
62 }