I've been looking at some of the source code for glibc, in particular the nptl code, and I've found it a little bit hard to understand since it seems to have conventions that I'm not familiar with.
For example I was looking at a very small file pthread_equal.c and there are a few things that I had questions about:
22 int
23 __pthread_equal (thread1, thread2)
24 pthread_t thread1;
25 pthread_t thread2;
26 {
27 return thread1 == thread2;
28 }
29 strong_alias (__pthread_equal, pthread_equal)
The declaration on lines 22 and 23 looks like something I understand. It has a return type of
int
then the function name__pthread_equal
and the parameter list(thread1, thread2)
. But what are the declarations on lines 24pthread_t thread1;
and 25pthread_t thread2;
for? It looks like these are being declared as global variables but I don't understand the purpose. I've seen this pattern in many files in the nptl directory and haven't been able to figure out why this is done.What is
strong_alias
? A quick Google search has examples of this being used but I did not find a link to any documentation.What is the reason for prefacing some names with two underscores
__
and some with one underscore_
. Most of the code I've seen uses the two underscores but I think I have seen some places where one underscore is used. For instance in pthreadP.h556 /* Old cleanup interfaces, still used in libc.so. */ 557 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, 558 void (*routine) (void *), void *arg); 559 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, 560 int execute); 561 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, 562 void (*routine) (void *), void *arg); 563 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, 564 int execute);
Admittedly that code is prefaced with a comment that says "old cleanup interfaces" but either way I'm curious about the difference and why sometimes one underscore is used and sometimes two underscores are used.
Any information regarding these questions is appreciated.