MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / ketama_sem_init

Function ketama_sem_init

libCacheSim/dataStructure/ketama/ketama.c:161–189  ·  view source on GitHub ↗

\brief Initialize a semaphore. * \param key Semaphore key to use. * \return The freshly allocated semaphore handle. */

Source from the content-addressed store, hash-verified

159 * \param key Semaphore key to use.
160 * \return The freshly allocated semaphore handle. */
161static int
162ketama_sem_init( key_t key )
163{
164 if (sem_ids == NULL) {
165 init_sem_id_tracker();
166 }
167
168 int sem_set_id;
169
170 sem_set_id = semget( key, 1, 0 );
171 track_sem_id(sem_set_id);
172
173 if ( sem_set_id == -1 )
174 {
175 // create a semaphore set with ID SEM_ID
176 sem_set_id = semget( key, 1, IPC_CREAT | 0666 );
177 track_sem_id(sem_set_id);
178
179 if ( sem_set_id == -1 )
180 {
181 strcpy( k_error, "Could not open semaphore!" );
182 return 0;
183 }
184
185 ketama_sem_unlock( sem_set_id );
186 }
187
188 return sem_set_id;
189}
190
191
192/* ketama.h does not expose this function */

Callers 1

ketama_rollFunction · 0.70

Calls 3

init_sem_id_trackerFunction · 0.70
track_sem_idFunction · 0.70
ketama_sem_unlockFunction · 0.70

Tested by

no test coverage detected