1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "pycore_abstract.h" // _PyNumber_Index()
6 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
7
8 PyDoc_STRVAR(_testinternalcapi_benchmark_locks__doc__,
9 "benchmark_locks($module, num_threads, use_pymutex=True,\n"
10 " critical_section_length=1, time_ms=1000, /)\n"
11 "--\n"
12 "\n");
13
14 #define _TESTINTERNALCAPI_BENCHMARK_LOCKS_METHODDEF \
15 {"benchmark_locks", _PyCFunction_CAST(_testinternalcapi_benchmark_locks), METH_FASTCALL, _testinternalcapi_benchmark_locks__doc__},
16
17 static PyObject *
18 _testinternalcapi_benchmark_locks_impl(PyObject *module,
19 Py_ssize_t num_threads,
20 int use_pymutex,
21 int critical_section_length,
22 int time_ms);
23
24 static PyObject *
_testinternalcapi_benchmark_locks(PyObject * module,PyObject * const * args,Py_ssize_t nargs)25 _testinternalcapi_benchmark_locks(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
26 {
27 PyObject *return_value = NULL;
28 Py_ssize_t num_threads;
29 int use_pymutex = 1;
30 int critical_section_length = 1;
31 int time_ms = 1000;
32
33 if (!_PyArg_CheckPositional("benchmark_locks", nargs, 1, 4)) {
34 goto exit;
35 }
36 {
37 Py_ssize_t ival = -1;
38 PyObject *iobj = _PyNumber_Index(args[0]);
39 if (iobj != NULL) {
40 ival = PyLong_AsSsize_t(iobj);
41 Py_DECREF(iobj);
42 }
43 if (ival == -1 && PyErr_Occurred()) {
44 goto exit;
45 }
46 num_threads = ival;
47 }
48 if (nargs < 2) {
49 goto skip_optional;
50 }
51 use_pymutex = PyObject_IsTrue(args[1]);
52 if (use_pymutex < 0) {
53 goto exit;
54 }
55 if (nargs < 3) {
56 goto skip_optional;
57 }
58 critical_section_length = PyLong_AsInt(args[2]);
59 if (critical_section_length == -1 && PyErr_Occurred()) {
60 goto exit;
61 }
62 if (nargs < 4) {
63 goto skip_optional;
64 }
65 time_ms = PyLong_AsInt(args[3]);
66 if (time_ms == -1 && PyErr_Occurred()) {
67 goto exit;
68 }
69 skip_optional:
70 return_value = _testinternalcapi_benchmark_locks_impl(module, num_threads, use_pymutex, critical_section_length, time_ms);
71
72 exit:
73 return return_value;
74 }
75 /*[clinic end generated code: output=105105d759c0c271 input=a9049054013a1b77]*/
76