Commit patch to not break on spaces.
[bowtie.git] / shmem.cpp
1 /*
2  * shmem.cpp
3  *
4  *  Created on: August 13, 2009
5  *      Author: Ben Langmead
6  */
7
8 #ifdef BOWTIE_SHARED_MEM
9
10 #include <iostream>
11 #include <string>
12 #include <unistd.h>
13 #include <sys/shm.h>
14 #include <errno.h>
15 #include "shmem.h"
16
17 using namespace std;
18
19 /**
20  * Notify other users of a shared-memory chunk that the leader has
21  * finished initializing it.
22  */
23 void notifySharedMem(void *mem, size_t len) {
24         ((volatile uint32_t*)((char*)mem + len))[0] = SHMEM_INIT;
25 }
26
27 /**
28  * Wait until the leader of a shared-memory chunk has finished
29  * initializing it.
30  */
31 void waitSharedMem(void *mem, size_t len) {
32         while(((volatile uint32_t*)((char*)mem + len))[0] != SHMEM_INIT) {
33                 sleep(1);
34         }
35 }
36
37 #endif