-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
#include "Python.h" | ||
|
||
/* | ||
* This is not quite as dark magic as it looks. We just convert the address of (pointer to) | ||
* a PyObject into a bytes object in _wrap_object, and convert these bytes back to the | ||
* pointer to the original object. | ||
* | ||
* This mainly looks a bit confusing due to our mental special-casing of "char*" from other | ||
* pointers. | ||
* | ||
* The big upside to this is that this neither does *any* serialization (beyond creating tiny | ||
* bytes objects as "stand-ins"), nor has to copy the entire object that's passed around. | ||
*/ | ||
|
||
static PyObject * | ||
_wrap_object(PyObject *obj) | ||
{ | ||
/* | ||
* Create a temporary reference to the object being passed around so it does not vanish. | ||
* Note that we never decref this one in _unwrap_object, since we just transfer that reference | ||
* there, i.e. there is an elided "Py_INCREF(x); Py_DECREF(x)". | ||
This comment has been minimized.
Sorry, something went wrong.
ThomasWaldmann
|
||
*/ | ||
Py_INCREF(obj); | ||
return PyBytes_FromStringAndSize((const char*) &obj, sizeof(void*)); | ||
} | ||
|
||
static PyObject * | ||
_unwrap_object(PyObject *bytes) | ||
{ | ||
if(!PyBytes_Check(bytes)) { | ||
PyErr_SetString(PyExc_TypeError, "Cannot unwrap non-bytes object"); | ||
return NULL; | ||
} | ||
if(PyBytes_Size(bytes) != sizeof(void*)) { | ||
PyErr_SetString(PyExc_TypeError, "Invalid length of bytes object"); | ||
return NULL; | ||
} | ||
PyObject *object = * (PyObject **) PyBytes_AsString(bytes); | ||
return object; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,13 @@ | |
from collections import namedtuple | ||
import locale | ||
import os | ||
import sys | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
cimport cython | ||
from libc.stdint cimport uint32_t, UINT32_MAX, uint64_t | ||
from libc.errno cimport errno | ||
from cpython.exc cimport PyErr_SetFromErrnoWithFilename | ||
from cpython.ref cimport Py_INCREF, Py_DECREF | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
enkore
Author
Owner
|
||
|
||
API_VERSION = '1.1_01' | ||
|
||
|
@@ -31,6 +33,11 @@ cdef extern from "_hashindex.c": | |
double HASH_MAX_LOAD | ||
|
||
|
||
cdef extern from "_utils.c": | ||
object _wrap_object(object obj) | ||
object _unwrap_object(object bytes) | ||
|
||
|
||
cdef _NoDefault = object() | ||
|
||
""" | ||
|
@@ -56,6 +63,14 @@ cdef uint32_t _MAX_VALUE = 2**32-1025 | |
assert _MAX_VALUE % 2 == 1 | ||
|
||
|
||
def wrap_obj(object): | ||
return _wrap_object(object) | ||
|
||
|
||
def unwrap_obj(ptr): | ||
return _unwrap_object(ptr) | ||
This comment has been minimized.
Sorry, something went wrong.
ThomasWaldmann
|
||
|
||
|
||
@cython.internal | ||
cdef class IndexBase: | ||
cdef HashIndex *index | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
#include <pthread.h> | ||
#include <sched.h> | ||
|
||
static int | ||
set_python_thread_affinity(void) | ||
{ | ||
pthread_t thread = pthread_self(); | ||
cpu_set_t cpu_set; | ||
|
||
if(pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpu_set) != 0) { | ||
/* Could be triggered by >64 HW threads */ | ||
return 0; | ||
} | ||
|
||
CPU_ZERO(&cpu_set); | ||
CPU_SET(1, &cpu_set); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ThomasWaldmann
|
||
|
||
if(pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpu_set) != 0) { | ||
/* Parent affinity excludes CPU1 or CPU1 does not exist (usually implies single core system) */ | ||
return 0; | ||
} | ||
|
||
return 1; | ||
} |
1 comment
on commit 4664f2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you copied quite some code from elsewhere to threads.
any plans about how to dedup that and how to test it?
btw, did you notice that (although having added that line)
pip install -e .
does not install pyzmq?