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
ac175a27
Commit
ac175a27
authored
21 years ago
by
edgrif
Browse files
Options
Downloads
Patches
Plain Diff
Add more error handling code to thread creation code.
Update routines to stringify request/raply enums.
parent
3715a4f3
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/zmapConn.c
+88
-21
88 additions, 21 deletions
src/zmapThreads/zmapConn.c
with
88 additions
and
21 deletions
src/zmapThreads/zmapConn.c
+
88
−
21
View file @
ac175a27
...
...
@@ -26,19 +26,21 @@
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited:
Jan 22 13:52
2004 (edgrif)
* Last edited:
Mar 2 10:39
2004 (edgrif)
* Created: Thu Jul 24 14:37:18 2003 (edgrif)
* CVS info: $Id: zmapConn.c,v 1.
2
2004-0
1-23 13:27:53
edgrif Exp $
* CVS info: $Id: zmapConn.c,v 1.
3
2004-0
3-03 12:04:18
edgrif Exp $
*-------------------------------------------------------------------
*/
#include
<string.h>
#include
<zmapConn_P.h>
/* Turn on/off all debugging messages for threads. */
gboolean
zmap_thr_debug_G
=
TRUE
;
static
ZMapConnection
createConnection
(
char
*
machine
,
char
*
port
,
char
*
protocol
,
char
*
sequence
)
;
static
void
destroyConnection
(
ZMapConnection
connection
)
;
ZMapConnection
zMapConnCreate
(
char
*
machine
,
char
*
port
,
char
*
protocol
,
char
*
sequence
)
...
...
@@ -46,50 +48,59 @@ ZMapConnection zMapConnCreate(char *machine, char *port, char *protocol, char *s
ZMapConnection
connection
;
pthread_t
thread_id
;
pthread_attr_t
thread_attr
;
int
status
;
connection
=
g_new
(
ZMapConnectionStruct
,
sizeof
(
ZMapConnectionStruct
))
;
int
status
=
0
;
connection
->
machine
=
g_strdup
(
machine
)
;
connection
->
port
=
atoi
(
port
)
;
connection
->
protocol
=
g_strdup
(
protocol
)
;
connection
->
sequence
=
g_strdup
(
sequence
)
;
connection
=
createConnection
(
machine
,
port
,
protocol
,
sequence
)
;
/* ok to just set state here because we have not started the thread yet.... */
zmapCondVarCreate
(
&
(
connection
->
request
))
;
connection
->
request
.
state
=
ZMAP_REQUEST_WAIT
;
zmapVarCreate
(
&
(
connection
->
reply
))
;
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
connection
->
reply
.
state
=
ZMAP_REPLY_INIT
;
#endif
/* ED_G_NEVER_INCLUDE_THIS_CODE */
connection
->
reply
.
state
=
ZMAP_REPLY_WAIT
;
/* Set the new threads attributes so it will run "detached", we do not want anything from them.
* when they die, we want them to go away and release their resources. */
if
((
status
=
pthread_attr_init
(
&
thread_attr
))
!=
0
)
if
(
status
==
0
&&
(
status
=
pthread_attr_init
(
&
thread_attr
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"Create thread attibutes"
)
;
}
if
((
status
=
pthread_attr_setdetachstate
(
&
thread_attr
,
PTHREAD_CREATE_DETACHED
))
!=
0
)
if
(
status
==
0
&&
(
status
=
pthread_attr_setdetachstate
(
&
thread_attr
,
PTHREAD_CREATE_DETACHED
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"Set thread detached attibute"
)
;
}
/* Create the new thread. */
if
((
status
=
pthread_create
(
&
thread_id
,
&
thread_attr
,
zmapNewThread
,
(
void
*
)
connection
))
!=
0
)
if
(
status
==
0
&&
(
status
=
pthread_create
(
&
thread_id
,
&
thread_attr
,
zmapNewThread
,
(
void
*
)
connection
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"Thread creation"
)
;
}
connection
->
thread_id
=
thread_id
;
if
(
status
==
0
)
connection
->
thread_id
=
thread_id
;
else
{
/* Ok to just destroy connection here as the thread was not successfully created so
* there can be no complications with interactions with condvars in connect struct. */
destroyConnection
(
connection
)
;
connection
=
NULL
;
}
return
connection
;
}
void
zMapConnLoadData
(
ZMapConnection
connection
)
{
zmapCondVarSignal
(
&
connection
->
request
,
ZMAP_REQUEST_GETDATA
)
;
...
...
@@ -129,13 +140,33 @@ gboolean zMapConnGetReplyWithData(ZMapConnection connection, ZMapThreadReply *st
void
*
zMapConnGetThreadid
(
ZMapConnection
connection
)
{
return
(
void
*
)(
connection
->
thread_id
)
;
}
/* Must be kept in step with declaration of ZMapThreadRequest enums in zmapConn_P.h */
char
*
zMapVarGetRequestString
(
ZMapThreadRequest
signalled_state
)
{
char
*
str_states
[]
=
{
"ZMAP_REQUEST_INIT"
,
"ZMAP_REQUEST_WAIT"
,
"ZMAP_REQUEST_TIMED_OUT"
,
"ZMAP_REQUEST_GETDATA"
}
;
return
str_states
[
signalled_state
]
;
}
/* Must be kept in step with declaration of ZMapThreadReply enums in zmapConn_P.h */
char
*
zMapVarGetReplyString
(
ZMapThreadReply
signalled_state
)
{
char
*
str_states
[]
=
{
"ZMAP_REPLY_INIT"
,
"ZMAP_REPLY_WAIT"
,
"ZMAP_REPLY_GOTDATA"
,
"ZMAP_REPLY_DIED"
,
"ZMAP_REPLY_CANCELLED"
}
;
return
str_states
[
signalled_state
]
;
}
/* Kill the thread by cancelling it, as this will asynchronously we cannot release the connections
* resources in this call. */
void
zMapConnKill
(
ZMapConnection
connection
)
...
...
@@ -144,10 +175,10 @@ void zMapConnKill(ZMapConnection connection)
ZMAP_THR_DEBUG
((
"GUI: killing and destroying connection for thread %x
\n
"
,
connection
->
thread_id
))
;
/* Really we should signal an exit here...but that lead to deadlocks, think about this bit.. */
/* we could signal an exit here by setting a condvar of EXIT...but that might lead to
* deadlocks, think about this bit.. */
/* Signal the thread to cancel it, we could set a cond var of EXIT but this will take ages
* for the thread to be cancelled. */
/* Signal the thread to cancel it */
if
((
status
=
pthread_cancel
(
connection
->
thread_id
))
!=
0
)
{
ZMAPSYSERR
(
status
,
"Thread cancel"
)
;
...
...
@@ -182,3 +213,39 @@ void zMapConnDestroy(ZMapConnection connection)
* --------------------- Internal routines ------------------------------
*/
static
ZMapConnection
createConnection
(
char
*
machine
,
char
*
port
,
char
*
protocol
,
char
*
sequence
)
{
ZMapConnection
connection
;
connection
=
g_new
(
ZMapConnectionStruct
,
sizeof
(
ZMapConnectionStruct
))
;
connection
->
machine
=
g_strdup
(
machine
)
;
connection
->
port
=
atoi
(
port
)
;
connection
->
protocol
=
g_strdup
(
protocol
)
;
connection
->
sequence
=
g_strdup
(
sequence
)
;
return
connection
;
}
/* some care needed in using this....what about the condvars, when can they be freed ?
* CHECK THIS ALL WORKS.... */
static
void
destroyConnection
(
ZMapConnection
connection
)
{
g_free
(
connection
->
machine
)
;
g_free
(
connection
->
protocol
)
;
g_free
(
connection
->
sequence
)
;
/* Setting this to zero prevents subtle bugs where calling code continues
* to try to reuse a defunct control block. */
/* Should crash if this returns NULL, need my macros from acedb code.... */
memset
((
void
*
)
connection
,
0
,
sizeof
(
ZMapConnectionStruct
))
;
g_free
(
connection
)
;
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