File: shmem.cpp

package info (click to toggle)
bowtie 1.2.3+dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 16,888 kB
  • sloc: cpp: 35,784; perl: 5,903; ansic: 1,247; sh: 1,180; python: 487; makefile: 426
file content (37 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * shmem.cpp
 *
 *  Created on: August 13, 2009
 *      Author: Ben Langmead
 */

#ifdef BOWTIE_SHARED_MEM

#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/shm.h>
#include <errno.h>
#include "shmem.h"

using namespace std;

/**
 * Notify other users of a shared-memory chunk that the leader has
 * finished initializing it.
 */
void notifySharedMem(void *mem, size_t len) {
	((volatile uint32_t*)((char*)mem + len))[0] = SHMEM_INIT;
}

/**
 * Wait until the leader of a shared-memory chunk has finished
 * initializing it.
 */
void waitSharedMem(void *mem, size_t len) {
	while(((volatile uint32_t*)((char*)mem + len))[0] != SHMEM_INIT) {
		sleep(1);
	}
}

#endif