smq_read.c
1 
27 #include <unistd.h> /* for usleep() */
28 #include <signal.h> /* for signal() */
29 #include <shm_arena.h> /* for Shared Memory Arena Library */
30 
31 static int running = 1;
32 
33 static void catcher(int sig)
34 {
35  printf("catch signal %d\n", sig);
36  running = 0;
37 }
38 
39 int main(void)
40 {
41  smq_t q;
42 
43  signal(SIGINT, catcher);
44 
45  q = smq_get(NULL, sizeof(int), 20, "q_count", O_CREAT);
46  if(!q)
47  {
48  printf("smq_get() failed\n");
49  return 1;
50  }
51 
52  while(running)
53  {
54  int num;
55 
56  num = smq_rdlock(q, 0);
57 
58  while(num > 0)
59  {
60  int *ptr;
61  ptr = smq_read(q);
62  printf("%d ", *ptr);
63  fflush(stdout);
64  num--;
65  }
66 
67  smq_unlock(q);
68 
69  sleep(1);
70  }
71 
72  return 0;
73 }
smq_t smq_get(shm_arena_t arena, size_t element_size, int q_length, const char *name, int flags)
get a Shared Multi-Queue object
Definition: smq.c:358
int smq_rdlock(smq_t q, int num)
acquire Shared Multi-Queue read-lock
Definition: smq.c:881
struct smq * smq_t
shared multi-queue object
Definition: shm_arena.h:196
int smq_unlock(smq_t q)
release Shared Multi-Queue read or write lock
Definition: smq.c:1102
void * smq_read(smq_t q)
read the next entry from the Shared Multi-Queue
Definition: smq.c:1262

Shared Memory Arena version RC-0.0.25