Module: Gtk

Defined in:
lib/gnms.rb,
lib/gui/widgets.rb

Defined Under Namespace

Classes: CList, ImageComboList

Constant Summary collapse

PENDING_CALLS_MUTEX =

Thread-safety stuff. Loosely based on booh, by Guillaume Cottenceau.

Mutex.new
PENDING_CALLS =
[]

Class Method Summary collapse

Class Method Details

.init_thread_protectObject



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/gnms.rb', line 284

def self.init_thread_protect
    Gtk.timeout_add(100) do
        PENDING_CALLS_MUTEX.synchronize do
            for closure in PENDING_CALLS
                closure.call
            end
            PENDING_CALLS.clear
        end
        true
    end
end

.thread_flushObject



274
275
276
277
278
279
280
281
282
# File 'lib/gnms.rb', line 274

def self.thread_flush
    if PENDING_CALLS_MUTEX.try_lock
        for closure in PENDING_CALLS
            closure.call
        end
        PENDING_CALLS.clear
        PENDING_CALLS_MUTEX.unlock
    end
end

.thread_protect(&proc) ⇒ Object



264
265
266
267
268
269
270
271
272
# File 'lib/gnms.rb', line 264

def self.thread_protect(&proc)
    if Thread.current == Thread.main
        proc.call
    else
        PENDING_CALLS_MUTEX.synchronize do
            PENDING_CALLS << proc
        end
    end
end