PoCL 源码学习 --- POCL_LOCK 实现
pocl_cl.h - local runtime library declarations.
POCL_LOCK implementation in pocl_cl.h
Guess this is a pthread lock(? I don't know!)
/* Some pthread_*() calls may return '0' or a specific non-zero value on
* success.
*/
#define PTHREAD_CHECK2(_status_ok, _code) \
do \
{ \
int _pthread_status = (_code); \
if (_pthread_status != 0 && _pthread_status != (_status_ok)) \
pocl_abort_on_pthread_error (_pthread_status, __LINE__, \
__FUNCTION__); \
} \
while (0)
#define PTHREAD_CHECK(code) PTHREAD_CHECK2 (0, code)
/* Generic functionality for handling different types of
OpenCL (host) objects. */
#define POCL_LOCK(__LOCK__) PTHREAD_CHECK (pthread_mutex_lock (&(__LOCK__)))
#define POCL_UNLOCK(__LOCK__) \
PTHREAD_CHECK (pthread_mutex_unlock (&(__LOCK__)))
#define POCL_INIT_LOCK(__LOCK__) \
PTHREAD_CHECK (pthread_mutex_init (&(__LOCK__), NULL))
/* We recycle OpenCL objects by not actually freeing them until the
very end. Thus, the lock should not be destroyed at the refcount 0. */
#define POCL_DESTROY_LOCK(__LOCK__) \
PTHREAD_CHECK (pthread_mutex_destroy (&(__LOCK__)))