Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove OpenMP and unlocked stdio? #93

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{matrix.arch}}
set THTK_ARCH=${{matrix.arch}}
call C:\shells\msys2bash.cmd -c "pacman -S --noconfirm --needed --noprogressbar groff dos2unix zip"
call C:\shells\msys2bash.cmd -c "./make-release.sh ci"
- name: Upload Artifact
Expand Down
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ check_symbol_exists("scandir" "dirent.h" HAVE_SCANDIR)
check_symbol_exists("fstat" "sys/stat.h" HAVE_FSTAT)
check_symbol_exists("fileno" "stdio.h" HAVE_FILENO)

check_symbol_exists("getc_unlocked" "stdio.h" HAVE_GETC_UNLOCKED)
if(${HAVE_GETC_UNLOCKED})
check_symbol_exists("fread_unlocked" "stdio.h" HAVE_FREAD_UNLOCKED)
if(${HAVE_FREAD_UNLOCKED})
check_symbol_exists("feof_unlocked" "stdio.h" HAVE_FEOF_UNLOCKED)
endif()
else()
check_symbol_exists("_getc_nolock" "stdio.h" HAVE__GETC_NOLOCK)
if(${HAVE__GETC_NOLOCK})
check_symbol_exists("_fread_nolock" "stdio.h" HAVE__FREAD_NOLOCK)
endif()
endif()

set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

Expand Down
37 changes: 0 additions & 37 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,6 @@ typedef SSIZE_T ssize_t;
#cmakedefine HAVE_SCANDIR
#cmakedefine HAVE_FILENO

#cmakedefine HAVE_GETC_UNLOCKED
#cmakedefine HAVE_FREAD_UNLOCKED
#cmakedefine HAVE_FEOF_UNLOCKED
#cmakedefine HAVE__GETC_NOLOCK
#cmakedefine HAVE__FREAD_NOLOCK
#ifndef HAVE_GETC_UNLOCKED
# ifdef HAVE__GETC_NOLOCK
# define getc_unlocked _getc_nolock
# define putc_unlocked _putc_nolock
# else
# define getc_unlocked getc
# define putc_unlocked putc
# endif
#endif
#ifndef HAVE_FREAD_UNLOCKED
# ifdef HAVE__FREAD_NOLOCK
# define fread_unlocked _fread_nolock
# define fwrite_unlocked _fwrite_nolock
# else
# define fread_unlocked fread
# define fwrite_unlocked fwrite
# endif
#endif
/* feof and fileno don't lock in VCRT, and thus they don't have _nolock versions. */
#ifndef HAVE_FEOF_UNLOCKED
# define feof_unlocked feof
# if defined(HAVE_FILENO)
# define fileno_unlocked fileno
# endif
#endif
/* Our code shouldn't need to check these */
#undef HAVE_GETC_UNLOCKED
#undef HAVE_FREAD_UNLOCKED
#undef HAVE_FEOF_UNLOCKED
#undef HAVE__GETC_NOLOCK
#undef HAVE__FREAD_NOLOCK

#ifdef _WIN32
# define API_SYMBOL __declspec(dllexport)

Expand Down
1 change: 0 additions & 1 deletion make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ done
cp build/thtk/RelWithDebInfo/thtk.dll $releasepath/
cp build/thtk/RelWithDebInfo/thtk.lib $releasepath/
cp build/thtk/RelWithDebInfo/thtk.pdb $releasepath-pdbs/
cp "$(cygpath "$VCToolsRedistDir")/${THTK_ARCH:-x86}/Microsoft.VC143.OPENMP/vcomp140.dll" $releasepath/

copy_doc() {
while [ "$1" != "" ]; do
Expand Down
6 changes: 0 additions & 6 deletions thdat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
include_directories(${CMAKE_SOURCE_DIR})
add_executable(thdat thdat.c)
target_compile_options(thdat PRIVATE ${THTK_WARNING_FLAGS})
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
target_link_libraries(thdat thtk util)
link_setargv(thdat)
install(TARGETS thdat DESTINATION bin)
Expand Down
14 changes: 3 additions & 11 deletions thdat/thdat.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.\" Redistribution and use in source and binary forms, with
.\" or without modification, are permitted provided that the
.\" following conditions are met:
.\"
.\"
.\" 1. Redistributions of source code must retain this list
.\" of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce this
.\" list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the
.\" distribution.
.\"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
.\" CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
.\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -24,7 +24,7 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
.\" DAMAGE.
.Dd April 16, 2018
.Dd April 3, 2022
.Dt THDAT 1
.Os thtk
.Sh NAME
Expand Down Expand Up @@ -57,14 +57,6 @@ Running the program without a command will list the supported formats.
.No If Li d is specified instead of Ar version ,
.Nm
automatically detects the file format.
.Sh ENVIRONMENT
.Bl -tag -width OMP_NUM_THREADS
.It Ev OMP_NUM_THREADS
The number of threads to be used for compression and decompression.
The default used when
.Ev OMP_NUM_THREADS
is not set depends on the OpenMP implementation.
.El
.Sh EXIT STATUS
The
.Nm
Expand Down
32 changes: 12 additions & 20 deletions thdat/thdat.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,19 @@ thdat_list(

entries = malloc(entry_count * sizeof(*entries));

#pragma omp parallel /* reduction(max:name_width) */
{
#pragma omp for
for (e = 0; e < entry_count; ++e) {
thtk_error_t* error = NULL;
entries[e].name = thdat_entry_get_name(state->thdat, e, &error);
entries[e].size = thdat_entry_get_size(state->thdat, e, &error);
entries[e].zsize = thdat_entry_get_zsize(state->thdat, e, &error);
if (!entries[e].name || entries[e].size == -1 || entries[e].zsize == -1) {
print_error(error);
thtk_error_free(&error);
continue;
}
int entry_name_width = strlen(entries[e].name);
#pragma omp critical
if (entry_name_width > name_width)
name_width = entry_name_width;
for (e = 0; e < entry_count; ++e) {
thtk_error_t* error = NULL;
entries[e].name = thdat_entry_get_name(state->thdat, e, &error);
entries[e].size = thdat_entry_get_size(state->thdat, e, &error);
entries[e].zsize = thdat_entry_get_zsize(state->thdat, e, &error);
if (!entries[e].name || entries[e].size == -1 || entries[e].zsize == -1) {
print_error(error);
thtk_error_free(&error);
continue;
}
int entry_name_width = strlen(entries[e].name);
if (entry_name_width > name_width)
name_width = entry_name_width;
}

// th105: Stored = Size
Expand Down Expand Up @@ -270,7 +265,6 @@ thdat_create_wrapper(
k = 0;
/* TODO: Properly indicate when insertion fails. */
ssize_t i;
#pragma omp parallel for schedule(dynamic)
for (i = 0; i < real_entry_count; ++i) {
thtk_error_t* error = NULL;
thtk_io_t* entry_stream;
Expand Down Expand Up @@ -471,7 +465,6 @@ main(

if (argc > 1) {
ssize_t a;
#pragma omp parallel for schedule(dynamic)
for (a = 1; a < argc; ++a) {
thtk_error_t* error = NULL;
int entry_index;
Expand All @@ -497,7 +490,6 @@ main(
}

ssize_t entry_index;
#pragma omp parallel for schedule(dynamic)
for (entry_index = 0; entry_index < entry_count; ++entry_index) {
thtk_error_t* error = NULL;
if (!thdat_extract_file(state, entry_index, &error)) {
Expand Down
2 changes: 1 addition & 1 deletion thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/* TODO: Add some \r handling to the line counting stuff. */
#define YY_INPUT(buf,result,max_size) \
{ \
int c = getc_unlocked(yyin); \
int c = getc(yyin); \
if (c == EOF) { \
result = YY_NULL; \
} else { \
Expand Down
6 changes: 0 additions & 6 deletions thtk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ add_library(thtk SHARED

util.h thtk.h)
target_compile_options(thtk PRIVATE ${THTK_WARNING_FLAGS})
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
Expand Down
20 changes: 7 additions & 13 deletions thtk/thdat02.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ th02_read(
thdat_entry_t* entry = &thdat->entries[entry_index];
unsigned char* data;
ssize_t ret;
#pragma omp critical
{
data = thtk_io_map(thdat->stream, entry->offset, entry->zsize, error);
}
if (!data)

if (!(data = thtk_io_map(thdat->stream, entry->offset, entry->zsize, error)))
return -1;

for (ssize_t i = 0; i < entry->zsize; ++i)
Expand Down Expand Up @@ -208,16 +205,13 @@ th02_write(

ssize_t ret = -1;

#pragma omp critical
{
entry->offset = thtk_io_seek(thdat->stream, 0, SEEK_CUR, error);
entry->offset = thtk_io_seek(thdat->stream, 0, SEEK_CUR, error);

if (entry->offset != -1)
ret = thtk_io_write(thdat->stream, data, entry->zsize, error);
if (entry->offset != -1)
ret = thtk_io_write(thdat->stream, data, entry->zsize, error);

if (ret != -1)
thdat->offset += ret;
}
if (ret != -1)
thdat->offset += ret;

thtk_io_unmap(output, data);

Expand Down
22 changes: 6 additions & 16 deletions thtk/thdat06.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,8 @@ th06_read(
thdat_entry_t* entry = &thdat->entries[entry_index];
unsigned char* zdata = malloc(entry->zsize);

int failed;
#pragma omp critical
{
failed = (thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, zdata, entry->zsize, error) != entry->zsize);
}
if (failed)
if ((thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, zdata, entry->zsize, error) != entry->zsize))
return -1;

thtk_io_t* zdata_stream = thtk_io_open_memory(zdata, entry->zsize, error);
Expand All @@ -202,7 +197,7 @@ th06_read(
int ret = th_unlzss(zdata_stream, output, entry->size, error);

thtk_io_close(zdata_stream);

return ret;
}

Expand Down Expand Up @@ -247,14 +242,9 @@ th06_write(
entry->extra += zdata[i];
}

int ret;

#pragma omp critical
{
ret = thtk_io_write(thdat->stream, zdata, entry->zsize, error);
entry->offset = thdat->offset;
thdat->offset += entry->zsize;
}
int ret = thtk_io_write(thdat->stream, zdata, entry->zsize, error);
entry->offset = thdat->offset;
thdat->offset += entry->zsize;

thtk_io_unmap(zdata_stream, zdata);
thtk_io_close(zdata_stream);
Expand Down
21 changes: 6 additions & 15 deletions thtk/thdat08.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,8 @@ th08_read(
return -1;
unsigned char* zdata = malloc(entry->zsize);

int failed = 0;
#pragma omp critical
{
failed = (thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, zdata, entry->zsize, error) != entry->zsize);
}

if (failed)
if ((thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, zdata, entry->zsize, error) != entry->zsize))
return -1;

thtk_io_t* zdata_stream = thtk_io_open_memory(zdata, entry->zsize, error);
Expand Down Expand Up @@ -303,13 +297,10 @@ th08_write(
if (!zdata)
return -1;

#pragma omp critical
{
/* TODO: Handle error. */
thtk_io_write(thdat->stream, zdata, entry->zsize, error);
entry->offset = thdat->offset;
thdat->offset += entry->zsize;
}
/* TODO: Handle error. */
thtk_io_write(thdat->stream, zdata, entry->zsize, error);
entry->offset = thdat->offset;
thdat->offset += entry->zsize;

thtk_io_unmap(zdata_stream, zdata);
thtk_io_close(zdata_stream);
Expand Down
33 changes: 10 additions & 23 deletions thtk/thdat105.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ th105_read(
thdat_entry_t* entry = thdat->entries + entry_index;
unsigned char* data = malloc(entry->size);

int failed = 0;
#pragma omp critical
{
failed = (thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, data, entry->size, error) != entry->size);
}

if (failed)
if ((thtk_io_seek(thdat->stream, entry->offset, SEEK_SET, error) == -1) ||
(thtk_io_read(thdat->stream, data, entry->size, error) != entry->size))
return -1;

th105_decrypt_data(thdat, entry, data);
Expand Down Expand Up @@ -176,22 +170,15 @@ th105_write(

th105_encrypt_data(thdat, entry, data);

int failed = 0;
#pragma omp critical
{
failed = (thtk_io_write(thdat->stream, data, entry->size, error) != entry->size);
if (!failed) {
entry->offset = thdat->offset;
thdat->offset += entry->size;
}
}

free(data);

if (failed)
if (!(thtk_io_write(thdat->stream, data, entry->size, error) != entry->size)) {
entry->offset = thdat->offset;
thdat->offset += entry->size;
free(data);
return entry->size;
} else {
free(data);
return -1;

return entry->size;
}
}

static int
Expand Down
Loading