From efeb37c33f15a903dbe5706529a7a26511e9ca58 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 22 Nov 2010 14:55:56 +0100 Subject: [PATCH] Retire Application class It is a redundant boiler plate, just call initialization and resource release directly from main() No functional change. Signed-off-by: Marco Costalba --- src/Makefile | 2 +- src/application.cpp | 72 --------------------------------------------- src/application.h | 39 ------------------------ src/benchmark.cpp | 2 +- src/book.cpp | 4 +-- src/main.cpp | 24 +++++++++++++-- src/material.cpp | 2 +- src/misc.h | 1 - src/pawns.cpp | 2 +- src/search.cpp | 2 +- src/tt.cpp | 2 +- src/types.h | 2 +- 12 files changed, 30 insertions(+), 124 deletions(-) delete mode 100644 src/application.cpp delete mode 100644 src/application.h diff --git a/src/Makefile b/src/Makefile index 25bb0f0b..1d258a44 100644 --- a/src/Makefile +++ b/src/Makefile @@ -33,7 +33,7 @@ BINDIR = $(PREFIX)/bin PGOBENCH = ./$(EXE) bench 32 1 10 default depth ### Object files -OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \ +OBJS = bitboard.o pawns.o material.o endgame.o evaluate.o main.o \ misc.o move.o movegen.o history.o movepick.o search.o position.o \ direction.o tt.o uci.o ucioption.o book.o bitbase.o san.o benchmark.o timeman.o diff --git a/src/application.cpp b/src/application.cpp deleted file mode 100644 index 08384716..00000000 --- a/src/application.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - Stockfish, a UCI chess playing engine derived from Glaurung 2.1 - Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad - - Stockfish is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Stockfish is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -//// -//// Includes -//// - -#include "bitboard.h" -#include "direction.h" -#include "endgame.h" -#include "evaluate.h" -#include "material.h" -#include "misc.h" -#include "movepick.h" -#include "position.h" -#include "search.h" -#include "thread.h" -#include "ucioption.h" - - -/// Application class is in charge of initializing global resources -/// at startup and cleanly releases them when program terminates. - -Application::Application() { - - init_direction_table(); - init_bitboards(); - init_uci_options(); - Position::init_zobrist(); - Position::init_piece_square_tables(); - init_eval(1); - init_bitbases(); - init_search(); - init_threads(); -} - -void Application::initialize() { - - // A static Application object is allocated - // once only when this function is called. - static Application singleton; -} - -void Application::free_resources() { - - // Warning, following functions reference global objects that - // must be still alive when free_resources() is called. - exit_threads(); - quit_eval(); -} - -void Application::exit_with_failure() { - - exit(EXIT_FAILURE); -} diff --git a/src/application.h b/src/application.h deleted file mode 100644 index 931e2e2b..00000000 --- a/src/application.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Stockfish, a UCI chess playing engine derived from Glaurung 2.1 - Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad - - Stockfish is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Stockfish is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#if !defined(APPLICATION_H_INCLUDED) -#define APPLICATION_H_INCLUDED - - -/// Singleton class used to housekeep memory and global resources -/// so to be sure we always leave in a clean state. - -class Application { - - Application(); - Application(const Application&); - -public: - static void initialize(); - static void free_resources(); - static void exit_with_failure(); -}; - -#endif // !defined(APPLICATION_H_INCLUDED) diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 33c1a1a9..d0afee89 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -102,7 +102,7 @@ void benchmark(int argc, char* argv[]) { if (!fenFile.is_open()) { cerr << "Unable to open positions file " << posFile << endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } string pos; while (fenFile.good()) diff --git a/src/book.cpp b/src/book.cpp index 7cb0863c..95ccd690 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -376,7 +376,7 @@ void Book::open(const string& fName) { return; } cerr << "Failed to open book file " << fileName << endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } @@ -496,7 +496,7 @@ void Book::read_entry(BookEntry& entry, int idx) { if (!good()) { cerr << "Failed to read book entry at index " << idx << endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } } diff --git a/src/main.cpp b/src/main.cpp index e83c2cc5..f9ed8de5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,8 +28,17 @@ #include #include +#include "bitboard.h" #include "bitcount.h" +#include "direction.h" +#include "endgame.h" +#include "evaluate.h" +#include "material.h" #include "misc.h" +#include "position.h" +#include "search.h" +#include "thread.h" +#include "ucioption.h" #ifdef USE_CALLGRIND #include @@ -50,8 +59,16 @@ int main(int argc, char* argv[]) { cout.rdbuf()->pubsetbuf(NULL, 0); cin.rdbuf()->pubsetbuf(NULL, 0); - // Initialization through global resources manager - Application::initialize(); + // Startup initializations + init_direction_table(); + init_bitboards(); + init_uci_options(); + Position::init_zobrist(); + Position::init_piece_square_tables(); + init_eval(1); + init_bitbases(); + init_search(); + init_threads(); #ifdef USE_CALLGRIND CALLGRIND_START_INSTRUMENTATION; @@ -79,6 +96,7 @@ int main(int argc, char* argv[]) { benchmark(argc, argv); } - Application::free_resources(); + exit_threads(); + quit_eval(); return 0; } diff --git a/src/material.cpp b/src/material.cpp index 5e8f75d9..01123000 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -144,7 +144,7 @@ MaterialInfoTable::MaterialInfoTable() { { cerr << "Failed to allocate " << MaterialTableSize * sizeof(MaterialInfo) << " bytes for material hash table." << endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo)); } diff --git a/src/misc.h b/src/misc.h index 1f10905f..6fffabfb 100644 --- a/src/misc.h +++ b/src/misc.h @@ -29,7 +29,6 @@ #include #include -#include "application.h" #include "types.h" //// diff --git a/src/pawns.cpp b/src/pawns.cpp index ef225847..e3201081 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -91,7 +91,7 @@ PawnInfoTable::PawnInfoTable() { { std::cerr << "Failed to allocate " << (PawnTableSize * sizeof(PawnInfo)) << " bytes for pawn hash table." << std::endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } memset(entries, 0, PawnTableSize * sizeof(PawnInfo)); } diff --git a/src/search.cpp b/src/search.cpp index 99773213..121575f5 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -2324,7 +2324,7 @@ split_point_start: // At split points actual search starts from here if (!ok) { cout << "Failed to create thread number " << i << endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } // Wait until the thread has finished launching and is gone to sleep diff --git a/src/tt.cpp b/src/tt.cpp index 375c00a6..63c3e995 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -70,7 +70,7 @@ void TranspositionTable::set_size(size_t mbSize) { { std::cerr << "Failed to allocate " << mbSize << " MB for transposition table." << std::endl; - Application::exit_with_failure(); + exit(EXIT_FAILURE); } clear(); } diff --git a/src/types.h b/src/types.h index 91563109..8e6356eb 100644 --- a/src/types.h +++ b/src/types.h @@ -17,7 +17,6 @@ along with this program. If not, see . */ - #if !defined(TYPES_H_INCLUDED) #define TYPES_H_INCLUDED @@ -51,6 +50,7 @@ typedef uint64_t Key; // Bitboard type typedef uint64_t Bitboard; +#include //// //// Configuration -- 2.39.2