Back to index

glibc  2.9
Functions
pthread_key_create.c File Reference
#include <errno.h>
#include "pthreadP.h"
#include <atomic.h>

Go to the source code of this file.

Functions

int __pthread_key_create (pthread_key_t *key, void(*)(void *) destr)

Function Documentation

int __pthread_key_create ( pthread_key_t key,
void (*) (void *)  destr 
)

Definition at line 26 of file pthread_key_create.c.

{
  /* Find a slot in __pthread_kyes which is unused.  */
  for (size_t cnt = 0; cnt < PTHREAD_KEYS_MAX; ++cnt)
    {
      uintptr_t seq = __pthread_keys[cnt].seq;

      if (KEY_UNUSED (seq) && KEY_USABLE (seq)
         /* We found an unused slot.  Try to allocate it.  */
         && ! atomic_compare_and_exchange_bool_acq (&__pthread_keys[cnt].seq,
                                               seq + 1, seq))
       {
         /* Remember the destructor.  */
         __pthread_keys[cnt].destr = destr;

         /* Return the key to the caller.  */
         *key = cnt;

         /* The call succeeded.  */
         return 0;
       }
    }

  return EAGAIN;
}

Here is the call graph for this function: