~octaspire/cl-octaspire-csfml

02fa2b5bd077a28dfa868b39c147c3781cfe894f — octaspire 1 year, 5 months ago beb079a
Remove foreign threads and mutexes

 * Common Lisp library should be used instead. The foreign
   threads implementation did not work well in combination
   with ECL's pthread usage.
4 files changed, 14 insertions(+), 101 deletions(-)

M doc/API.org
M src/package.lisp
M src/system.lisp
M test/system-test.lisp
M doc/API.org => doc/API.org +9 -28
@@ 12,32 12,15 @@ Helper function ~CLAMP~ is available.
     Exported as ~CLOCK-GETELAPSEDTIME~.
**** DONE Function ~sfClock_restart~
     Exported as ~CLOCK-RESTART~.
*** TODO Export.h
*** DONE Export.h
Nothing to do for Lisp side.
*** TODO InputStream.h
*** DONE Mutex.h
**** DONE Function ~sfMutex_create~
     Exported as ~MUTEX-CREATE~.
**** DONE Function ~sfMutex_destroy~
     Exported as ~MUTEX-DESTROY~.
**** DONE Function ~sfMutex_lock~
     Exported as ~MUTEX-LOCK~.
**** DONE Function ~sfMutex_unlock~
     Exported as ~MUTEX-UNLOCK~.
*** TODO Sleep.h
*** TODO Thread.h
**** DONE Function ~sfThread_create~
     Exported as ~THREAD-CREATE~. Callback can be created easily with macro
     ~MAKE-THREAD-CALLBACK~. Callback can be created manually like this:
     #+begin_src lisp
     (defcallback thread-callback :void ((ptr :pointer))
       (format t "~%This will be printed from the new thread.~%"))
     #+end_src
     Next, when calling the C-code, use ~(callback thread-callback)~
     to give the function pointer to C.
**** DONE Function ~sfThread_destroy~
     Exported as ~THREAD-DESTROY~.
**** DONE Function ~sfThread_launch~
     Exported as ~THREAD-LAUNCH~.
All skipped. Use Lisp instead.
*** DONE Sleep.h
Skipped. Use lisp ~SLEEP~ instead.
*** DONE Thread.h
All skipped. Use Lisp instead.
*** DONE Time.h
**** DONE Structure ~sfTime~
     ~sfTime~ is defined for Lisp, but is not exported. It has one ~:INT64~


@@ 70,11 53,9 @@ Helper function ~CLAMP~ is available.
     ~sfClock~ is not defined in Lisp (it contains C++ class), but
     instead it is exported as opaque ~:POINTER~ ~:CLOCK~.
**** DONE Structure ~sfMutex~
     ~sfMutex~ is not defined in Lisp (it contains C++ class), but
     instead it is exported as opaque ~:POINTER~ ~:MUTEX~.
Skipped. Use Lisp instead.
**** DONE Structure ~sfThread~
     ~sfThread~ is not defined in Lisp (it contains C++ class), but
     instead it is exported as opaque ~:POINTER~ ~:THREAD~.
Skipped. Use Lisp instead.
*** DONE Vector2.h
**** DONE Structure ~sfVector2i~
     ~sfvector2i~ is defined for Lisp, but is not exported. It has two ~:INT~

M src/package.lisp => src/package.lisp +1 -12
@@ 60,15 60,4 @@
   :clock-copy
   :clock-destroy
   :clock-getelapsedtime
   :clock-restart
   :mutex
   :mutex-create
   :mutex-destroy
   :mutex-lock
   :mutex-unlock
   :thread
   :make-thread-callback
   :thread-create
   :thread-destroy
   :thread-launch
   :thread-wait))
   :clock-restart))

M src/system.lisp => src/system.lisp +2 -42
@@ 394,23 394,7 @@ clock by setting its time counter back to zero."

;; MUTEXES

(defctype :mutex (:pointer)
  "Public type intended to be used instead of (:STRUCT SFMUTEX).")

(defcfun ("sfMutex_create" mutex-create) :mutex
  "Allocate new opaque :MUTEX structure.")

(defcfun ("sfMutex_destroy" mutex-destroy) :void
  "Release given opaque MUTEX."
  (mutex :mutex))

(defcfun ("sfMutex_lock" mutex-lock) :void
  "Lock given opaque MUTEX."
  (mutex :mutex))

(defcfun ("sfMutex_unlock" mutex-unlock) :void
  "Unlock given opaque MUTEX."
  (mutex :mutex))
;; Skipped. Use Lisp instead.

;; TIME RELATED HELPER FUNCTIONS



@@ 430,28 414,4 @@ equal to all the rest given times (if only one value is given, returns true)."
;; SFML/System/Thread.h.
;;

(defctype :thread (:pointer)
  "Public type intended to be used instead of (:STRUCT THREAD).")

(defmacro make-thread-callback (name &body body)
  `(defcallback ,name :void ((ptr :pointer))
     ,@body))

(defcfun ("sfThread_create" thread-create) :thread
  "Allocate new opaque :THREAD structure."
  (funcpointer :pointer)
  (userdata    :pointer))

(defcfun ("sfThread_destroy" thread-destroy) :void
  "Release given opaque MUTEX. Calls THREAD-WAIT."
  (thread :thread))

(defcfun ("sfThread_launch" thread-launch) :void
  "Start running the callback code and returns immediately.
After this function returns, the callback's code is running
parallel to the calling code."
  (thread :thread))

(defcfun ("sfThread_wait" thread-wait) :void
  "Start running the callback code and block until the new thread ends."
  (thread :thread))
;; Skipped. Use Lisp instead.

M test/system-test.lisp => test/system-test.lisp +2 -19
@@ 671,25 671,8 @@ was expected.")))))

;; MUTEXES

(fiveam:test
 test-mutex-create--mutex-lock--mutex-unlock--mutex-destroy
 (let ((v (mutex-create)))
   (mutex-lock v)
   (mutex-unlock v)
   (mutex-destroy v)))
;; Skipped. Use Lisp instead.

;; THREAD

(defparameter *thread-result* 0)
;; This must be on top level for CCL.
(make-thread-callback thread-callback (setf *thread-result* 123))

(fiveam:test
 test-make-thread-callback--thread-create--thread-wait--thread-wait--thread-destroy
 (let ((expected 123))
   (let ((v (thread-create (callback thread-callback) (null-pointer))))
     (thread-launch v)
     (thread-wait v)
     (is (= expected *thread-result*)
         #?"Result is $(*thread-result*), but $(expected) was expected.")
     (thread-destroy v))))
;; Skipped Use Lisp instead.