@@ -383,8 +383,22 @@ static PyObject * vmp_get_profile_path(PyObject *module, PyObject *noargs) {
383383
384384#ifdef VMPROF_UNIX
385385static PyObject *
386- insert_real_time_thread (PyObject * module , PyObject * noargs ) {
386+ insert_real_time_thread (PyObject * module , PyObject * args ) {
387387 ssize_t thread_count ;
388+ unsigned long thread_id = 0 ;
389+ pthread_t th = pthread_self ();
390+
391+ if (!PyArg_ParseTuple (args , "|k" , & thread_id )) {
392+ return NULL ;
393+ }
394+
395+ if (thread_id ) {
396+ #if SIZEOF_LONG <= SIZEOF_PTHREAD_T
397+ th = (pthread_t ) thread_id ;
398+ #else
399+ th = (pthread_t ) * (unsigned long * ) & thread_id ;
400+ #endif
401+ }
388402
389403 if (!vmprof_is_enabled ()) {
390404 PyErr_SetString (PyExc_ValueError , "vmprof is not enabled" );
@@ -397,15 +411,29 @@ insert_real_time_thread(PyObject *module, PyObject * noargs) {
397411 }
398412
399413 vmprof_aquire_lock ();
400- thread_count = insert_thread (pthread_self () , -1 );
414+ thread_count = insert_thread (th , -1 );
401415 vmprof_release_lock ();
402416
403417 return PyLong_FromSsize_t (thread_count );
404418}
405419
406420static PyObject *
407- remove_real_time_thread (PyObject * module , PyObject * noargs ) {
421+ remove_real_time_thread (PyObject * module , PyObject * args ) {
408422 ssize_t thread_count ;
423+ unsigned long thread_id = 0 ;
424+ pthread_t th = pthread_self ();
425+
426+ if (!PyArg_ParseTuple (args , "|k" , & thread_id )) {
427+ return NULL ;
428+ }
429+
430+ if (thread_id ) {
431+ #if SIZEOF_LONG <= SIZEOF_PTHREAD_T
432+ th = (pthread_t ) thread_id ;
433+ #else
434+ th = (pthread_t ) * (unsigned long * ) & thread_id ;
435+ #endif
436+ }
409437
410438 if (!vmprof_is_enabled ()) {
411439 PyErr_SetString (PyExc_ValueError , "vmprof is not enabled" );
@@ -418,7 +446,7 @@ remove_real_time_thread(PyObject *module, PyObject * noargs) {
418446 }
419447
420448 vmprof_aquire_lock ();
421- thread_count = remove_thread (pthread_self () , -1 );
449+ thread_count = remove_thread (th , -1 );
422450 vmprof_release_lock ();
423451
424452 return PyLong_FromSsize_t (thread_count );
@@ -445,9 +473,9 @@ static PyMethodDef VMProfMethods[] = {
445473#ifdef VMPROF_UNIX
446474 {"get_profile_path" , vmp_get_profile_path , METH_NOARGS ,
447475 "Profile path the profiler logs to." },
448- {"insert_real_time_thread" , insert_real_time_thread , METH_NOARGS ,
476+ {"insert_real_time_thread" , insert_real_time_thread , METH_VARARGS ,
449477 "Insert a thread into the real time profiling list." },
450- {"remove_real_time_thread" , remove_real_time_thread , METH_NOARGS ,
478+ {"remove_real_time_thread" , remove_real_time_thread , METH_VARARGS ,
451479 "Remove a thread from the real time profiling list." },
452480#endif
453481 {NULL , NULL , 0 , NULL } /* Sentinel */
0 commit comments