Created
April 19, 2012 21:43
-
-
Save dcolish/2424404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stdio.h> | |
#include "Python.h" | |
#define atomic_int_add(ptr, val) __sync_add_and_fetch(&ptr, val) | |
static PyObject* | |
int_add(PyObject *self, PyObject *args) | |
{ | |
int avalue, bvalue; | |
if (!PyArg_ParseTuple(args, "ii", &avalue, &bvalue)) | |
return NULL; | |
return Py_BuildValue("i", atomic_int_add(avalue, bvalue)); | |
} | |
static PyMethodDef AtomicMethods[] = { | |
{"int_add", int_add, METH_VARARGS, "Atomically increment an integer"}, | |
{NULL, NULL, 0, NULL} | |
}; | |
PyMODINIT_FUNC | |
initatomic(void) | |
{ | |
Py_InitModule("atomic", AtomicMethods); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from setuptools import setup, Extension | |
atomic = Extension('atomic', | |
sources=['atomic_py.c']) | |
setup(name='AtomicPy', | |
version='dev', | |
ext_modules=[atomic] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment