1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
--- ./src/sphinxstd.cpp.orig 2012-11-28 21:23:23.177922214 +0000
+++ ./src/sphinxstd.cpp 2012-11-28 21:23:34.961920201 +0000
@@ -1,5 +1,5 @@
//
-// $Id: sphinxstd.cpp 3445 2012-10-12 10:45:41Z kevg $
+// $Id$
//
//
@@ -737,6 +737,24 @@
{
m_pMutex = NULL;
+#ifdef __FreeBSD__
+ CSphString sError, sWarning;
+ if ( !m_pStorage.Alloc ( sizeof(sem_t) + iExtraSize, sError, sWarning ) )
+ {
+ m_sError.SetSprintf ( "storage.alloc, error='%s', warning='%s'", sError.cstr(), sWarning.cstr() );
+ return;
+ }
+
+ m_pMutex = (sem_t*) m_pStorage.GetWritePtr ();
+ int iRes = sem_init ( m_pMutex, 1, 1 );
+ if ( iRes )
+ {
+ m_sError.SetSprintf ( "sem_init, errno=%d ", iRes );
+ m_pMutex = NULL;
+ m_pStorage.Reset ();
+ return;
+ }
+#else
pthread_mutexattr_t tAttr;
int iRes = pthread_mutexattr_init ( &tAttr );
if ( iRes )
@@ -767,6 +785,7 @@
m_pStorage.Reset ();
return;
}
+#endif // __FreeBSD__
}
#else
CSphProcessSharedMutex::CSphProcessSharedMutex ( int )
@@ -777,18 +796,28 @@
void CSphProcessSharedMutex::Lock () const
{
#if !USE_WINDOWS
+#ifdef __FreeBSD__
+ if ( m_pMutex )
+ sem_wait ( m_pMutex );
+#else
if ( m_pMutex )
pthread_mutex_lock ( m_pMutex );
#endif
+#endif
}
void CSphProcessSharedMutex::Unlock () const
{
#if !USE_WINDOWS
+#ifdef __FreeBSD__
+ if ( m_pMutex )
+ sem_post ( m_pMutex );
+#else
if ( m_pMutex )
pthread_mutex_unlock ( m_pMutex );
#endif
+#endif
}
@@ -802,6 +831,20 @@
if ( !m_pMutex )
return false;
+#ifdef __FreeBSD__
+ struct timespec tp;
+ clock_gettime ( CLOCK_REALTIME, &tp );
+
+ tp.tv_nsec += tmSpin * 1000;
+ if ( tp.tv_nsec > 1000000 )
+ {
+ int iDelta = (int)( tp.tv_nsec / 1000000 );
+ tp.tv_sec += iDelta * 1000000;
+ tp.tv_nsec -= iDelta * 1000000;
+ }
+
+ return ( sem_timedwait ( m_pMutex, &tp )==0 );
+#else
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(HAVE_CLOCK_GETTIME)
struct timespec tp;
clock_gettime ( CLOCK_REALTIME, &tp );
@@ -830,6 +873,7 @@
return iRes==0;
#endif // HAVE_PTHREAD_MUTEX_TIMEDLOCK && HAVE_CLOCK_GETTIME
+#endif // __FreeBSD__
#endif // USE_WINDOWS
}
@@ -1338,5 +1382,5 @@
#endif
//
-// $Id: sphinxstd.cpp 3445 2012-10-12 10:45:41Z kevg $
+// $Id$
//
|