本文整理汇总了C++中shm_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ shm_lock函数的具体用法?C++ shm_lock怎么用?C++ shm_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shm_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shm_event_raise
void shm_event_raise(long used, long size, long perc)
{
evi_params_p list = 0;
*event_shm_pending = 1;
*event_shm_last = perc;
// event has to be triggered - check for subscribers
if (!evi_probe_event(EVI_SHM_THRESHOLD_ID)) {
goto end;
}
if (!(list = evi_get_params()))
goto end;
if (evi_param_add_int(list, &shm_usage_str, (int *)&perc)) {
LM_ERR("unable to add usage parameter\n");
goto end;
}
if (evi_param_add_int(list, &shm_threshold_str, (int *)&event_shm_threshold)) {
LM_ERR("unable to add threshold parameter\n");
goto end;
}
if (evi_param_add_int(list, &shm_used_str, (int *)&used)) {
LM_ERR("unable to add used parameter\n");
goto end;
}
if (evi_param_add_int(list, &shm_size_str, (int *)&size)) {
LM_ERR("unable to add size parameter\n");
goto end;
}
/*
* event has to be raised without the lock otherwise a deadlock will be
* generated by the transport modules, or by the event_route processing
*/
#ifdef HP_MALLOC
shm_unlock(0);
#else
shm_unlock();
#endif
if (evi_raise_event(EVI_SHM_THRESHOLD_ID, list)) {
LM_ERR("unable to send shm threshold event\n");
}
#ifdef HP_MALLOC
shm_lock(0);
#else
shm_lock();
#endif
list = 0;
end:
if (list)
evi_free_params(list);
*event_shm_pending = 0;
}
示例2: qm_shm_info
void qm_shm_info(void* qmp, struct mem_info* info)
{
shm_lock();
qm_info(qmp, info);
shm_unlock();
}
示例3: while
bool
SHMSrc::resize_area()
{
while ((sizeof(SHMHeader) + shm_area_->buffer_size) > shm_area_len_) {
size_t new_size = sizeof(SHMHeader) + shm_area_->buffer_size;
shm_unlock();
if (munmap(shm_area_, shm_area_len_)) {
std::cerr << "Could not unmap shared area" << std::endl;
perror(strerror(errno));
return false;
}
shm_area_ = static_cast<SHMHeader*>(mmap(NULL, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
shm_area_len_ = new_size;
if (!shm_area_) {
shm_area_ = 0;
std::cerr << "Could not remap shared area" << std::endl;
return false;
}
shm_area_len_ = new_size;
shm_lock();
}
return true;
}
示例4: shm_unlock
bool SHMSink::resize_area(size_t desired_length)
{
if (desired_length <= shm_area_len_)
return true;
shm_unlock();
if (munmap(shm_area_, shm_area_len_)) {
ERROR("Could not unmap shared area");
strErr();
return false;
}
if (ftruncate(fd_, desired_length)) {
ERROR("Could not resize shared area");
strErr();
return false;
}
shm_area_ = static_cast<SHMHeader*>(mmap(NULL, desired_length, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
shm_area_len_ = desired_length;
if (shm_area_ == MAP_FAILED) {
shm_area_ = 0;
ERROR("Could not remap shared area");
return false;
}
shm_lock();
return true;
}
示例5: qm_shm_free
void qm_shm_free(void* qmp, void* p, const char* file, const char* func,
unsigned int line)
{
shm_lock();
qm_free(qmp, p, file, func, line);
shm_unlock();
}
示例6: shm_callback
int shm_callback(int mode, struct kern_ipc_perm *ipc, struct ipc_namespace *ns)
{
switch(mode) {
case 0:
printf("key shmid owner perms bytes nattch status \n");
break;
case 1:
if(id==-1 || id==ipc->id) {
struct shmid_kernel *shp = shm_lock(ns, ipc->id);
printf("0x%08x %-10d %-10d %-10o %-10ld %-10ld %-6s %-6s\n",
ipc->key,
ipc->id,
ipc->uid,
ipc->mode & 0777,
shp->shm_segsz,
shp->shm_nattch,
ipc->mode & SHM_DEST ? "dest" : " ",
ipc->mode & SHM_LOCKED ? "locked" : " ");
}
break;
case 2:
break;
}
return 1;
}
示例7: shm_available_safe
unsigned long shm_available_safe()
{
unsigned long ret;
shm_lock();
ret = shm_available();
shm_unlock();
return ret;
}
示例8: qm_shm_realloc
void* qm_shm_realloc(void* qmp, void* p, unsigned long size)
{
void *r;
shm_lock();
r = qm_realloc(qmp, p, size);
shm_unlock();
return r;
}
示例9: qm_shm_available
unsigned long qm_shm_available(void* qmp)
{
unsigned long r;
shm_lock();
r = qm_available(qmp);
shm_unlock();
return r;
}
示例10: sh_realloc
inline static void* sh_realloc(void* p, unsigned int size)
{
void *r;
shm_lock();
shm_free_unsafe(p);
r=shm_malloc_unsafe(size);
shm_unlock();
return r;
}
示例11: qm_shm_resize
void* qm_shm_resize(void* qmp, void* p, unsigned long size)
{
void *r;
shm_lock();
if(p) qm_free(qmp, p);
r = qm_malloc(qmp, size);
shm_unlock();
return r;
}
示例12: shm_inc
static inline void shm_inc (int id) {
struct shmid_kernel *shp;
if(!(shp = shm_lock(id)))
BUG();
shp->shm_atim = CURRENT_TIME;
shp->shm_lprid = current->pid;
shp->shm_nattch++;
shm_unlock(id);
}
示例13: shm_inc
static inline void shm_inc (int id) {
struct shmid_kernel *shp;
if(!(shp = shm_lock(id)))
BUG();
shp->shm_atim = get_seconds();
shp->shm_lprid = current->tgid;
shp->shm_nattch++;
shm_unlock(shp);
}
示例14: shm_lock
void SHMSrc::render(char *dest, size_t len)
{
shm_lock();
while (buffer_gen_ == shm_area_->buffer_gen) {
shm_unlock();
std::cerr << "Waiting for next buffer" << std::endl;;
sem_wait(&shm_area_->notification);
shm_lock();
}
if (!resize_area())
return;
std::cerr << "Reading from buffer!" << std::endl;
memcpy(dest, shm_area_->data, len);
buffer_gen_ = shm_area_->buffer_gen;
shm_unlock();
}
示例15: update_totag_set
/* append a newly received tag from a 200/INVITE to
* transaction's set; (only safe if called from within
* a REPLY_LOCK); it returns 1 if such a to tag already
* exists
*/
inline static int update_totag_set(struct cell *t, struct sip_msg *ok)
{
struct totag_elem *i, *n;
str *tag;
char *s;
if (!ok->to || !ok->to->parsed) {
LM_ERR("to not parsed\n");
return 0;
}
tag=&get_to(ok)->tag_value;
if (!tag->s) {
LM_DBG("no tag in to\n");
return 0;
}
for (i=t->fwded_totags; i; i=i->next) {
if (i->tag.len==tag->len
&& memcmp(i->tag.s, tag->s, tag->len) ==0 ){
/* to tag already recorded */
#ifdef XL_DEBUG
LM_CRIT("totag retransmission\n");
#else
LM_DBG("totag retransmission\n");
#endif
return 1;
}
}
/* that's a new to-tag -- record it */
#ifndef HP_MALLOC
shm_lock();
n=(struct totag_elem*) shm_malloc_unsafe(sizeof(struct totag_elem));
s=(char *)shm_malloc_unsafe(tag->len);
shm_unlock();
#else
n=(struct totag_elem*) shm_malloc(sizeof(struct totag_elem));
s=(char *)shm_malloc(tag->len);
#endif
if (!s || !n) {
LM_ERR("no more share memory \n");
if (n) shm_free(n);
if (s) shm_free(s);
return 0;
}
memset(n, 0, sizeof(struct totag_elem));
memcpy(s, tag->s, tag->len );
n->tag.s=s;n->tag.len=tag->len;
n->next=t->fwded_totags;
t->fwded_totags=n;
LM_DBG("new totag \n");
return 0;
}