Fix ovni_thread_isready() after ovni_thread_free()
Until now, the value returned by ovni_thread_isready() was still non-zero when the thread stream was destroyed in ovni_thread_free() This was making it impossible to detect when a stream was destroyed. This change makes it return 0 after ovni_thread_free() by using a new finished flag. The flag keeps track on then the stream is destroyed, preventing double initialization of a free stream.
This commit is contained in:
parent
75833f5e21
commit
0439399f05
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Calling `ovni_thread_isready()` after `ovni_thread_free()` now returns 0.
|
||||||
|
|
||||||
## [1.5.0] - 2023-12-15
|
## [1.5.0] - 2023-12-15
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -26,6 +26,7 @@ struct ovni_rthread {
|
|||||||
int streamfd;
|
int streamfd;
|
||||||
|
|
||||||
int ready;
|
int ready;
|
||||||
|
int finished;
|
||||||
|
|
||||||
/* The number of bytes filled with events */
|
/* The number of bytes filled with events */
|
||||||
size_t evlen;
|
size_t evlen;
|
||||||
@ -552,6 +553,9 @@ ovni_thread_init(pid_t tid)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rthread.finished)
|
||||||
|
die("thread %d has finished, cannot init again", tid);
|
||||||
|
|
||||||
if (tid == 0)
|
if (tid == 0)
|
||||||
die("cannot use tid=%d", tid);
|
die("cannot use tid=%d", tid);
|
||||||
|
|
||||||
@ -578,6 +582,9 @@ ovni_thread_init(pid_t tid)
|
|||||||
void
|
void
|
||||||
ovni_thread_free(void)
|
ovni_thread_free(void)
|
||||||
{
|
{
|
||||||
|
if (rthread.finished)
|
||||||
|
die("thread already finished");
|
||||||
|
|
||||||
if (!rthread.ready)
|
if (!rthread.ready)
|
||||||
die("thread not initialized");
|
die("thread not initialized");
|
||||||
|
|
||||||
@ -597,6 +604,9 @@ ovni_thread_free(void)
|
|||||||
|
|
||||||
close(rthread.streamfd);
|
close(rthread.streamfd);
|
||||||
rthread.streamfd = -1;
|
rthread.streamfd = -1;
|
||||||
|
|
||||||
|
rthread.ready = 0;
|
||||||
|
rthread.finished = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -22,6 +22,7 @@ test_emu(require-bad-version.c SHOULD_FAIL REGEX "unsupported ovni model version
|
|||||||
test_emu(require-compat.c REGEX "loading trace in compatibility mode")
|
test_emu(require-compat.c REGEX "loading trace in compatibility mode")
|
||||||
test_emu(require-repeated.c)
|
test_emu(require-repeated.c)
|
||||||
test_emu(thread-crash.c SHOULD_FAIL REGEX "incomplete stream")
|
test_emu(thread-crash.c SHOULD_FAIL REGEX "incomplete stream")
|
||||||
|
test_emu(thread-free-isready.c)
|
||||||
test_emu(flush-tmpdir.c MP DRIVER "flush-tmpdir.driver.sh")
|
test_emu(flush-tmpdir.c MP DRIVER "flush-tmpdir.driver.sh")
|
||||||
test_emu(tmpdir-metadata.c MP DRIVER "tmpdir-metadata.driver.sh")
|
test_emu(tmpdir-metadata.c MP DRIVER "tmpdir-metadata.driver.sh")
|
||||||
test_emu(dummy.c NAME "ovniver" DRIVER "ovniver.driver.sh")
|
test_emu(dummy.c NAME "ovniver" DRIVER "ovniver.driver.sh")
|
||||||
|
27
test/emu/ovni/thread-free-isready.c
Normal file
27
test/emu/ovni/thread-free-isready.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* Copyright (c) 2023 Barcelona Supercomputing Center (BSC)
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||||
|
|
||||||
|
#include <ovni.h>
|
||||||
|
#include "instr.h"
|
||||||
|
|
||||||
|
/* Check the behavior of ovni_thread_isready(), which should only be 1
|
||||||
|
* after ovni_thread_init() and before ovni_thread_free(). */
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
if (ovni_thread_isready())
|
||||||
|
die("thread must not be ready before init");
|
||||||
|
|
||||||
|
instr_start(0, 1);
|
||||||
|
|
||||||
|
if (!ovni_thread_isready())
|
||||||
|
die("thread must be ready after init");
|
||||||
|
|
||||||
|
instr_end();
|
||||||
|
|
||||||
|
if (ovni_thread_isready())
|
||||||
|
die("thread must not be ready after free");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user