mlock.c

来自「KPIT GNU Tools is a set of GNU developme」· C语言 代码 · 共 65 行

C
65
字号
#ifndef MALLOC_PROVIDED/*FUNCTION<<__malloc_lock>>, <<__malloc_unlock>>---lock malloc poolINDEX	__malloc_lockINDEX	__malloc_unlockANSI_SYNOPSIS	#include <malloc.h>	void __malloc_lock (struct _reent *<[reent]>);	void __malloc_unlock (struct _reent *<[reent]>);TRAD_SYNOPSIS	void __malloc_lock(<[reent]>)	struct _reent *<[reent]>;	void __malloc_unlock(<[reent]>)	struct _reent *<[reent]>;DESCRIPTIONThe <<malloc>> family of routines call these functions when they need to lockthe memory pool.  The version of these routines supplied in the library usethe lock API defined in sys/lock.h.  If multiple threads of execution cancall <<malloc>>, or if <<malloc>> can be called reentrantly, then you need todefine your own versions of these functions in order to safely lock thememory pool during a call.  If you do not, the memory pool may becomecorrupted.A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,<<__malloc_unlock>>, <<__malloc_unlock>>.  Any implementation of theseroutines must be careful to avoid causing a thread to wait for a lockthat it already holds.*/#include <malloc.h>#include <sys/lock.h>#ifndef __SINGLE_THREAD____LOCK_INIT_RECURSIVE(static, __malloc_lock_object);#endifvoid__malloc_lock (ptr)     struct _reent *ptr;{#ifndef __SINGLE_THREAD__  __lock_acquire_recursive (__malloc_lock_object);#endif}void__malloc_unlock (ptr)     struct _reent *ptr;{#ifndef __SINGLE_THREAD__  __lock_release_recursive (__malloc_lock_object);#endif}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?