Redmine #5337: Dlsym thread safety fix and optimizations.

<pre>
commit b2996e4591be78f3835b766b79d328e497e3093a
Author: Kristian Amlie <kristian.amlie@cfengine.com>
Date:   Wed Apr 2 09:26:44 2014

    Redmine #5337: Optimize by caching calls to dlsym().
    
    - Introduce static function pointer which we save between calls.
    
    - Thread safety is not needed, since even if two threads try to write
      to the function pointer simultaneously, both will write the same
      value.
    
    - The old stub code is inline, so we cannot use a static variable
      there. Fixed my moving the stub code into the stub macro instead,
      where it doesn't need to be inline.

commit 2ee488008a8f147eafe0c9da64ba902682327539
Author: Kristian Amlie <kristian.amlie@cfengine.com>
Date:   Wed Apr 2 09:25:18 2014

    Redmine #5337: Fix sporadic deadlock in dlsym().
    
    Apparently dlsym() is not threadsafe, so we need to protect it with a
    mutex.

commit a7814dfa31fb41327d4d735a6deea548ff4f6a31
Author: Kristian Amlie <kristian.amlie@cfengine.com>
Date:   Tue Apr 1 15:33:19 2014

    Fix incorrect extension stub definition.
</pre>