Skip to content

Commit

Permalink
Ensure the cache rwlock can be used across processes
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Parlane <[email protected]>
  • Loading branch information
carlgsmith authored and sparlane committed Dec 16, 2014
1 parent 177573f commit 273dd22
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void
cache_init (void)
{
int already_init = 0;
pthread_rwlockattr_t attr;
int length;
int shmid;

Expand Down Expand Up @@ -92,8 +93,11 @@ cache_init (void)
/* Initialise the cache */
cache->shmid = 0;
cache->length = length;
pthread_rwlock_init (&cache->rwlock, NULL);
pthread_rwlockattr_init (&attr);
pthread_rwlockattr_setpshared (&attr, PTHREAD_PROCESS_SHARED);
pthread_rwlock_init (&cache->rwlock, &attr);
pthread_rwlock_wrlock (&cache->rwlock);
pthread_rwlockattr_destroy (&attr);
sem_init (&cache->ref, 1, 1);
memset (cache->table, 0, NUM_BUCKETS * sizeof (hash_entry_t));
cache->shmid = shmid;
Expand Down

0 comments on commit 273dd22

Please sign in to comment.