From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02517.html | 280 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 docs/doxygen/nel/a02517.html (limited to 'docs/doxygen/nel/a02517.html') diff --git a/docs/doxygen/nel/a02517.html b/docs/doxygen/nel/a02517.html new file mode 100644 index 00000000..c9a0848d --- /dev/null +++ b/docs/doxygen/nel/a02517.html @@ -0,0 +1,280 @@ + + +NeL: NLMISC::CFastMutexMP class Reference + + + +
+

NLMISC::CFastMutexMP Class Reference

#include <mutex.h> +

+


Detailed Description

+Fast mutex for multiprocessor implementation (not fairly). Used for multiprocessor critical section synchronisation. The mutex ARE NOT recursive (ie don't call enter() several times on the same mutex from the same thread without having called leave()) ; The threads use a spin system to wait a little time before be put to sleep. It waits using CPU time.

+Implementation notes:

+

+

CFastMutexMP m; + m.enter (); + // do critical stuffs + m.leave (); + * +
Author:
Cyril 'Hulud' Corvazier

+Olivier Cado

+Nevrax France

+
Date:
2002, 2003
+ +

+ +

+Definition at line 309 of file mutex.h. + + + + + + + + + + + + + + + +

Public Member Functions

 CFastMutexMP ()
 Constructor.

__forceinline void enter () volatile
void init () volatile
 Same as constructor, useful for init in a shared memory block.

__forceinline void leave () volatile

Private Attributes

volatile uint32 _Lock
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NLMISC::CFastMutexMP::CFastMutexMP  )  [inline]
+
+ + + + + +
+   + + +

+Constructor. +

+ +

+Definition at line 314 of file mutex.h. +

+

00314 : _Lock(0) {}
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + +
__forceinline void NLMISC::CFastMutexMP::enter  )  volatile [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 320 of file mutex.h. +

+References uint. +

+

00321         {
+00322           //std::cout << "Entering, Lock=" << _Lock << std::endl; 
+00323                 while (CFastMutex::atomic_swap (&_Lock))
+00324                 {
+00325                         static uint last = 0;
+00326                         static uint _max = 30;
+00327                         uint spinMax = _max;
+00328                         uint lastSpins = last;
+00329                         volatile uint temp = 17;
+00330                         uint i;                 
+00331                         for (i = 0; i < spinMax; ++i) 
+00332                         {
+00333                                 if (i < lastSpins/2 || _Lock) 
+00334                                 {
+00335                                         temp *= temp; 
+00336                                         temp *= temp;
+00337                                         temp *= temp; 
+00338                                         temp *= temp;
+00339                                 }
+00340                                 else 
+00341                                 {
+00342                                         if (!CFastMutex::atomic_swap(&_Lock)) 
+00343                                         {
+00344                                                 last = i;
+00345                                                 _max = 1000;
+00346                                                 return;
+00347                                         }
+00348                                 }
+00349                         }
+00350 
+00351                         _max = 30;
+00352                         
+00353                         // First test
+00354                         for (i = 0 ;; ++i)
+00355                         {
+00356                                 uint wait_time = i + 6;
+00357                                 
+00358                                 // Increment wait time with a log function
+00359                                 if (wait_time > 27) 
+00360                                         wait_time = 27;
+00361                                 
+00362                                 // Sleep
+00363                                 if (wait_time <= 20) 
+00364                                         wait_time = 0;
+00365                                 else
+00366                                         wait_time = 1 << (wait_time - 20);
+00367                                 
+00368                                 if (!CFastMutex::atomic_swap (&_Lock))
+00369                                         break;
+00370 
+00371 #ifdef NL_OS_WINDOWS
+00372                                 Sleep (wait_time);
+00373 #else
+00374                                 //std::cout <<  "Sleeping i=" << i << std::endl;
+00375                                 usleep( wait_time*1000 );
+00376 #endif                          
+00377                         }
+00378                 }
+00379         }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CFastMutexMP::init void   )  volatile [inline]
+
+ + + + + +
+   + + +

+Same as constructor, useful for init in a shared memory block. +

+ +

+Definition at line 317 of file mutex.h. +

+

00317 { _Lock = 0; }
+
+

+ + + + +
+ + + + + + + + + +
__forceinline void NLMISC::CFastMutexMP::leave  )  volatile [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 382 of file mutex.h. +

+

00383         {
+00384                 _Lock = 0;
+00385                 //std::cout << "Leave" << std::endl;
+00386         }
+
+


Field Documentation

+

+ + + + +
+ + +
volatile uint32 NLMISC::CFastMutexMP::_Lock [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 389 of file mutex.h.

+


The documentation for this class was generated from the following file: +
Generated on Tue Mar 16 13:12:35 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1