Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zmap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
zmap
Commits
c80be97a
Commit
c80be97a
authored
21 years ago
by
edgrif
Browse files
Options
Downloads
Patches
Plain Diff
Sort out debug messages. Sort out passing data via condvar.
parent
0cd9f3ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/zmapThreads/zmapConnutils.c
+62
-37
62 additions, 37 deletions
src/zmapThreads/zmapConnutils.c
with
62 additions
and
37 deletions
src/zmapThreads/zmapConnutils.c
+
62
−
37
View file @
c80be97a
...
...
@@ -26,13 +26,14 @@
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited: Mar
1 14:
26
2004 (edgrif)
* Last edited: Mar 1
2
14:
31
2004 (edgrif)
* Created: Thu Jul 24 14:37:35 2003 (edgrif)
* CVS info: $Id: zmapConnutils.c,v 1.
3
2004-03-
03 12:06:2
7 edgrif Exp $
* CVS info: $Id: zmapConnutils.c,v 1.
4
2004-03-
12 15:58:1
7 edgrif Exp $
*-------------------------------------------------------------------
*/
#include
<errno.h>
#include
<ZMap/zmapUtils.h>
#include
<zmapConn_P.h>
...
...
@@ -47,20 +48,21 @@ void zmapCondVarCreate(ZMapRequest thread_state)
if
((
status
=
pthread_mutex_init
(
&
(
thread_state
->
mutex
),
NULL
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"mutex init"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"mutex init"
)
;
}
if
((
status
=
pthread_cond_init
(
&
(
thread_state
->
cond
),
NULL
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"cond init"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"cond init"
)
;
}
thread_state
->
state
=
ZMAP_REQUEST_INIT
;
thread_state
->
data
=
NULL
;
return
;
}
void
zmapCondVarSignal
(
ZMapRequest
thread_state
,
ZMapThreadRequest
new_state
)
void
zmapCondVarSignal
(
ZMapRequest
thread_state
,
ZMapThreadRequest
new_state
,
gchar
*
data
)
{
int
status
;
...
...
@@ -68,19 +70,23 @@ void zmapCondVarSignal(ZMapRequest thread_state, ZMapThreadRequest new_state)
if
((
status
=
pthread_mutex_lock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarSignal mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarSignal mutex lock"
)
;
}
thread_state
->
state
=
new_state
;
/* For some requests there will be no data. */
if
(
data
)
thread_state
->
data
=
data
;
if
((
status
=
pthread_cond_signal
(
&
(
thread_state
->
cond
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarSignal cond signal"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarSignal cond signal"
)
;
}
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarSignal mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarSignal mutex unlock"
)
;
}
pthread_cleanup_pop
(
0
)
;
/* 0 => only call cleanup if cancelled. */
...
...
@@ -98,20 +104,20 @@ void zmapCondVarWait(ZMapRequest thread_state, ZMapThreadRequest waiting_state)
if
((
status
=
pthread_mutex_lock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarWait mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait mutex lock"
)
;
}
while
(
thread_state
->
state
==
waiting_state
)
{
if
((
status
=
pthread_cond_wait
(
&
(
thread_state
->
cond
),
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarWait cond wait"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait cond wait"
)
;
}
}
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarWait mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait mutex unlock"
)
;
}
pthread_cleanup_pop
(
0
)
;
/* 0 => only call cleanup if cancelled. */
...
...
@@ -127,30 +133,29 @@ void zmapCondVarWait(ZMapRequest thread_state, ZMapThreadRequest waiting_state)
* something has changed from the waiting state...i.e. somehow you need to return to the
* waiting state before looping again. */
ZMapThreadRequest
zmapCondVarWaitTimed
(
ZMapRequest
condvar
,
ZMapThreadRequest
waiting_state
,
TIMESPEC
*
relative_timeout
,
gboolean
reset_to_waiting
)
TIMESPEC
*
relative_timeout
,
gboolean
reset_to_waiting
,
char
**
data_out
)
{
ZMapThreadRequest
signalled_state
=
ZMAP_REQUEST_INIT
;
int
status
;
TIMESPEC
abs_timeout
;
pthread_cleanup_push
(
releaseCondvarMutex
,
(
void
*
)
condvar
)
;
if
((
status
=
pthread_mutex_lock
(
&
(
condvar
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarWait mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait mutex lock"
)
;
}
/* Get the relative timeout converted to absolute for the call. */
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
if
((
status
=
pthread_get_expiration_np
(
relative_timeout
,
&
abs_timeout
))
!=
0
)
ZMAPSYSERR
(
status
,
"zmapCondVarWaitTimed invalid time"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWaitTimed invalid time"
)
;
#endif
/* ED_G_NEVER_INCLUDE_THIS_CODE */
if
((
status
=
getAbsTime
(
relative_timeout
,
&
abs_timeout
))
!=
0
)
ZMAPSYSERR
(
status
,
"zmapCondVarWaitTimed invalid time"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWaitTimed invalid time"
)
;
while
(
condvar
->
state
==
waiting_state
)
{
...
...
@@ -163,7 +168,7 @@ ZMapThreadRequest zmapCondVarWaitTimed(ZMapRequest condvar, ZMapThreadRequest wa
break
;
}
else
ZMAPSYSERR
(
status
,
"zmapCondVarWait cond wait"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait cond wait"
)
;
}
}
...
...
@@ -173,13 +178,25 @@ ZMapThreadRequest zmapCondVarWaitTimed(ZMapRequest condvar, ZMapThreadRequest wa
if
(
reset_to_waiting
)
condvar
->
state
=
waiting_state
;
/* Return data if there is some, seems to make sense only to do this if we _haven't_ timed out.
* Note how we reset condvar->data so we detect if new data comes in next time. */
if
(
condvar
->
state
!=
ZMAP_REQUEST_TIMED_OUT
)
{
if
(
condvar
->
data
)
{
*
data_out
=
condvar
->
data
;
condvar
->
data
=
NULL
;
}
}
if
((
status
=
pthread_mutex_unlock
(
&
(
condvar
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapCondVarWait mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapCondVarWait mutex unlock"
)
;
}
pthread_cleanup_pop
(
0
)
;
/* 0 => only call cleanup if cancelled. */
return
signalled_state
;
}
...
...
@@ -190,13 +207,13 @@ void zmapCondVarDestroy(ZMapRequest thread_state)
if
((
status
=
pthread_cond_destroy
(
&
(
thread_state
->
cond
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"cond destroy"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"cond destroy"
)
;
}
if
((
status
=
pthread_mutex_destroy
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"mutex destroy"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"mutex destroy"
)
;
}
return
;
...
...
@@ -213,7 +230,7 @@ void zmapVarCreate(ZMapReply thread_state)
if
((
status
=
pthread_mutex_init
(
&
(
thread_state
->
mutex
),
NULL
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"mutex init"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"mutex init"
)
;
}
thread_state
->
state
=
ZMAP_REPLY_INIT
;
...
...
@@ -229,14 +246,14 @@ void zmapVarSetValue(ZMapReply thread_state, ZMapThreadReply new_state)
if
((
status
=
pthread_mutex_lock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValue mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValue mutex lock"
)
;
}
thread_state
->
state
=
new_state
;
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValue mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValue mutex unlock"
)
;
}
return
;
...
...
@@ -256,7 +273,7 @@ gboolean zmapVarGetValue(ZMapReply thread_state, ZMapThreadReply *state_out)
if
(
status
==
EBUSY
)
unlocked
=
FALSE
;
else
ZMAPSYSERR
(
status
,
"zmapVarGetValue mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarGetValue mutex lock"
)
;
}
else
{
...
...
@@ -265,7 +282,7 @@ gboolean zmapVarGetValue(ZMapReply thread_state, ZMapThreadReply *state_out)
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarGetValue mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarGetValue mutex unlock"
)
;
}
}
...
...
@@ -279,7 +296,7 @@ void zmapVarSetValueWithData(ZMapReply thread_state, ZMapThreadReply new_state,
if
((
status
=
pthread_mutex_lock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValueWithData mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValueWithData mutex lock"
)
;
}
thread_state
->
state
=
new_state
;
...
...
@@ -287,7 +304,7 @@ void zmapVarSetValueWithData(ZMapReply thread_state, ZMapThreadReply new_state,
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValueWithData mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValueWithData mutex unlock"
)
;
}
return
;
...
...
@@ -300,15 +317,17 @@ void zmapVarSetValueWithError(ZMapReply thread_state, ZMapThreadReply new_state,
if
((
status
=
pthread_mutex_lock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValueWithError mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValueWithError mutex lock"
)
;
}
thread_state
->
state
=
new_state
;
thread_state
->
error_msg
=
err_msg
;
if
(
err_msg
)
thread_state
->
error_msg
=
err_msg
;
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarSetValueWithError mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarSetValueWithError mutex unlock"
)
;
}
return
;
...
...
@@ -330,21 +349,27 @@ gboolean zmapVarGetValueWithData(ZMapReply thread_state, ZMapThreadReply *state_
if
(
status
==
EBUSY
)
unlocked
=
FALSE
;
else
ZMAPSYSERR
(
status
,
"zmapVarGetValue mutex lock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarGetValue mutex lock"
)
;
}
else
{
*
state_out
=
thread_state
->
state
;
if
(
thread_state
->
data
)
*
data_out
=
thread_state
->
data
;
{
*
data_out
=
thread_state
->
data
;
thread_state
->
data
=
NULL
;
}
if
(
thread_state
->
error_msg
)
*
err_msg_out
=
thread_state
->
error_msg
;
{
*
err_msg_out
=
thread_state
->
error_msg
;
thread_state
->
error_msg
=
NULL
;
}
unlocked
=
TRUE
;
if
((
status
=
pthread_mutex_unlock
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"zmapVarGetValue mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"zmapVarGetValue mutex unlock"
)
;
}
}
...
...
@@ -358,7 +383,7 @@ void zmapVarDestroy(ZMapReply thread_state)
if
((
status
=
pthread_mutex_destroy
(
&
(
thread_state
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"mutex destroy"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"mutex destroy"
)
;
}
return
;
...
...
@@ -383,7 +408,7 @@ static void releaseCondvarMutex(void *thread_data)
if
((
status
=
pthread_mutex_unlock
(
&
(
condvar
->
mutex
)))
!=
0
)
{
ZMAPSYSERR
(
status
,
"releaseCondvarMutex cleanup handler - mutex unlock"
)
;
ZMAP
FATAL
SYSERR
(
status
,
"%s"
,
"releaseCondvarMutex cleanup handler - mutex unlock"
)
;
}
return
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment