]> git.sesse.net Git - stockfish/commitdiff
Retire Application class
authorMarco Costalba <mcostalba@gmail.com>
Mon, 22 Nov 2010 13:55:56 +0000 (14:55 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 22 Nov 2010 17:36:18 +0000 (18:36 +0100)
It is a redundant boiler plate, just call initialization and
resource release directly from main()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 files changed:
src/Makefile
src/application.cpp [deleted file]
src/application.h [deleted file]
src/benchmark.cpp
src/book.cpp
src/main.cpp
src/material.cpp
src/misc.h
src/pawns.cpp
src/search.cpp
src/tt.cpp
src/types.h

index 25bb0f0b0e280833693aa211c56e4bc428630f38..1d258a4485db95f3d68700c68e6fcba3f3c1d026 100644 (file)
@@ -33,7 +33,7 @@ BINDIR = $(PREFIX)/bin
 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
 
 ### Object files
 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
 
        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 (file)
index 0838471..0000000
+++ /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 <http://www.gnu.org/licenses/>.
-*/
-
-
-////
-//// 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 (file)
index 931e2e2..0000000
+++ /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 <http://www.gnu.org/licenses/>.
-*/
-
-
-#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)
index 33c1a1a9982c061ae5672eeaa4d3245322498696..d0afee898695b50616b951987136d987e8af401d 100644 (file)
@@ -102,7 +102,7 @@ void benchmark(int argc, char* argv[]) {
       if (!fenFile.is_open())
       {
           cerr << "Unable to open positions file " << posFile << endl;
       if (!fenFile.is_open())
       {
           cerr << "Unable to open positions file " << posFile << endl;
-          Application::exit_with_failure();
+          exit(EXIT_FAILURE);
       }
       string pos;
       while (fenFile.good())
       }
       string pos;
       while (fenFile.good())
index 7cb0863c11158b2f414a0c2868d0a8041b5b3cf9..95ccd690506251c284dc557905a53d5c1cc6711f 100644 (file)
@@ -376,7 +376,7 @@ void Book::open(const string& fName) {
           return;
   }
   cerr << "Failed to open book file " << fileName << endl;
           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;
   if (!good())
   {
       cerr << "Failed to read book entry at index " << idx << endl;
-      Application::exit_with_failure();
+      exit(EXIT_FAILURE);
   }
 }
 
   }
 }
 
index e83c2cc5f94422dec45f4d77d1c0bf99a55190e0..f9ed8de52c361fd10c3f8e8b280e8f711af30314 100644 (file)
 #include <iostream>
 #include <string>
 
 #include <iostream>
 #include <string>
 
+#include "bitboard.h"
 #include "bitcount.h"
 #include "bitcount.h"
+#include "direction.h"
+#include "endgame.h"
+#include "evaluate.h"
+#include "material.h"
 #include "misc.h"
 #include "misc.h"
+#include "position.h"
+#include "search.h"
+#include "thread.h"
+#include "ucioption.h"
 
 #ifdef USE_CALLGRIND
 #include <valgrind/callgrind.h>
 
 #ifdef USE_CALLGRIND
 #include <valgrind/callgrind.h>
@@ -50,8 +59,16 @@ int main(int argc, char* argv[]) {
   cout.rdbuf()->pubsetbuf(NULL, 0);
   cin.rdbuf()->pubsetbuf(NULL, 0);
 
   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;
 
 #ifdef USE_CALLGRIND
   CALLGRIND_START_INSTRUMENTATION;
@@ -79,6 +96,7 @@ int main(int argc, char* argv[]) {
           benchmark(argc, argv);
   }
 
           benchmark(argc, argv);
   }
 
-  Application::free_resources();
+  exit_threads();
+  quit_eval();
   return 0;
 }
   return 0;
 }
index 5e8f75d9cc4b6c2561fdd5b1a5bb784078be323c..0112300080f56c43a3ae16823a990975b1247dc1 100644 (file)
@@ -144,7 +144,7 @@ MaterialInfoTable::MaterialInfoTable() {
   {
       cerr << "Failed to allocate " << MaterialTableSize * sizeof(MaterialInfo)
            << " bytes for material hash table." << endl;
   {
       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));
 }
   }
   memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo));
 }
index 1f10905f0e487b0f5a736c4b7e5c7ebe044afad0..6fffabfba1233aae8134ef88f9593c6a5294d242 100644 (file)
@@ -29,7 +29,6 @@
 #include <fstream>
 #include <string>
 
 #include <fstream>
 #include <string>
 
-#include "application.h"
 #include "types.h"
 
 ////
 #include "types.h"
 
 ////
index ef225847776eb593757e376de49824ceb6e2a60d..e3201081635be80e9aaa5a3520b13ff90cf3d21e 100644 (file)
@@ -91,7 +91,7 @@ PawnInfoTable::PawnInfoTable() {
   {
       std::cerr << "Failed to allocate " << (PawnTableSize * sizeof(PawnInfo))
                 << " bytes for pawn hash table." << std::endl;
   {
       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));
 }
   }
   memset(entries, 0, PawnTableSize * sizeof(PawnInfo));
 }
index 997732131408d314efbb913b3ed87f838e6f9a87..121575f554525c6a2b13b52140a7d4d6fa2f86b6 100644 (file)
@@ -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;
         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
         }
 
         // Wait until the thread has finished launching and is gone to sleep
index 375c00a67308fbc934e7cad2fe569f5a780468f3..63c3e995ab30b22f33191faf22a881350fe19cf9 100644 (file)
@@ -70,7 +70,7 @@ void TranspositionTable::set_size(size_t mbSize) {
       {
           std::cerr << "Failed to allocate " << mbSize
                     << " MB for transposition table." << std::endl;
       {
           std::cerr << "Failed to allocate " << mbSize
                     << " MB for transposition table." << std::endl;
-          Application::exit_with_failure();
+          exit(EXIT_FAILURE);
       }
       clear();
   }
       }
       clear();
   }
index 91563109f997187db40aaaaad8784ef75746f629..8e6356eb344f4d94b23323633014bb258dfecb00 100644 (file)
@@ -17,7 +17,6 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-
 #if !defined(TYPES_H_INCLUDED)
 #define TYPES_H_INCLUDED
 
 #if !defined(TYPES_H_INCLUDED)
 #define TYPES_H_INCLUDED
 
@@ -51,6 +50,7 @@ typedef uint64_t Key;
 // Bitboard type
 typedef uint64_t Bitboard;
 
 // Bitboard type
 typedef uint64_t Bitboard;
 
+#include <cstdlib>
 
 ////
 //// Configuration
 
 ////
 //// Configuration