smq_write.c
1 
26 #include <unistd.h> /* for usleep() */
27 #include <signal.h> /* for signal() */
28 #include <shm_arena.h> /* for Shared Memory Arena Library */
29 
30 static int running = 1;
31 
32 static void catcher(int sig)
33 {
34  printf("catch signal %d\n", sig);
35  running = 0;
36 }
37 
38 int main(void)
39 {
40  smq_t q;
41  int count = 0;
42  int *ptr;
43 
44  signal(SIGINT, catcher);
45 
46  q = smq_get(NULL, sizeof(int), 10, "q_count", O_CREAT);
47  if(!q)
48  {
49  printf("smq_get() failed\n");
50  return 1;
51  }
52 
53  while(running)
54  {
55  smq_wrlock(q, 0);
56  /* get the next entry to write */
57  ptr = smq_write(q);
58  /* write */
59  *ptr = count;
60  smq_unlock(q);
61 
62  count++;
63  usleep(100000); /* micro seconds */
64  }
65 
66  return 0;
67 }
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
void * smq_write(smq_t q)
write an entry into the Shared Multi-Queue
Definition: smq.c:1165
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
int smq_wrlock(smq_t q, int num)
acquire Shared Multi-Queue write-lock
Definition: smq.c:1073

Shared Memory Arena version RC-0.0.25