envlock.c
来自「KPIT GNU Tools is a set of GNU developme」· C语言 代码 · 共 62 行
C
62 行
/*FUNCTION<<__env_lock>>, <<__env_unlock>>---lock environ variableINDEX __env_lockINDEX __env_unlockANSI_SYNOPSIS #include "envlock.h" void __env_lock (struct _reent *<[reent]>); void __env_unlock (struct _reent *<[reent]>);TRAD_SYNOPSIS void __env_lock(<[reent]>) struct _reent *<[reent]>; void __env_unlock(<[reent]>) struct _reent *<[reent]>;DESCRIPTIONThe <<setenv>> family of routines call these functions when they need tomodify the environ variable. The version of these routines supplied in thelibrary use the lock API defined in sys/lock.h. If multiple threads ofexecution can call <<setenv>>, or if <<setenv>> can be called reentrantly,then you need to define your own versions of these functions in order tosafely lock the memory pool during a call. If you do not, the memory poolmay become corrupted.A call to <<setenv>> may call <<__env_lock>> recursively; that is,the sequence of calls may go <<__env_lock>>, <<__env_lock>>,<<__env_unlock>>, <<__env_unlock>>. Any implementation of theseroutines must be careful to avoid causing a thread to wait for a lockthat it already holds.*/#include "envlock.h"#include <sys/lock.h>#ifndef __SINGLE_THREAD____LOCK_INIT_RECURSIVE(static, __env_lock_object);#endifvoid__env_lock (ptr) struct _reent *ptr;{#ifndef __SINGLE_THREAD__ __lock_acquire_recursive (__env_lock_object);#endif}void__env_unlock (ptr) struct _reent *ptr;{#ifndef __SINGLE_THREAD__ __lock_release_recursive (__env_lock_object);#endif}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?